3

Given the code

function [nImg,mask] = myFunc(img,rl,rh)


    [n m] = size(img);
    mask = ones(n, m);

    % do some stuff
    %   more 
    %   and more 
    % 

    fourierImg = fft2(img); % take the fourier transform 2d for the given image
    fourierImg = fftshift(fourierImg); %  shift the fourier transform 
    output = mask.*fourierImg; % calc with the mask  % THAT LINE CAUSES 
    %  Warning: Displaying real part of complex input ? 
    ishifting = ifftshift(output); % grab the DC element 
    nImg = ifft2(ishifting); % inverse back to the image dimension

end

I keep getting : Warning: Displaying real part of complex input when I execute the line output = mask.*fourierImg; % calc with the mask .

How can I fix that ?

Regards

JAN
  • 21,236
  • 66
  • 181
  • 318
  • This seems really unlikely. Does the warning still appear if you put `return;` right after that line, and disappear if you put `return;` right before it? – aschepler Jan 24 '13 at 17:57
  • @aschepler: If I remove that line then nothing appears , no shouts regarding real part or imaginary ... – JAN Jan 24 '13 at 17:58

1 Answers1

5

The warning means that you're trying to plot complex values on real axes.

I believe that it's not that line that triggers that warning, but rather a plot command (or its similar) somewhere else in your code.

The result of FFT transforms is usually complex, so if you want to plot these values, use two plots: one for the magnitude and one for the phase (or one plot for the real part and one for the imaginary part, but this is far less common to do so). To obtain the magnitude use the abs command.

Following your comment, instead of imshow(X) try imshow(abs(X)) or imshow(real(X)).

Eitan T
  • 32,660
  • 14
  • 72
  • 109
  • Yeap , you're right . When I do `imshow(X)` where `X` is one of the return values of the function ,then I get that message – JAN Jan 24 '13 at 18:00
  • When I do the `imshow` with `abs` then the picture is different ,blurred , any idea why ? thanks . – JAN Jan 24 '13 at 18:12
  • Probably because you have negative values, so `abs` distorts that. Try using `real` instead of `abs` then. But really, you need to understand what you're displaying. If the image has a significant imaginary part, it won't make much sense plotting the `real` part alone. – Eitan T Jan 24 '13 at 18:19