Display Separated Color Channels of an RGB Image

This example creates a simple truecolor image and then separates the color channels (planes). The example displays each color channel and the original image.

Create an RGB image with uninterrupted areas of red, green, and blue. The dimensions of this image are 200-by-200 pixels. Display the image.

RGB=reshape(ones(200,1)*reshape(jet(200),1,600),[200,200,3]);
imshow(RGB)
title('Original RGB Image')

Separate the three color channels.

[R,G,B] = imsplit(RGB);

Display each color channel separately, along with the original RGB image. Notice that each separated color plane in the figure contains an area of white. The white corresponds to the highest values (purest shades) of each separate color. For example, in the Red Channel image, the white represents the highest concentration of pure red values. As red becomes mixed with green or blue, gray pixels appear. The black region in the image shows pixel values that contain no red values, i.e., R == 0.

subplot(2,2,1)
imshow(R)
title('Red Channel')

subplot(2,2,2)
imshow(G)
title('Green Channel')

subplot(2,2,3)
imshow(B)
title('Blue Channel')

subplot(2,2,4)
imshow(RGB)
title('Original Image')

Create an all-black channel.

allBlack = zeros(size(RGB, 1), size(RGB, 2), class(RGB));

Create color versions of the individual color channels.

justRed = cat(3, R, allBlack, allBlack);
justGreen = cat(3, allBlack, G, allBlack);
justBlue = cat(3, allBlack, allBlack, B);

Display all the channels and the original image in a montage.

montage({justRed, justGreen, justBlue, RGB}, 'ThumbnailSize', []);

See Also

Related Topics