MATLAB: How to get R component from an image that is found in a listbox and display it on a new axis

guideImage Processing Toolboxlistbox rgb axes images processing

I have a button to load the images in a listbox, the listbox which displays the images on an axes. I want to display the images R , G , B components separately on a different axis. My code is something like this :
handles.output = hObject;
index = get(handles.listbox1,'value');
R =double (index(:,:,1));
axes(handles.C);
imshow (R);
guidata(hObject, handles);
I get a black or white or the same picture on axis C. Can somebody help me? I have a due date at my College and I can't figure it out.
The code is placed on the pushbutton that I want to manipulate the pictures.

Best Answer

Don't use double() or imdouble(). Try this:
index = get(handles.listbox1,'value');
allFilenames = get(handles.listbox1,'String');
filename = allFilenames{index}
rgbImage = imread(filename);
if ndims(rgbImage) == 3
% Extract the individual red, green, and blue color channels.
redChannel = rgbImage(:, :, 1);
greenChannel = rgbImage(:, :, 2);
blueChannel = rgbImage(:, :, 3);
axes(handles.axesRed);
imshow(redChannel);
axes(handles.axesGreen);
imshow(greenChannel );
axes(handles.axesBlue);
imshow(blueChannel );
else
message = sprintf('%s is not an RGB image', filename);
uiwait(warndlg(message));
end
Make sure you have 3 axes for the 3 different color channels.