
# komprese obrazku

close all

n_komp=44000;

obr=imread('fiat3.jpg');

figure(1);

imshow(obr);


vel=size(obr)

spektr=fftshift(fft2(ifftshift(obr)));


figure(2);

imshow(abs(spektr),[0,max(max(abs(spektr)))/100])

spektr_lin=spektr(:);

intens=abs(spektr_lin);

[intens2,idx]=sort(intens,'descend'); 

figure(3)

bar(intens2(1:100))

spektr_lin_filt=spektr_lin;


for n_komp=round(logspace(log10(2),log10(100000),30))

n_komp

spektr_lin_filt=spektr_lin;

spektr_lin_filt(idx(n_komp+1:end))=0;

spektr_filt=reshape(spektr_lin_filt,vel(1),vel(2));

obr2=real(fftshift(ifft2(ifftshift(spektr_filt))));

figure(4)

imshow(obr2,[0,max(max(obr2))])

str=strcat("komponenty: ",int2str(n_komp));
str=strcat(str," / "); str=strcat(str,int2str(vel(1)*vel(2)));

title(str)

pause(1)

endfor



