MATLAB: In the following code imshow(img(:,:,1)) displays image, while storing that in image(:,:,1) and displaying it gives white figure..plz help me rectify it…Thanks

colorimageprocessingImage Processing Toolbox

img=imread('1.jpg');
image(:,:,1)=img(:,:,1);
imshow(img(:,:,1))
figure,imshow(image(:,:,1))

Best Answer

You should not do this:
image(:,:,1)=img(:,:,1);
because image() is a built-in function. Pick another name.
If an image displays as all white or all black, the usual situation is that the image variable is floating point, not a uint8 or uint16. What is the class of the variable you're trying to display. To make it work with a floating point variable, add [] to imshow():
imshow(img(:,:,1), []);