在OpenCV中从Mat对象构建图像
building an image from Mat object in OpenCV
我使用 OpenCV 并且我有一个大小为 1024*1024 的 Mat 对象(从照片中提取并进行处理),值在 [1..25] 范围内。
Mat g;
g=[1,5,2,14,13,5,22,24,5,13....;
21,12,...;
..
.];
我想将这些值表示为图像。它只是一个插图图像来显示不同的区域,每个区域都有一种颜色。例如:所有等于 1=红色的值,所有等于 14=蓝色的值,依此类推。
然后构建并显示这张照片。
有人知道我应该如何进行吗?
谢谢!
如果你不太在意你得到什么颜色,你可以缩放你的数据(所以它几乎填满了0到255的范围),然后使用内置的颜色图。例如
cv::Mat g = ...
cv::Mat image;
cv::applyColorMap(g * 10, image, COLORMAP_RAINBOW);
请参阅 applyColorMap() doco
有 颜色图 ,但如果您的数据仅在 [0..25] 范围内,它们将无济于事。 所以你可能已经推出了你自己的版本:
Vec3b lut[26] = {
Vec3b(0,0,255),
Vec3b(13,255,11),
Vec3b(255,22,1),
// all the way down, you get the picture, no ?
};
Mat color(w,h,CV_8UC3);
for ( int y=0; y<h; y++ ) {
for ( int x=0; x<w; x++ ) {
color.at<Vec3b>(y,x) = lut[ g.at<uchar>(y,x) ];
// check the type of "g" please, i assumed CV_8UC1 here.
// if it's CV_32S, use g.at<int> , i.e, you need the right type here
}
}
相关文章:
- C++为构建时间获取QDateTime的可靠方法
- 无法在 CLion 中构建 C++ 项目
- C++,OpenCV,尝试显示图像时"OpenCV(4.3.0) Error: Assertion failed (size.width>0 && size.height>0)"此错误
- 函数向量_指针有不同的原型,我可以构建一个吗
- 如何使用ndk-build.cmd构建Android.so文件
- 如何使用OpenCV将RBG图像转换为HSV,并将H、S和V值保存为C++中的3个独立图像
- OpenCV EqualizeHist()从彩色图像创建黑白图像
- 将"打开的CV图像"中的"颜色"转换为整数格式
- libssh 的函数在构建 libssh 时无法在 Qt 和 cmake 错误中找到
- 使用cmake从源代码构建MySQL连接器/C++失败(与以前的声明冲突)
- 平均图像时图像损坏
- VSCode-有一个红色下划线,但程序构建和运行正确,并且出现配音错误
- 如何使用OpenCV从已知的3D点云(在没有I的情况下构建)估计新图像I的相机姿态矩阵
- 如何使用opencv从矩阵向量中构建图像
- OpenCV使用像素指针构建图像
- 应用傅里叶逆变换OpenCV后构建图像
- 将数据坐标构建为像素坐标的图像
- 在OpenCV中从Mat对象构建图像
- Xcode 4中的命令行工具构建版本,在构建可执行文件中包含图像存在问题
- 从灰度图像构建颜色条