Issue with importing coloured image into MATLAB
1 view (last 30 days)
I have been working with images recently for my college project and everytime I try to import a coloured image, the image turns out as black and white. I did see some other codes to deal with this but it hasn't worked.
Can someone explain what I am doing wrong?
Gokul Nath S J on 5 Dec 2022
There is a possibility that your image might be in grayscale. Kindly check the dimension of the image matrix (img) imported after the following command.
img = imread(‘image.jpg’);
Please check whether there is any third dimension in the img matrix.
It would be helpful if you can share the code along with the image for further clarification.
Image Analyst on 5 Dec 2022
Is your colored image floating point with values outside the range of 0 to 1? If so everything 1 or larger will show up as white. Again, attach your image with the paperclip icon.
DGM on 6 Dec 2022
Edited: DGM on 6 Dec 2022
@Image Analyst is right. The easiest way to know what's wrong is to attach an example of the image in question and show how you're trying to read it.
Since we're guessing, I'm going to place my bet as well. I'm going to guess that it's an indexed image. If the image is indexed color, then you need to read the corresponding map as well and use it throughout whatever you do with the image.
[inpict map] = imread('canoe.tif'); % an indexed color image
imshow(inpict) % the index array is a 2D array and will be rendered as grayscale
imshow(inpict,map) % for the image to be rendered in color, a nondefault map is needed
This also demonstrates the problem with assuming that 2D images are grayscale. Request both outputs from imread() and check the map argument. If the map is empty, you can probably assume it's grayscale.
That said, there are plenty of other possible problems that can't be revealed by providing an example image. For example, you might be doing something like:
inpict = imread('peppers.png'); % an actual RGB image
roirangex = 100:200; % let's say we wanted to do some sort of indexing into it
roirangey = 100:200;
imshow(inpict(roirangey,roirangex,:)) % display a region of interest
In this case, the image is being read as color just fine, but if you had made a tiny abbreviation to the indexing expression by accident, you would get this instead:
imshow(inpict(roirangey,roirangex)) % display a region of interest (red channel only)
Note how dissimilar our suggestions are. That's how conversations struggle with poor specificity.