码迷,mamicode.com
首页 > 其他好文 > 详细

OpenCV实现彩色图片的补色与反色

时间:2020-04-30 12:03:26      阅读:129      评论:0      收藏:0      [点我收藏+]

标签:name   cat   clu   open   return   show   col   names   read   

 1 #include "stdafx.h"
 2 #include <algorithm> 
 3 #include <opencv2/core/core.hpp>
 4 #include <opencv2/highgui/highgui.hpp>
 5 #include <opencv2/imgproc/imgproc.hpp>
 6 using namespace cv;
 7 
 8 int _tmain(int argc, _TCHAR* argv[])
 9 {
10     Mat img = imread("cat.jpg");
11     Mat dst1,dst2;
12     img.copyTo(dst1);
13     img.copyTo(dst2);
14     int row = img.rows;
15     int col = img.cols;
16     for (int i = 0; i < row;++i)
17     for (int j = 0; j < col; ++j){
18         int b = img.at<Vec3b>(i, j)[0];//blue
19         int g = img.at<Vec3b>(i, j)[1];//green
20         int r = img.at<Vec3b>(i, j)[2];//red
21         int maxrgb = max(max(r, g), b);
22         int minrgb = min(min(r, g), b);
23         dst1.at<Vec3b>(i, j)[0] = maxrgb + minrgb - b;
24         dst1.at<Vec3b>(i, j)[1] = maxrgb + minrgb - g;
25         dst1.at<Vec3b>(i, j)[2] = maxrgb + minrgb - r;
26         dst2.at<Vec3b>(i, j)[0] = 255 - b;
27         dst2.at<Vec3b>(i, j)[1] = 255 - g;
28         dst2.at<Vec3b>(i, j)[2] = 255 - r;
29     }
30     imshow("原图" , img );
31     imshow("补色", dst1);
32     imshow("反色", dst2);
33     waitKey();
34     return 0;
35 }

 

OpenCV实现彩色图片的补色与反色

标签:name   cat   clu   open   return   show   col   names   read   

原文地址:https://www.cnblogs.com/ybqjymy/p/12807466.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!