octave imread() question. I dont know why are they different

Viewed 211

I used 8bit grayscale 256x256 lena picture (figure3).

figure; imshow(imread('lena.png'))
figure; imshow(data)
figure; imshow('lena.png')

I think same outputs, but they are different outputs:

enter image description here

What's wrong in my code?

1 Answers

From the three different calls to imshow, the correct one seems to be the one where you just pass it the filepath. Reading the sourcecode for imshow you will see that it also reads the image colormap.

Seems like you don't have a simple grayscale image but instead you have an indexed image, so you should be doing this instead:

[img, cmap] = imread (...);
imshow (img, cmap);

By the way, it seems to me that you're trying to pre-allocate the image data. If so, you are doing it wrong.

# The pre-allocation with zeros here does nothing. Not only does
# imread creates its own new array, its data type will be uint8 while
# zeros is creating one of doubles by default.
data = zeros(256, 256) ;
data = imread('lena.png');  
Related