Error using imgaussfilt Expected A to be real.

10 visualizaciones (últimos 30 días)
Gulfam Saju
Gulfam Saju el 31 de Mzo. de 2022
Respondida: Paras Gupta el 22 de Sept. de 2023
%demo
clear all;
CoilNum = 12;
load slice66.mat;
for s = 1 : CoilNum
Img(:,:,s) = ifft2(raw_data(:,:,s));
end
image1= Img;
load slice94.mat;
for s = 1 : CoilNum
Img2(:,:,s) = ifft2(raw_data(:,:,s));
end
image2= Img2;
psnr_=getPSNR(image1,image2);
ssim_=getMSSIM(image1,image2);
fprintf('PSNR= %f - SSIM= %f\n',psnr_,ssim_);
While I run this code, I get this error.
Error using imgaussfilt
Expected A to be real.
Error in imgaussfilt>parseInputs (line 398)
validateattributes(A, supportedClasses, supportedImageAttributes, mfilename, 'A');
Error in imgaussfilt (line 121)
[A, options] = parseInputs(args{:});
Error in getMSSIM (line 16)
mu1=imgaussfilt(frameReference,1.5);
Error in demo (line 16)
ssim_=getMSSIM(image1,image2);

Respuestas (1)

Paras Gupta
Paras Gupta el 22 de Sept. de 2023
Hi Gulfam,
I understand that you are getting an error while using the imgaussfilt function in MATLAB.
The error message in the question indicates that the imgaussfilt function expects the input image A to be real, but it seems to be receiving a complex-valued image.
The potential reason for this issue is the use of “ifft2” function on the variable “raw_datafor each of the slices. Fourier transform operates in the frequency domain, where the data can have both real and imaginary components. When performing an inverse Fourier transform using ifft2function in MATLAB, the resulting image may be complex-valued. This can happen in the following cases:
  • If the input is complex-valued
  • If the input data is not symmetric or centered
  • Even when the input data is real-valued, the output may have small imaginary components that are close to zero due to numerical precision limitations.
To resolve this issue, you can use the ‘real’ function in MATLAB to extract the real part of the complex valued images before passing them to the “getMSSIM” function.
image1 = real(Img); % Convert to real-valued image
image2 = real(Img2); % Convert to real-valued image
psnr_=getPSNR(image1,image2);
ssim_=getMSSIM(image1,image2);
fprintf('PSNR= %f - SSIM= %f\n',psnr_,ssim_);
Please refer to the following documentations for more information:
Hope this helps.

Productos

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by