1
votes

I've started learning about image processing in Matlab and I have a small problem.

I'm trying to visualize FFT of images. The function imshow does what I need, when I supply the empty matrix (e.g. sintax imshow(image, [] ).

Now, the imshow does a good job because when supplied with the empty matrix, it will display the lowest value in the picture as black, the highest as white and will adjust all the other values accordingly. (at least that is how I understood it).

The scaling that imshow does is great and I was wondering if there is a Matlab function that would take an image and perform that kind of scaling? I thought of saving the pictures manually after using imshow, but I would like to do this programatically.

I assume there is a nice Matlab feature that does this, but after googling around, I couldn't find any solutions.

3

3 Answers

1
votes

What you want is to rescale your image so that its minimum is zero, and its maximum is 255 (for 8-bit image) before calling imwrite.

For example:

img = randn(100);
figure,imshow(img,[]); %# show the image

mx = max(img(:));
mn = min(img(:));

imgScaled = (img-mn)/(mx-mn);

%# convert to uint8 and save
imwrite( uint8(round(imgScaled*255))), 'test.tif');

%# reload and display without scaling 
%# if we have done everything correctly
%# the images before and after should look alike
imgLoaded = imread('test.tif');
figure,imshow(imgLoaded)
0
votes

Sounds like imagesc is what you want, here. But naturally to display a FFT you'll have to get rid of the complex values, e.g. do something like create magnitude, phase plots separately. But this said, imshow already is a Matlab function that does scaling so I'm not quite sure why you need a new function; imagesc lets you get color, at least.

Then for saving, use imwrite.

0
votes

There are lots of good answers to this, but for a quick hack you might want to print what you see in the figure, just see doc print for more info.