Displaying Y Cb and Cr components in Matlab
我有一个尺寸为640 * 480的RGB图像。 我已通过使用Matlab命令Rgbtoycbcr将其转换为Y Cb Cr图像,但我想分别显示Y Cb Cr分量,如图所示。 我该怎么做?
这是Benoit_11代码的扩展。 该代码不是将每个通道的值显示为灰度图像,而是以50%的恒定值填充其他通道。 这样,每个通道对最终图像的影响就更容易观察到。 特别是Y通道的重要性是显而易见的。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
您可以显示每个组件,就像对RGB图像的第3维索引的红色,绿色或蓝色通道一样。
简单的例子:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
输出:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | 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); |