當你分割一個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