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
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
plotcommand (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
abscommand.Following your comment, instead of
imshow(X)tryimshow(abs(X))orimshow(real(X)).