Matlab - 如何修复:警告:显示复杂输入的实部?

JAN*_*JAN 3 matlab fft ifft

给定代码

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
Run Code Online (Sandbox Code Playgroud)

Warning: Displaying real part of complex input当我执行该行时,我不断收到: output = mask.*fourierImg; % calc with the mask

我该如何解决这个问题?

问候

Eit*_*n T 5

该警告意味着您正在尝试在实轴上绘制复数值。

我相信触发该警告的不是该行,而是plot代码中其他位置的命令(或其类似命令)。

FFT 变换的结果通常很复杂,因此如果要绘制这些值,请使用两张图:一张用于幅度,一张用于相位(或者一张用于实部,一张用于虚部,但这远远不够)这样做的情况较少见)。要获得幅度,请使用abs命令。

按照您的评论,而不是imshow(X)尝试imshow(abs(X))imshow(real(X))