仅供参考定有错误木有绝对正确实验11—1closeall;clear;f=zeros(40,40);%f(10:30,10:30)=1;subplot(1,3,1);%imshow(f);%F=fft2(f)subplot(1,3,2);%imshow(F);%D=log(1+abs(F));%subplot(1,3,3);imshow(D);1——2clcloadimdemossaturn2subplot(121)imshow(saturn2)i=fftshift(fft2(saturn2));subplot(122)imshow(log(abs(i)),[]),colormap(jet(64)),colorbar;1——3w=imread('text.png');a=w(33:45,88:98);figure;imshow(w);figure;imshow(a);C=real(ifft2(fft2(w).*fft2(rot90(a,2),256,256)));figure;imshow(C,[]);max(C(:));thresh=60;figure;imshow(Cthresh);1——4RGB=imread('autumn.tif');figure(1),imshow(RGB);I=rgb2gray(RGB);figure(2),imshow(I);J=dct2(I);figure(3),imshow(log(abs(J)),[]),colormap(jet(64)),colorbar;J(abs(J)10)=0;K=idct2(J)/255;figure(4),imshow(K);1——5——2cr=0.125;sig=imread('cameraman.tif');sig=double(sig)/255;figure(1),imshow(sig);[m_sig,n_sig]=size(sig);sizi=8;snum=64;t=hadamard(sizi);hdcoe=blkproc(sig,[sizisizi],'P1*x*P2',t,t');coe=im2col(hdcoe,[sizisizi],'distinct');coe_temp=coe;[YInd]=sort(coe);[m,n]=size(coe);snum=snum-snum*cr;fori=1:ncoe_temp(Ind(1:snum),i)=0;endre_hdcoe=col2im(coe_temp,[sizisizi],[m_sign_sig],'distinct');re_sig=blkproc(re_hdcoe,[sizisizi],'P1*x*P2',t,t');re_sig=double(re_sig)/64;figure(2);imshow(re_sig);error=sig.^2-re_sig.^2;MSE=sum(error(:))/prod(size(re_sig));2——1i=imread('pout.tif');imshow(i);figure;subplot(1,2,1);imhist(i);j=histeq(i,64);subplot(1,2,2)imhist(j)2——2f=imread('autumn.tif');gl=imadjust(f,[01],[1,0]);subplot(121);imshow(f);subplot(122);imshow(gl);2——3f=imread('autumn.tif');gl=imadjust(f,[0.50.75],[1,0]);subplot(121);imshow(f);subplot(122);imshow(gl);2——4f=imread('autumn.tif');gl=imadjust(f,[],[],2);subplot(121);imshow(f);subplot(122);imshow(gl);test1I=imread('pout.tif');[row,col]=size(I);imshow(I);K=histeq(I,64)subplot(121)imhist(K);title('直方图均衡化')J=zeros(row,col);fori=1:rowforj=1:colif(I(i,j)10&&I(i,j)0)J(i,j)=0.5*I(i,j);elseif(I(i,j)20)J(i,j)=2*I(i,j)-15;elseif(I(i,j)30)J(i,j)=0.5*I(i,j)+15;elseJ(i,j)=0.5*I(i,j);endendendJ=uint8(J);subplot(122);imhist(J)title('线形变化')test2I=imread('cameraman.tif')figuresubplot(121)f=imcomplement(I);imshow(f)title('求反图像')I1=I;axis([50,250,50,200]);gridon;%显示网格线axison;%显示坐标系J=double(I1);J=40*(log(J+1));H=uint8(J);subplot(1,2,2),imshow(H);title('对数变换处理')3-1I=imread('eight.tif');J=imnoise(I,'salt&pepper',0.02);subplot(1,2,1);imshow(I);title('原始图像');subplot(1,2,2);imshow(J);title('噪声图像');K1=filter2(fspecial('average',3),J)/255;K2=filter2(fspecial('average',5),J)/255;K3=filter2(fspecial('average',7),J)/255;figure,imshow(K1);title('3*3模板均值滤波');figure,imshow(K2);title('5*5模板均值滤波');figure,imshow(K3);title('7*7模板均值滤波');title('7*7模板均值滤波');3-2I=imread('eight.tif');J=imnoise(I,'salt&pepper',0.02);subplot(2,2,1);imshow(J);title('噪声图像');K1=medfilt2(J,[33]);K2=medfilt2(J,[55]);K3=medfilt2(J,[77]);subplot(2,2,2);imshow(K1);title('3*3模板中值滤波');subplot(2,2,3);imshow(K2);title('5*5模板中值滤波');subplot(2,2,4);imshow(K3);title('7*7模板中值滤波');3-3f=imread('moon.tif');w4=fspecial('laplacian',0);w8=[111;1-81;111];f=im2double(f);g4=imfilter(f,w4,'replicate');g8=imfilter(f,w8,'replicate');G4=f-g4;G8=f-g8;imshow(f);figure,imshow(G4);figure,imshow(G8);3-4clear;I1=imread('moon.tif');subplot(2,2,1);imshow(I1);title('原始图像');I2=imnoise(I1,'salt&pepper');subplot(2,2,2);imshow(I2);title('噪声图像')';f=double(I2);g=fft2(f);g=fftshift(g);[N1,N2]=size(g);n=2;do=50;n1=fix(N1/2);n2=fix(N2/2);fori=1:N1forj=2:N2d=sqrt((i-n1)^2+(j-n2)^2);h=1/(1+0.414*(d/do)^(2*n));result1(i,j)=h*g(i,j);if(g(i,j)50)result2(i,j)=0;elseresult2(i,j)=g(i,j);endendendresult1=ifftshift(result1);result2=ifftshift(result2);X2=ifft2(result1);X3=uint8(real(X2));subplot(2,2,3);imshow(X3);title('Butterworth滤波图像');X4=ifft2(result2);X5=uint8(real(X4));subplot(2,2,4);imshow(X5);title('理想低通滤波器');test1I=imread('m83.tif');J=imnoise(I,'salt&pepper',0.02);subplot(2,2,1);imshow(J);title('噪声图像');K1=medfilt2(J,[33]);K2=medfilt2(J,[55]);K3=medfilt2(J,[77]);subplot(2,2,2);imshow(K1);title('3*3模板中值滤波');subplot(2,2,3);imshow(K2);title('5*5模板中值滤波');subplot(2,2,4);imshow(K3);title('7*7模板中值滤波');f=imread('board.tif');w4=fspecial('sobel');w8=[121;000;-1-2-1];f=im2double(f);g4=imfilter(f,w4,'replicate');g8=imfilter(f,w8,'replicate');G4=f-g4;G8=f-g8;imshow(f);figure,imshow(G4);figure,imshow(G8);test2f=imread('board.tif');w4=fspecial('sobel');w8=[121;000;-1-2-1];f=im2double(f);g4=imfilter(f,w4,'replicate');g8=imfilter(f,w8,'replicate');G4=f-g4;G8=f-g8;imshow(f);figure,imshow(G4);figure,imshow(G8);4-1clear;d=15h=zeros(2*d+1,2*d+1);h(d+1,1:2*d+1)=1/(2*d);f=imread('cameraman.tif');[m,n]=size(f);fe=zeros(m+2*d,n+2*d);fe(1:m,1:n)=f;he=zeros(m+2*d,n+2*d);he(1:2*d+1,1:2*d+1)=h;F=fft2(fe);H=fft2(he);ns=5*rand(m+2*d,n+2*d);g=ifft2(F.*H)+ns;G=fft2(g);K=0;F_est=((H.^2)./(H.^2+K)).*G./H;f_est=real(ifft2(F_est));imshow(f);figure;imshow(g(d+1:m+d,d+1:n+d),[min(g(:))max(g(:))]);figure;imshow(f_est(1:m,1:n),[min(f_est(:))max(f_est(:))]);4-2F=checkerboard(8);figure(1);imshow(F,[]);PSF=fspecial('motion',7,45);MF=imfilter(F,PSF,'circular');noise=imnoise(zeros(size(F)),'gaussian',0,0.01);MFN=MF+noise