MATLAB: 8 bit depth RGB image(gif)

8 bit depth rgb image

is it possible to separate red ,green and blue channel of a 8 bit depth gif image with the following code?
redimg=im;
blueimg=im;
redimg(:,:,2:3)=0;
blueimg(:,:,1:2)=0;
greenimg=im;
greenimg(:,:,3)=0;
greenimg(:,:,1)=0;
if not then how can that be achieved?

Best Answer

Copy and paste this example code:
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
clear; % Erase all existing variables.
workspace; % Make sure the workspace panel is showing.
fontSize = 20;
% Change the filename to your filename!
[gifImage cmap] = imread('C:\Users\yourname\Pictures\whatever.gif');
% Display indexed GIF image.
subplot(2,3, 1);
imshow(gifImage);
% Convert to true color RGB image.
rgbImage = ind2rgb(gifImage, cmap);
title('GIF Image', 'FontSize', fontSize);
% Enlarge figure to full screen.
set(gcf, 'units','normalized','outerposition',[0 0 1 1]);
subplot(2,3, 2);
imshow(rgbImage);
title('After conversion to RGB', 'FontSize', fontSize);
% Extract the individual red, green, and blue color channels.
redChannel = rgbImage(:, :, 1);
greenChannel = rgbImage(:, :, 2);
blueChannel = rgbImage(:, :, 3);
% Display the three component color channels.
subplot(2,3, 4);
imshow(redChannel);
title('Red Channel', 'FontSize', fontSize);
subplot(2,3, 5);
imshow(greenChannel);
title('Green Channel', 'FontSize', fontSize);
subplot(2,3, 6);
imshow(blueChannel);
title('Blue Channel', 'FontSize', fontSize);
Related Question