d0 = 30; % Cutoff frequency H = zeros(P, Q); for i = 1:P for j = 1:Q D = sqrt((i - P/2)^2 + (j - Q/2)^2); if D < d0 H(i, j) = 1; end end end subplot(3, 3, 5); imshow(H, []); title("Ideal Low Pass Filter");
% STEP 7: Apply the filter
G = F .* H; magnitudeG = log(1 + abs(G)); % Magnitude Spectrum of filtered result subplot(3, 3, 6); imshow(magnitudeG, []); title("Filtered Spectrum");
% STEP 8: Compute Inverse Fourier Transform
g = ifft2(G); g = real(g); % Take real part to avoid numerical errors g = g .* ((-1).^(0:P-1)' * (-1).^(0:Q-1)); % Center the spectrum back subplot(3, 3, 7); imshow(g, []); title("IFFT Result (Filtered Image)");
% STEP 9: Extract the filtered image
newImage = g(1:M, 1:N); % Crop back to original size subplot(3, 3, 8); imshow(newImage, []); title("Extracted Image (Final Output)"); Output: