C++图像伪彩色处理源代码


一个基于C++的灰度图像伪彩色处理程序源代码。供大家参考。
资源截图
代码片段和文件信息
// OpenCV_1.cpp : 定义控制台应用程序的入口点。
//
//彩虹图的颜色分配取一下值
// R G B gray
//----------------------------------
// 红 255 0 0 255
// 橙 255 127 0 204
// 黄 255 255 0 153
// 绿 0 255 0 102
// 青 0 255 255 51
// 蓝 0 0 255 0

#include 
#include 
using namespace cv;
using namespace std;
int main(int argc char* argv[])
{

Mat img = imread(“143225_IR.bmp“ CV_LOAD_IMAGE_GRAYSCALE);//采用灰度格式读取图片
namedWindow(“bmp_img“);
imshow(“bmp_img“ img);

Mat img_pseudocolor(img.rows img.cols CV_8UC3);//构造RGB图像,参数CV_8UC3教程文档里面有讲解
int tmp = 0;
for (int y = 0; y {
for (int x = 0; x {
tmp = img.at(y x);

//img_pseudocolor.at(y x)[0] = abs(255 - tmp); //blue
//img_pseudocolor.at(y x)[1] = abs(127 - tmp); //green
//img_pseudocolor.at(y x)[2] = abs(0 - tmp); //red

/*if (0<=tmp<=75)
img_pseudocolor.at(y x)[0] = abs(11.6+1.504*tmp); //blue
else if (75 img_pseudocolor.at(y x)[0] = abs(184.06667 - 0.872*tmp); //blue
else
img_pseudocolor.at(y x)[0] = abs(4.53187*tmp-916.89011); //blue
img_pseudocolor.at(y x)[1] = abs(0.00444*tmp*tmp-0.12047*tmp+4.69224); //green
img_pseudocolor.at(y x)[2] = abs(20.2594+1.10083*tmp); //red*/

if (0 <= tmp <= 125)
img_pseudocolor.at(y x)[0] = abs(55.60714 + 3.43843*tmp - 0.02711*tmp*tmp); //blue

else
img_pseudocolor.at(y x)[0] = abs(841.85728 - 9.59932*tmp + 0.02762*tmp*tmp); //blue
    img_pseudocolor.at(y x)[1] = abs(0.00336*tmp*tmp + 0.000916564*tmp + 30.45043); //green
    img_pseudocolor.at(y x)[2] = abs(6.38595 + 2.64406*tmp - 0.0074*tmp*tmp); //red*/
}
}


/*IplImage *img1 = cvCreateImage(cvSize(256 50) IPL_DEPTH_8U 3);
cvZero(img1);//相当于初始化图片,值都为0,矩阵大小为640*480
for (int i = 0; i < 256;i++)

img1[: i 0] = img_pseudocolor[i][0]
map_image_arr[: i 1] = img_pseudocolor[i][1]
map_image_arr[: i 2] = img_pseudocolor[i][2]
map_image = Image.fromarray(map_image_arr)
map_image.show()
map_image.save(“colormap.png“)*/



namedWindow(“img_pseudocolor“);
imshow(“img_pseudocolor“ img_pseudocolor);
imwrite(“20180622_142641_IRp.bmp“ img_pseudocolor);

Mat img_color(img.rows img.cols CV_8UC3);//构造RGB图像
#define IMG_B(imgyx) img.at(yx)[0]
#define IMG_G(imgyx) img.at(yx)[1]
#define IMG_R(imgyx) img.at(yx)[2]
uchar tmp2 = 0;
for (int y = 0; y {
for (int x = 0; x {
tmp2 = img.at(y x);




if (tmp2 <= 51)
{
IMG_B(img_color y x) = 255;
IMG_G(img_color y x) = tmp2 * 5;
IMG_R(img_color y x) = 0;
}
else if (tmp2 <= 102)
{
tmp2 -= 51;
IMG_B(img_color y x) = 255 - tmp2 * 5;
IMG_G(img_color y x) = 255;
IMG

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

    ..A..H.     28160  2018-12-10 16:30  Pesudo_color.vsPesudo_colorv14.suo

     文件     614454  2018-08-27 14:01  Pesudo_colorPesudo_color140100_IR.bmp

     文件     614454  2018-08-27 14:05  Pesudo_colorPesudo_color140524_IR.bmp

     文件     614454  2018-08-27 14:09  Pesudo_colorPesudo_color140927_IR.bmp

     文件     614454  2018-08-27 14:14  Pesudo_colorPesudo_color141424_IR.bmp

     文件     614454  2018-08-27 14:18  Pesudo_colorPesudo_color141805_IR.bmp

     文件     614454  2018-08-27 14:27  Pesudo_colorPesudo_color142755_IR.bmp

     文件     614454  2018-08-27 14:32  Pesudo_colorPesudo_color143225_IR.bmp

     文件     614454  2018-08-27 14:37  Pesudo_colorPesudo_color143749_IR.bmp

     文件     614454  2018-08-27 14:42  Pesudo_colorPesudo_color144250_IR.bmp

     文件     614454  2018-08-27 14:48  Pesudo_colorPesudo_color144856_IR.bmp

     文件     614454  2018-08-27 15:01  Pesudo_colorPesudo_color150134_IR.bmp

     文件     614454  2018-08-27 15:08  Pesudo_colorPesudo_color150809_IR.bmp

     文件     614454  2018-08-27 15:15  Pesudo_colorPesudo_color151529_IR.bmp

     文件     614454  2018-08-27 15:20  Pesudo_colorPesudo_color152031_IR.bmp

     文件     614454  2018-08-27 15:22  Pesudo_colorPesudo_color152257_IR.bmp

     文件     614454  2018-08-27 15:28  Pesudo_colorPesudo_color152833_IR.bmp

     文件     308278  2018-06-22 14:26  Pesudo_colorPesudo_color20180622_142641_IR.bmp

     文件     921654  2018-12-10 14:02  Pesudo_colorPesudo_color20180622_142641_IRp.bmp

     文件     921654  2018-12-10 14:02  Pesudo_colorPesudo_color20180622_142641_IRr.bmp

     文件     308278  2018-06-22 14:27  Pesudo_colorPesudo_color20180622_142707_IR.bmp

     文件     308278  2018-06-22 14:31  Pesudo_colorPesudo_color20180622_143142_IR.bmp

     文件     308278  2018-06-22 14:32  Pesudo_colorPesudo_color20180622_143206_IR.bmp

     文件     308278  2018-06-22 14:32  Pesudo_colorPesudo_color20180622_143234_IR.bmp

     文件        140  2018-11-20 10:52  Pesudo_colorPesudo_colorDebugPesudo_color.log

     文件        598  2018-11-19 11:23  Pesudo_colorPesudo_colorDebugPesudo_color.tlogcl.command.1.tlog

     文件      16796  2018-11-19 11:23  Pesudo_colorPesudo_colorDebugPesudo_color.tlogCL.read.1.tlog

     文件        528  2018-11-19 11:23  Pesudo_colorPesudo_colorDebugPesudo_color.tlogCL.write.1.tlog

     文件          2  2018-11-20 10:52  Pesudo_colorPesudo_colorDebugPesudo_color.tloglink.command.1.tlog

     文件          2  2018-11-20 10:52  Pesudo_colorPesudo_colorDebugPesudo_color.tloglink.read.1.tlog

............此处省略49个文件信息

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件举报,一经查实,本站将立刻删除。

发表评论

评论列表(条)