%% localization demo %% transform image, threshold DFT, and reconstruct % get image load chess % get 2D FFT of image X= X-mean(mean(X)); % get rid of the DC component X = zeros(126); X(21:35,21:60)=1; FX = fft2(X); sFX = fftshift(FX); % display results figure(1) imshow(X,[]) title('original image'); figure(2) imshow(log(0.1+abs(sFX)),[]); title('shifted log(1+|dft|)'); %threshhold tlev = 0.05*max(max(abs(FX))); tFX = FX; J = find(abs(FX)< tlev); tFX(J) = zeros(size(J)); rX = real(ifft2(tFX)); stFX = fftshift(tFX); % display results figure(3) imshow(log(0.1+abs(stFX)),[]); title('thresholded, shifted log(1+|dft|)'); figure(4) imshow(rX,[]) title('reconstructed image'); figure(5) mesh(rX) rotate3d compression_ratio = 100-100*length(J)/length(X(:)) percent_retained_energy = 100*sum(sum(rX.*rX))/sum(sum(X.*X))