%  write learnhighpass('saturn.tif',150)


function recon = learnlowpass(image,coef) 
    warning off;
    image=imread(image);
    k=coef;
    [m,n] = size(image);
    if mod(m,2)
        m=m-1;
    end
    if mod(n,2) 
        n=n-1;
    end
    image=image(1:m,1:n);   % original image
    IMAGE = fftshift(fft2(image));  % transformed image
    recon = zeros(m,n);     % compressed image         
     
    figure(1), clf;
    lowpass=IMAGE;
    %tmp=zeros((m-k)/2:(m-k)/2+k,(n-k)/2:(n-k)/2+k);
    %lowpass((m-k)/2:(m-k)/2+k,(n-k)/2:(n-k)/2+k)=tmp;
    for i=(m-k)/2:(m-k)/2+k
        for j=(n-k)/2:(n-k)/2+k
            lowpass(i,j)=0;
        end
    end
    
        
    recon=real(ifft2(fftshift(lowpass)));
	
    subplot(2,2,2),imagesc(image),colormap gray, axis image, axis off ;
    subplot(2,2,1),fftshow(image);
    subplot(2,2,3),imagesc(log(abs(lowpass))),colormap(gray),axis image,axis off;
    subplot(2,2,4),imagesc(recon),colormap(gray),axis image,axis off;
    hold on;
     
    sprintf('the compression ratio is %0.5g',m*n/(coef*coef))
  
function IMAGE=fftshow(image)

IMAGE = fft2(image);
imagesc(fftshift(log(abs(IMAGE)))),colormap gray, axis image
    axis off;