im = imread('lena_color.png');

imagesc(im);axis image
imagesc(im(:,:,1),[0 255]);axis image;colormap gray
imagesc(im(:,:,2),[0 255]);axis image;colormap gray
imagesc(im(:,:,3),[0 255]);axis image;colormap gray

im = double(imread('lena.png'));
imagesc(im);axis image

IM=fft2(im);
imagesc(log(1e-10+abs(IM)));axis image
imagesc(fftshift(log(1e-10+abs(IM))));axis image
imagesc(im);axis image

im_filt=zeros(size(im));
im_filt(1:20,1:20) = 1;
imagesc(im_filt);axis image

imagesc(ifft2(fft2(im).*fft2(im_filt)));axis image

im_filt=zeros(size(im));
im_filt(100:120,100:120) = 1;
imagesc(im_filt);axis image

imagesc(ifft2(fft2(im).*fft2(im_filt)));axis image
imagesc(ifft2(fft2(im,768,768).*fft2(im_filt,768,768)));axis image

for D=0:5
    im_filt=zeros(size(im));
    im_filt(1:D+1,1:D+1) = 1/(2*D+1)^2;
    im_filt(1:D+1,end-D+1:end) = 1/(2*D+1)^2;
    im_filt(end-D+1:end,1:D+1) = 1/(2*D+1)^2;
    im_filt(end-D+1:end,end-D+1:end) = 1/(2*D+1)^2;
%     imagesc(im2);axis image
    
    im_noise = im+30*randn(size(im));
    im_denoise = ifft2(fft2(im_noise).*fft2(im_filt));
    imagesc(im_denoise,[0 255]);axis image
    pause
end
