当你分割一个3通道图像分成3单通道图像,每个图像是灰度级。他们代表色彩信息的事实是无关紧要的。
原图:
的YCrCb渠道:
你可以,但是,应用颜色效果:
您可以模糊Y通道,然后合并3个单声道,并转换回BGR:
这里供参考全码:
#include <opencv2/opencv.hpp>
#include <vector>
using namespace std;
using namespace cv;
int main()
{
Mat3b bgr = imread("path_to_image");
Mat3b ycrcb;
cvtColor(bgr, ycrcb, COLOR_BGR2YCrCb);
vector<Mat1b> planes;
split(ycrcb, planes);
// Collage planes
Mat1b collagePlanes(bgr.rows, bgr.cols*3);
for (int i = 0; i < 3; ++i)
{
planes[i].copyTo(collagePlanes(Rect(i*bgr.cols, 0, bgr.cols, bgr.rows)));
}
Mat1b gray(bgr.rows, bgr.cols, uchar(128));
// Y
vector<Mat1b> vy(3);
vy[0] = planes[0];
vy[1] = gray.clone();
vy[2] = gray.clone();
Mat3b my;
merge(vy, my);
// Cr
vector<Mat1b> vcr(3);
vcr[0] = gray.clone();
vcr[1] = planes[1];
vcr[2] = gray.clone();
Mat3b mcr;
merge(vcr, mcr);
// Cb
vector<Mat1b> vcb(3);
vcb[0] = gray.clone();
vcb[1] = gray.clone();
vcb[2] = planes[2];
Mat3b mcb;
merge(vcb, mcb);
// Collage planes
Mat3b collageColor(bgr.rows, bgr.cols * 3);
my.copyTo(collageColor(Rect(0, 0, bgr.cols, bgr.rows)));
mcr.copyTo(collageColor(Rect(bgr.cols, 0, bgr.cols, bgr.rows)));
mcb.copyTo(collageColor(Rect(2 * bgr.cols, 0, bgr.cols, bgr.rows)));
cvtColor(collageColor, collageColor, COLOR_YCrCb2BGR);
////////////////////////////
// Blur Y
boxFilter(planes[0], planes[0], CV_8U, Size(7,7));
Mat3b blurred;
merge(planes, blurred);
cvtColor(blurred, blurred, COLOR_YCrCb2BGR);
imshow("Original", bgr);
imshow("YCrCb planes", collagePlanes);
imshow("YCrCb planes colored", collageColor);
imshow("Blurred", blurred);
waitKey();
return 0;
}
你将3通道图像分成3个1通道图像。 1通道图像是灰度,并将显示为灰色sh。他们的像素值实际上是一个颜色信息的事实是无关紧要的,他们仍然是灰度图像。所以,你的代码是好的,只是你的解释是不正确的。 – Miki
为了使它们变得丰富多彩,我应该在我的代码中添加什么?@Miki – Blu
'cvtColor(RGBImage,YCrCb,CV_BGR2YCrCb);'也许更好 – sturkmen