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.

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.

title('Red Channel')

title('Green Channel')

title('Blue Channel')

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