Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why doesn't my image load properly in MATLAB?

This is my original image:

enter image description here

But when I load it up on MATLAB and use imshow() on it, this is how I see it:

enter image description here

This is the code I'm using:

I=imread('D:\Matty\pout.gif')
 imshow(I)
like image 270
GrowinMan Avatar asked Feb 15 '12 14:02

GrowinMan


2 Answers

Forget what I said earlier. It has to do with the colormap. The image seems to have a funky colormap. Generally you should be able to read the colormap with [X, map] = imread(...), but there is some clipping of the data that I don't fully understand.

I copied the colormap manually out of the raw data from a hexeditor and saved it as gif_colormap.txt

B1 B1 B1 AF AF AF AB AB AB A9 A9 A9 A7 A7 A7 A3 A3 A3 A1 A1 A1 9F 9F 9F 9D 9D 9D 9B 9B 9B 99 99 99 97 97 97 95 95 95 93 93 93 91 91 91 8F 8F 8F 8B 8B 8B 89 89 89 85 85 85 83 83 83 7F 7F 7F 7D 7D 7D 7B 7B 7B 79 79 79 77 77 77 75 75 75 71 71 71 6D 6D 6D 6B 6B 6B 69 69 69 67 67 67 65 65 65 63 63 63 61 61 61 5F 5F 5F 5D 5D 5D 5B 5B 5B 59 59 59 57 57 57 53 53 53 4D 4D 4D 4B 4B 4B E0 E0 E0 DC DC DC DA DA DA D6 D6 D6 D4 D4 D4 D2 D2 D2 D0 D0 D0 CE CE CE CC CC CC CA CA CA C8 C8 C8 C4 C4 C4 C2 C2 C2 C0 C0 C0 BE BE BE BA BA BA B8 B8 B8 B6 B6 B6 B4 B4 B4 B2 B2 B2 B0 B0 B0 AE AE AE AC AC AC AA AA AA A6 A6 A6 A4 A4 A4 A2 A2 A2 A0 A0 A0 9E 9E 9E 9C 9C 9C 9A 9A 9A 96 96 96 94 94 94 92 92 92 90 90 90 8E 8E 8E 8A 8A 8A 88 88 88 86 86 86 84 84 84 82 82 82 80 80 80 7E 7E 7E 7A 7A 7A 78 78 78 74 74 74 72 72 72 70 70 70 6E 6E 6E 6C 6C 6C 6A 6A 6A 66 66 66 62 62 62 5E 5E 5E 56 56 56 54 54 54 52 52 52 50 50 50 4E 4E 4E 4A 4A 4A DF DF DF DD DD DD DB DB DB D7 D7 D7 D5 D5 D5 D3 D3 D3 D1 D1 D1 CF CF CF CD CD CD C9 C9 C9 C7 C7 C7 C5 C5 C5 C3 C3 C3 C1 C1 C1 BD BD BD BB BB BB B9 B9 B9 B5 B5 B5 B3 B3 B3

Then I read in the new colormap and set it manually

fid = fopen('gif_colormap.txt', 'r')
A = fscanf(fid, '%x ');
fclose(fid);
my_map = reshape(A,3,121)'

im = imread('pout.gif');

%colormap has to be between 0 and 1
my_map = (my_map-min(my_map(:)))/max(my_map(:)); 

imshow(im,[])

%set colormap manually
colormap(my_map);

result image of pouting girl

like image 123
Lucas Avatar answered Oct 24 '22 09:10

Lucas


GIF is indexed format, and each image can have its own colormap. So you need to read the colormap together with the image:

[I, Imap] = imread('D:\Matty\pout.gif');
imshow(I,Imap)

I've tested it on your image and it works very well. i don't understand what was the problem @Lucas described in his answer.

like image 35
yuk Avatar answered Oct 24 '22 09:10

yuk