我有一个尺寸为640 * 480的RGB图像。我已经使用Matlab命令Rgbtoycbcr将其转换为Y Cb Cr图像,但我想分别显示Y Cb Cr组件作为图。我该怎么做?
答案 0 :(得分:6)
这是Benoit_11代码的扩展。此代码不是将每个通道的值显示为灰度图像,而是使用50%的常量值填充其他通道。这样,每个通道对最终图像的影响更容易观察。特别是Y通道的重要性是显而易见的。
RGB = imread('board.tif');
YCBCR = rgb2ycbcr(RGB);
figure;
lb={'Y','Cb','Cr'};
for channel=1:3
subplot(1,3,channel)
YCBCR_C=YCBCR;
YCBCR_C(:,:,setdiff(1:3,channel))=intmax(class(YCBCR_C))/2;
imshow(ycbcr2rgb(YCBCR_C))
title([lb{channel} ' component'],'FontSize',18);
end
答案 1 :(得分:3)
您可以像对RGB图像的红色,绿色或蓝色通道一样显示每个组件,索引图像的第三维。
简单示例:
RGB = imread('board.tif');
YCBCR = rgb2ycbcr(RGB);
figure;
subplot(1,3,1)
imshow(YCBCR(:,:,1))
title('Y component','FontSize',18);
subplot(1,3,2)
imshow(YCBCR(:,:,2))
title('Cb component','FontSize',18);
subplot(1,3,3)
imshow(YCBCR(:,:,3))
title('Cr component','FontSize',18);
输出:
答案 2 :(得分:0)
rgbImage = imread('C:\Users\Public\Pictures\Sample Pictures\Desert.jpg'); %# A sample RGB image
A = [65.481 -37.797 112; ... %# A 3-by-3 matrix of scale factors
128.553 -74.203 -93.786; ...
24.966 112 -18.214];
%# First convert the RGB image to double precision, scale its values to the
%# range 0 to 1, reshape it to an N-by-3 matrix, and multiply by A:
ycbcrImage = reshape(double(rgbImage)./255,[],3)*A;
%# Shift each color plane (stored in each column of the N-by-3 matrix):
ycbcrImage(:,1) = ycbcrImage(:,1)+16;
ycbcrImage(:,2) = ycbcrImage(:,2)+128;
ycbcrImage(:,3) = ycbcrImage(:,3)+128;
%# Convert back to type uint8 and reshape to its original size:
ycbcrImage = reshape(uint8(ycbcrImage),size(rgbImage));
imshow(ycbcrImage);
ycbcry = ycbcrImage;
ycbcry(:,:,2) = 2;
ycbcry(:,:,3) = 2;
rgb1 = ycbcr2rgb(ycbcry);
figure, imshow(rgb1);
% display the cb component as a color image
ycbcru = ycbcrImage;
ycbcru(:,:,1) = 4;
ycbcru(:,:,3) = 4;
rgb2 = ycbcr2rgb(ycbcru);
figure, imshow(rgb2);
% display the cr component as a color image
ycbcrv = ycbcrImage;
ycbcrv(:,:,1) = 8;
ycbcrv(:,:,2) = 8;
rgb3 = ycbcr2rgb(ycbcrv);
figure, imshow(rgb3);