- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试将Format_Grayscale8
图像转换为Format_ARGB32
(或任何其他8bpp RGB格式)。我尝试使用QImage::convertToFormat
和颜色表,但无法正常工作。输入是一个小的8位灰度图像(PGM格式的文本字符串)。
QImage img;
img.loadFromData(gray_map.toLatin1());
QImage heatmap = img.convertToFormat(QImage::Format_Indexed8, color_gradient.getColorMap());
// gray_img format is QImage::Format_Grayscale8
QImage createHeatMap(QImage gray_img)
{
QImage heatmap(gray_img.width(), gray_img.height(), QImage::Format_ARGB32);
// custom heatmap, size() is 256
const QVector<QRgb> color_map = color_gradient.getColorMap();
// Default color
heatmap.fill(color_map[0]);
for (int y = 0; y < gray_img.height(); y++)
{
for (int x = 0; x < gray_img.width(); x++)
{
const uchar* img_ptr = gray_img.bits();
int offset = x + y*gray_img.bytesPerLine();
uchar gray_pix = *(img_ptr + offset);
// just in case
if (gray_pix < color_map.size())
heatmap.setPixel(x, y, color_map[gray_pix]);
}
}
return heatmap;
}
QImage img;
img.loadFromData(doppler_map.toLatin1());
QImage heatmap = createHeatMap(img);
// Heatmap color lookup table generator, inspired from:
// http://www.andrewnoske.com/wiki/Code_-_heatmaps_and_color_gradients
#include <QColor>
class ColorGradient
{
private:
struct ColorPoint
{
float r, g, b;
float val; // Position of our color along the gradient (between 0 and 1).
ColorPoint(float red, float green, float blue, float value)
: r(red), g(green), b(blue), val(value)
{
}
};
std::vector<ColorPoint> mColors; // An array of color points in ascending value.
uint mTableSize = 0;
QVector<QRgb> mColorMap;
// hidden
ColorGradient();
public:
inline auto getColorMap()
{
return mColorMap;
}
ColorGradient(uint table_size)
{
createDefaultHeatMapGradient(table_size);
}
//-- Places a 6 color heapmap gradient into the "color" vector
#define CF64(val) ((float)(val) / 64.0)
#define CF256(val) ((float)(val) / 256.0)
void createDefaultHeatMapGradient(uint table_size)
{
mTableSize = table_size;
mColorMap.clear();
mColors.clear();
// ascending order
mColors.push_back(ColorPoint(0, 0, CF256(96), CF64(00))); // Dark Blue
mColors.push_back(ColorPoint(0, 0, 1, CF64(06))); // Blue
mColors.push_back(ColorPoint(0, 1, 1, CF64(22))); // Cyan
mColors.push_back(ColorPoint(1, 1, 0, CF64(39))); // Yellow
mColors.push_back(ColorPoint(1, 0, 0, CF64(55))); // Red
mColors.push_back(ColorPoint(CF256(159),0, 0, CF64(63))); // Dark Red
QColor color;
// Generate the color table
for (uint n = 0; n < table_size; n++)
{
float value = (float)n / (float)table_size;
bool found = false;
for (int i = 0; i < mColors.size(); i++)
{
ColorPoint &currC = mColors[i];
if (value < currC.val)
{
ColorPoint &prevC = mColors[std::max(0, i - 1)];
float valueDiff = (prevC.val - currC.val);
float fractBetween = (valueDiff == 0) ? 0 : (value - currC.val) / valueDiff;
float r = (prevC.r - currC.r)*fractBetween + currC.r;
float g = (prevC.g - currC.g)*fractBetween + currC.g;
float b = (prevC.b - currC.b)*fractBetween + currC.b;
color.setRgbF(r, g, b);
mColorMap.append(color.rgb());
found = true;
break;
}
}
if (!found)
{
color.setRgbF(mColors.back().r, mColors.back().g, mColors.back().b);
mColorMap.append(color.rgb());
}
}
}
};
P2
40 17
64
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 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窍是先转换为不带任何颜色映射的QImage::Format_Indexed8
,然后在单独的调用中进行设置:
QImage heatmap = img.convertToFormat(QImage::Format_Indexed8);
heatmap.setColorTable(color_gradient.getColorMap());
QImage::Format_RGB888
或任何您需要的转换。
关于c++ - QImage:如何将灰度图像转换为RGB热图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58509179/
我正在寻找一种方法来简单地将一些Qimage粘贴到更大的图像中,从一些给定的(x,y)开始。现在,我正在逐像素复制所有Qimage。 最佳答案 QImage srcImage = QImage(100
我正在开发一个图像处理程序,当程序不断收到这些消息时,这里有一些示例,但我收到了数百条消息,以至于程序无法完全执行。 QImage::setPixel: coordinate (1043968,0)
我尝试将具有 RGB32 的 QImage 转换为具有 RGB24 的 QImage。我的代码在这种情况下不起作用: 当图片在BMP头中多出1024字节时,图片的大小为X*Y*3+54+未知的1024
我找到了类似的主题,但不是这个特定的主题。知道以下代码有什么问题吗?它返回'loaded=false',这显然意味着无法加载图像数据。 cv::Mat mymat; QImage qimg; myma
我创建了一个 Publisher 类,它定期发出 QImage 对象。 但是,我很难将 QImage 绘制到 QML 元素。 Image 和 Canvas QML 组件似乎需要 QUrl 而不是 QI
我是图形编程的新手(像素、图像等) 我正在尝试将原始数据转换为 QImage 并将其显示在 QLabel 上。问题是,原始数据可以是任何数据(它实际上不是图像原始数据,而是二进制文件。) 原因是,为了
是 QImage基于 QSharedData ?做 Qimage关注 pimpl或 copy on write ? 例如复制(通过复制骗局或分配)Qimage 会复制像素的深拷贝吗? 最佳答案 QIm
我正在调试一个巨大的 Qt 应用程序,其中包含数百个类、凌乱的代码等。在跟踪错误的同时,我想单步执行 gdb(kdbg、ddd 等等),同时观察使用 QPainter 绘制到 QImage 中的内容这
如何清除或清理 QIMage 我的以下方法获取对 QIMage 的常量引用。 MyMethod(const QImage & img) { // save it to a file img.s
我正在尝试将Format_Grayscale8图像转换为Format_ARGB32(或任何其他8bpp RGB格式)。我尝试使用QImage::convertToFormat和颜色表,但无法正常工作。
我正在使用 Qt 库创建 QImages。 我可以使用 this constructor : QImage image("example.jpg"); 但是我遇到了 this static funct
我知道 QImage 的高度和宽度,以及每个像素值(从 x、y 位置)。我如何构建一个知道这些值的 QImage? 最佳答案 setPixel() 的第二个参数是单个 int 中的 24 位 RGB
我正在开发用于编辑光栅图形的应用程序。在这个应用程序中,我必须创建扫描线函数,它与 QImage 类中的扫描线函数做同样的事情。但是我对扫描线函数的工作方式和一般的扫描线有点困惑。例如,当我为高度为
我的工作基于 this answer ,我正在尝试使用 Qt 的 QGLWidget 来呈现视频,但我遇到了一些问题。在我的视频解码线程中解码后立即保存帧时,结果很好: 但是当画出来的时候,它被严重破
我目前使用的是 Qt 5.12.3,在理解 QImage::pixel 函数的 10 位数字输出时遇到问题。对于此代码: QImage image; image.load("D:/qtProjects
我有一个简单的绘图应用程序,但是当我调整窗口大小时图像被删除,我想保留它。我尝试使用 image.scaled(current size) 但它不起作用。 qDebug() size(); QImag
我正在尝试显示 QImage在 QML 中,可能带有 Image .目前,我发现了类似 QQuickImageProvider 的内容,我实现并尝试使用,但没有成功。 我有QList我自己的对象( I
QImage具有以下构造函数: QImage(const QString &fileName, const char *format = nullptr); 但是,我正在尝试解析已作为字节数组加载的
我在我的 qt quick 应用程序中用相机捕获了一个图像。我想将路径发送到我的 c++ 代码并在 c++ QImage 中加载该图像。但是路径是 image://camera/preview_1 我
在我控制窗口的主类中,我有这个函数,其中 pixmapItem 是类头中定义的 QGraphicsPixmapItem*: void updateDisplay() { uchar *data
我是一名优秀的程序员,十分优秀!