Given a percentage
p, such as 75, compress the “winter” image by setting p percent of its Fourier coefficients to zero.
Solution.
p = 75;
im = imread('winter.png');
fc = fft2(im);
thr = prctile(abs(fc(:)), p);
fc(abs(fc) < thr) = 0;
im2 = uint8(real(ifft2(fc)));
imshow(im2)
The inverse Fourier transform may have imaginary part due to the truncation of Fourier coefficients and rounding errors in computations. This imaginary part is removed with
real. The result is converted to unsigned 8-bit integers with uint8.

