MATLAB imread reads a color GIF as gray-scale

Viewed 733

When I try to read the following GIF image using imread:

enter image description here

I get to see this gray-scale image instead:

enter image description here

This is the code to reproduce the issue:

img = imread('https://i.stack.imgur.com/ISgSJ.gif');
imshow(img)

MATLAB reads other images correctly. What is wrong with this particular image? How should I read it?

1 Answers

This GIF image has a color map. You need to read the color map in separately and use it for display:

[img, cm] = imread('https://i.stack.imgur.com/ISgSJ.gif');
imshow(img, cm)

To convert the image to an RGB image, use ind2rgb:

img = ind2rgb(img, cm);
Related