Matrix dimensions must agree.

7 views (last 30 days)
Fei Teng
Fei Teng on 18 May 2016
Answered: Chad Greene on 18 May 2016
I want to use the following code to do a lowpass filtering with my figure
f = imread('mri_snapshot.jpg'); PQ = 2*size(f); [U, V] = dftuv(PQ(1),PQ(2)); D = sqrt(U.^2+V.^2); D0 = 0.05*PQ(2); F = fft2(f,PQ(1),PQ(2)); H = exp(-(D.^2)/(2*(D0^2))); g = real(ifft2(H.*F)); g = g(1:size(f,1),1:size(f,2)); figure; imshow(g,[])
but g = real(ifft2(H.*F));, H.*F, the matrix dimension is not agree, because F = 956x928X3 while H= 956x928

Answers (1)

Chad Greene
Chad Greene on 18 May 2016
You could do this separately for the R, G, and B components of the image, then concatenate:
gR = real(ifft2(H.*squeeze(F(:,:,1))));
gG = real(ifft2(H.*squeeze(F(:,:,2))));
gB = real(ifft2(H.*squeeze(F(:,:,3))));
g = cat(3,gR,gG,gB);

Categories

Find more on Fourier Analysis and Filtering in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!