Qmage:使用颜色表从灰度转换为RGB
QImage: convert from grayscale to RGB with a color table
使用Qt,我尝试使用颜色表定义的自定义转换规则将Format_Indexed8
图像转换为Format_RGB30
。我认为这很简单,因为QImage::convertToFormat
可以将颜色表作为参数,但我无法使其工作。
这是我的代码:
QImage image = QImage(data, width, height, QImage::Format_Indexed8);
QVector<QRgb> colorTable(256);
for (int i = 0; i < 255; i++)
colorTable[i] = qRgb(255 - i, i, i);
image = image.convertToFormat(QImage::Format_RGB30, colorTable);
这段代码只是给了我一个RGB格式的图像,但看起来与灰度图像的眼睛相同。
我认为QImage::convertToFormat
中的颜色表参数需要从 RGB 转换为索引,而您正在以相反的方式进行转换。
我会尝试直接在索引文件(源(中设置颜色表,使用 QImage::setColorTable
,然后调用 convertToFormat
仅传递格式参数:
QImage image = QImage(data, width, height, QImage::Format_Indexed8);
image.setColorTable(colorTable);
image = image.convertToFormat(QImage::Format_RGB30);
自Qt 5.5(2015年7月发布(以来,这不是必需的。您现在可以使用 QImage::Format_Grayscale8
.您的代码很简单:
QImage image{data, width, height, QImage::Format_Grayscale8};
相关文章:
- OpenCV - 如何将灰度转换为彩色(CV_8UC3)?
- C++ Gdi+将图像转换为灰度
- 将 BMP 图像转换为灰度
- 颜色到灰度转换
- 如何将图像转换为灰度 opengl c++
- 如何正确将位图转换为 OpenCV 灰度垫
- 将 YUV420p QVideoFrame 转换为灰度 OpenCV 垫
- Qmage:使用颜色表从灰度转换为RGB
- 在OpenCV中将灰度图像转换为单色
- Mat的convertTo函数在OpenCV中将灰度图像的类型转换为CV_32F时抱怨断言错误
- 使用某些系数将图像转换为灰度的最快方法
- OPENCV:从RGB转换为灰度只有蓝色
- 在C++中将彩色位图转换为灰度
- 如何将灰度/二进制垫子转换为qimage
- 使用libpng将转换设置为灰度
- 使用煤渣转换为灰度
- 将颜色图像转换为OpenCV中的灰度问题
- 在open cv中,我如何将灰度图像转换回RGB图像(颜色)
- 我正在尝试将灰度转换为更大的黑色图像.我得到这个错误OpenCV错误:断言失败
- 将图像颜色从灰度转换为RGB OpenCV C++