How do I split a color image into its 3 RGB channels?

Illustration
krastinedekart - 2022-07-01T09:45:53+00:00
Question: How do I split a color image into its 3 RGB channels?

Hi, How can I split a color image into its 3 RGB channels, like in this link: http://www.originlab.com/www/products/images/ChannelSplit_Merge.png ( Image link ) 

Expert Answer

Profile picture of John Williams John Williams answered . 2025-11-20

For this you an follow this code :

% Read in original RGB image.
rgbImage = imread('flower.webp');
 
% Extract color channels.
redChannel = rgbImage(:,:,1); % Red channel
greenChannel = rgbImage(:,:,2); % Green channel
blueChannel = rgbImage(:,:,3); % Blue channel
% Create an all black channel.
allBlack = zeros(size(rgbImage, 1), size(rgbImage, 2), 'uint8');
 
% Create color versions of the individual color channels.
just_red = cat(3, redChannel, allBlack, allBlack);
just_green = cat(3, allBlack, greenChannel, allBlack);
just_blue = cat(3, allBlack, allBlack, blueChannel);
 
% Recombine the individual color channels to create the original RGB image again.
recombinedRGBImage = cat(3, redChannel, greenChannel, blueChannel);
 
% Display them all.
subplot(3, 3, 2);
imshow(rgbImage);
fontSize = 20;
title('Original RGB Image', 'FontSize', fontSize)
subplot(3, 3, 4);
imshow(just_red);
title('Red Channel in Red', 'FontSize', fontSize)
subplot(3, 3, 5);
imshow(just_green)
title('Green Channel in Green', 'FontSize', fontSize)
subplot(3, 3, 6);
imshow(just_blue);
title('Blue Channel in Blue', 'FontSize', fontSize)
subplot(3, 3, 8);
imshow(recombinedRGBImage);
title('Recombined to Form Original RGB Image Again', 'FontSize', fontSize)
 
set(gcf, 'Name', 'Demo by ImageAnalyst', 'NumberTitle', 'Off')


Not satisfied with the answer ?? ASK NOW

Get a Free Consultation or a Sample Assignment Review!