下面的代码对图像中的B分量进行了增强
#include <iostream>
#include <opencv2/opencv.hpp>
using namespace std;
using namespace cv;
int main(int argc, const char * argv[]) {
// insert code here...
Mat yyImg = imread("/Users/username/Documents/mine/YY.jpeg");
Mat yyImgNew;
resize(yyImg, yyImgNew, cv::Size(300, 300), INTER_AREA);
int rows = yyImgNew.rows;
int cols = yyImgNew.cols;
int channels = yyImg.channels();
cout<<"rows:"<<rows<<" cols:"<<cols<<" channels:"<<channels<<endl;
for(int i = 0; i < rows; i++)
{
for(int j = 0; j < cols; j++)
{
int newValue = yyImgNew.at<Vec3b>(i, j)[0] + 170;
if(newValue > 255)
{
yyImgNew.at<Vec3b>(i, j)[0] = 255;
} else{
yyImgNew.at<Vec3b>(i, j)[0] = newValue;
}
}
}
imshow("YY", yyImgNew);
std::cout << "Hello, World!\n";
waitKey();
return 0;
}
原始图像:
增强后的图像: