Issues with greyscale png images in matlab

I have a number of greyscale png images of faces (from a free dataset) that I am using as part of a Psychtoolbox experiment. In photo apps such as preview they all look okay, but when I open them in MATLAB several of them are pixelated and the colours are off so they are unusable (see attached photos). Any suggestions as to why this might be?
Thanks!

2 Comments

Can you attach the image as a file and post the code you used?
myimage = imread('F1.png');
imshow(myimage)

Sign in to comment.

 Accepted Answer

Dave B
Dave B on 18 Oct 2021
Edited: Dave B on 18 Oct 2021
This looks like the result of loading an indexed image, you can read the colormap using the second output of imread:
[img,cmap]=imread('image.png');
imshow(img,cmap)
Or you can convert it to an rgb image using ind2rgb:
img_rgb = ind2rgb(img,cmap);
imshow(img_rgb)

More Answers (0)

Products

Release

R2020a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!