19,468
社区成员
发帖
与我相关
我的任务
分享
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <vector>
int main()
{
// A test comparing luminance and brightness
// create linear intensity image
cv::Mat linear(100,256,CV_8U);
for (int i=0; i<256; i++) {
linear.col(i)= i;
}
// split the 3 channels into 3 images
std::vector<cv::Mat> channels(3);
// create a Lab image
linear.copyTo(channels[0]);
cv::Mat constante(100,256,CV_8U,cv::Scalar(128));
constante.copyTo(channels[1]);
constante.copyTo(channels[2]);
cv::Mat image;
cv::merge(channels,image);
// convert back to BGR
cv::Mat brightness;
cv::cvtColor(image,brightness, CV_Lab2BGR);
cv::split(brightness, channels);
// create combined image
cv::Mat combined(200,256, CV_8U);
cv::Mat half1(combined,cv::Rect(0,0,256,100));
linear.copyTo(half1);
cv::Mat half2(combined,cv::Rect(0,100,256,100));
channels[0].copyTo(half2);
cv::namedWindow("Luminance vs Brightness");
cv::imshow("Luminance vs Brightness",combined);
cv::waitKey();
}