中南民族大学数字图像处理实验报告学院:电子信息工程学院专业:光信息学生学号实验一图像变换实验目的1:了解二维fourier变换的原理2:掌握二维fourier变换的性质3:掌握离散余弦变换的原理实验内容1.绘制一个二值,并将其傅里叶函数可视化。
close all;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);运行结果:2.对给定的一副图像saturn2.tif进行傅里叶变换load imdemos saturn2;subplot(1,2,1);imshow(saturn2);I=fftshift(fft2(saturn2));subplot(1,2,2);imshow(log(abs(I)),[]),colormap(jet(64)),colorbar运行结果:3.在图像text,tif中定位字母aw=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(C>thresh);运行结果:0 5 104.对一幅图进行离散余弦变换和反变换RGB=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);105-5思考题1.编写M程序文件验证二维傅里叶变换的平移性,旋转性clear all;image1=zeros(128,128);image1(30:93,52:67)=1;subplot(2,2,1);imshow(image1,[]);title('原始图像');image2=abs(fft2(image1));subplot(2,2,2);imshow(log10(1+image2),[]);title('频谱');image3=image1;i=size(image1,1);j=size(image2,2);for k=1:ifor r=1:jimage3(k,r)=(-1)^(k+r).*image1(k,r);endendimage4=abs(fft2(image3));subplot(2,2,3);imshow(image3,[])title('中心化后的图像');subplot(2,2,4);imshow(log10(1+image4),[]);title('中心化后的频谱');image5=zeros(i,j);i=round(i/2)j=round(j/2)for u=-i:ifor v=-j:jm=cos(pi/4)*u-sin(pi/4)*v;n=sin(pi/4)*u+cos(pi/4)*v;m=round(m);n=round(n);if abs(m)<i&&abs(n)<jimage5(u+i+1,v+j+1)=image1(m+i,n+j);endendendfiguresubplot(2,1,1);imshow(image5,[]);image6=abs(fft2(image5));subplot(2,1,2);imshow(log10(1+image6),[]);运行结果实验二 图像的空间变换增强实验目的1:掌握图像的直方图均衡化的原理与应用 2:掌握灰度变换的原理与应用 3:掌握伪彩色图像处理增强的方法实验内容1.MATLAB 提供的直方图修正函数I=imread('pout.tif'); subplot(221); imshow(I); subplot(222); imhist(I);J=histeq(I,64); subplot(223); imshow(J); subplot(224);imhist(J);00100200001002002.通过灰度变换调整图像对比度f=imread('e:\myimage\breast.tif');g1=imadjust(f,[0 1],[1,0],1);g2=imadjust(f,[0.5 0.75],[0,1],1);g3=imadjust(f,[ ],[ ],2);subplot(221);imshow(f);subplot(222);imshow(g1);subplot(223);imshow(g2);subplot(224);imshow(g3);思考题1.对pout.tif的灰度图像,进行如图所示的分段线性变换处理f=imread('pout.tif');[row,col] = size(f);g= zeros(row,col);for x=1:rowfor y=1:colif (f(x,y)<32)g(x,y) = f(x,y)*2;elseif ( f(x,y)>192)g(x,y) = f(x,y)*1.5-128;elseg(x,y) = f(x,y)*0.6+44.8;endendendsubplot(1,2,1);imshow(f);subplot(1,2,2);imshow(g,[]);2.分别对图像cameraman.tif进行求反和对数变换处理I=imread('cameraman.tif');subplot(131);imshow(I);I=double(I);[M,N]=size(I);for i=1:Mfor j=1:NJ(i,j)=255-I(i,j);endendsubplot(132);imshow(mat2gray(J));for i=1:Mfor j=1:NH(i,j)=log(I(i,j)+1);endendsubplot(133);imshow(mat2gray(H));实验三图像的滤波增强处理实验目的1.了解空域增强的基本原理2.掌握平滑滤波器和锐化滤波器的使用3.掌握图像中值滤波增强的结果实验内容1.对一副图像进行不同大小的模板的均值滤波,并比较结果I=imread('eight.tif');J=imnoise(I,'salt & pepper',0.02);subplot(2,2,1);imshow(J);title('原始图像');K1=medfilt2(J,[3 3]);K2=medfilt2(J,[5 5]);K3=medfilt2(J,[7 7]);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模板均值滤波');原始图像噪声图像7*7模板均值滤波5*5模板均值滤波2.对一副图像实现不同模板的中值滤波,并比较结果I=imread('eight.tif');J=imnoise(I,'salt & pepper',0.02);imshow(I);title('原始图像');subplot(2,2,1);imshow(J);title('噪声图像');k1=medfilt2(J,[3 3]);k2=medfilt2(J,[5 5]);k3=medfilt2(J,[7 7]);subplot(2,2,2);imshow(k1);title('3*3模板中值滤波');subplot(2,2,3);imshow(k1);title('5*5模板中值滤波');subplot(2,2,4);imshow(k1);title('7*7模板中值滤波');运行结果:噪声图像3*3模板中值滤波5*5模板中值滤波7*7模板中值滤波3.使用filter2函数和fspecial函数来实现边缘锐化处理f=imread('moon.tif');w4=fspecial('laplacian',0);w8=[1 1 1;1 -8 1;1 1 1];g4=imfilter(f,w4,'replicate');g8=imfilter(f,w8,'replicate');G4=f-g4;G8=f-g8;subplot(1,3,1);imshow(f);subplot(1,3,2);imshow(G4);subplot(1,3,3);imshow(G8);3.用sobel算子prewit算子log算子对图进行锐化处理I=imread('cameraman.tif');k1=fspecial('sobel');S=imfilter(I,k1,'replicate');k2=fspecial('prewitt');P=imfilter(I,k2,'replicate');k3=fspecial('log');L=imfilter(I,k3,'replicate');subplot(2,2,1);imshow(I);title('原图');subplot(2,2,2);imshow(S);title('sobel算子');subplot(2,2,3);imshow(P);title('prewitt算子');subplot(2,2,4);imshow(L);title('log算子');4.对一副图像加入椒盐噪声后,实现butterworth低通滤波I1=imread('saturn2.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; d0=50;n1=fix(N1/2); n2=fix(N2/2); for i=1:N1 for j=2:N2d=sqrt((i-n1)^2+(j-n2)^2);h=1/(1+0.414*(d/d0)^(2*n));%butterworth result1(i,j)=h*g(i,j); if (g(i,j)>50)result2(i,j)=0; elseresult2(i,j)=g(i,j); end end endresult1=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(uint8(X5));title('理想低通滤波图像');原始图像噪声图像butterworth 滤波图像理想低通滤波图像5.对一副图像moon.tif 实现butterworth 高通滤波高通滤波I1=imread('moon.tif');f=double(I1);subplot(1,2,1);imshow(I1);title('原始图像'); g=fftshift(fft2(f)); [N1,N2]=size(g); n=2; d0=50;n1=fix(N1/2); n2=fix(N2/2); for i=1:N1 for j=2:N2d=sqrt((i-n1)^2+(j-n2)^2);h=1-1/(1+0.414*(d/d0)^(2*n));%butterworth result1(i,j)=h*g(i,j); end endresult1=ifftshift(result1); X2=ifft2(result1); X3=uint8(real(X2)); subplot(1,2,2);imshow(X3);title('butterworth 高通滤波图像');思考题原始图像butterworth 高通滤波图像1.用合适的方法分别对图A 所示的花粉图像和图B 所示的电路板图像进行增强处理。