load trees
x=ind2gray(X,map);
clf;
imshow(x,64), title('original Image');

 [nr,nc]=size(x);
disp('press a key')
pause
% linear filtering
[f1,f2]=freqspace([11,11]);
[x1,y]=meshgrid(f1,f2);
Hd=zeros(size(x1));
d=find(sqrt(x1.*x1+y.*y)>.3); 
Hd(d)=ones(size(d));; h=fwind1(Hd,hamming(11));
disp('press a key')
pause
N=filter2(h,imnoise(zeros(258,350),'gaussian'));
colormap(jet),imagesc(log(abs(fftshift(fft2(N)))));
colorbar; title('High frequency noise is created and its fft is displayed');
disp('press a key')
pause
deg_x=max(0,min(x+N,1));
imshow(deg_x,64), title('Image degraded with the above noise');
disp('press a key')
pause
[f1,f2]=freqspace([11,11]);
[x1,y]=meshgrid(f1,f2);
Hd=zeros(size(x1));
d=find(sqrt(x1.*x1+y.*y)<.3); 
Hd(d)=ones(size(d));; h=fwind1(Hd,hamming(11));
k=filter2(h,deg_x);
imshow(k,64); title('Filtered image');
disp('press a key')
pause
% Wiener filtering
nois_x=imnoise(x,'gaussian');
k=wiener2(nois_x,[3 3],[50 50]);
subplot(1,2,1),imshow(nois_x,64), title('Image corrupted with gaussian noise');
subplot(1,2,2),imshow(k,64), title('After Wiener filtering');
disp('press a key')
pause
noi_x=imnoise(x,'salt & pepper');
k=medfilt2(noi_x,[3 3],[50 50]);
subplot(1,2,1),imshow(noi_x,64), title('Image corrupted with Speckle noise');
subplot(1,2,2),imshow(k,64), title('After Median filtering');



