1、实验四图像增强实验四-图像增强 信息工程学院实验报告成 绩:指导老师(签名):课程名称:数字图像处理 实验项目名称:实验四 图像增强 实验时间:2016.11.08 班级: 姓名: 学号: 一、实验目的1.了解图像增强的目的及意义,加深对图像增强的感性认识,巩固所学理论知识。2. 掌握图像空域增强算法的基本原理。3. 掌握图像空域增强的实际应用及MATLAB实现。4. 掌握频域滤波的概念及方法。5. 熟练掌握频域空间的各类滤波器。6.掌握怎样利用傅立叶变换进行频域滤波。7. 掌握图像频域增强增强的实际应用及MATLAB实现。二、实验步骤及结果分析1. 基于幂次变换的图像增强 程序代码:clea
2、r all;close all;I1=double(imread(fig534b.tif);I1=I1/255;figure,subplot(2,4,1);imshow(I1,);hold onI2=double(imread(room.tif);I2=I2/255;subplot(2,4,5);imshow(I2,);hold onfor m=1:2 Index=0; for lemta=0.5 5 Index=Index+1; FmIndex=Im.lemta;subplot(2,4,(m-1)*4+Index+1),imshow(FmIndex,)endend执行结果:图1 幂次变换增强
3、结果实验结果分析:由实验结果可知,当r1时,黑色区域被压缩,变的几乎不可见。2. 直方图规定化处理程序代码:clear allclc close all%0.读图像I=double(imread(lena.tiff);subplot(2,4,1);imshow(I,);title(原图)N=32;Hist_image=hist(I(:),N);Hist_image=Hist_image/sum(Hist_image);Hist_image_cumulation=cumsum(Hist_image);%累计直方图subplot(245);stem(0:N-1,Hist_image);title(
4、原直方图);%1.设计目标直方图Index=0:N-1;%正态分布直方图Hist1=exp(-(Index-N/2).2/N);Hist1=Hist1/sum(Hist1);Hist_cumulation1=cumsum(Hist1);subplot(242);stem(0:N-1,Hist1);title(规定化直方图1);%倒三角形状直方图Hist2=abs(2*N-1-2*Index);Hist2=Hist2/sum(Hist2);Hist_cumulation2=cumsum(Hist2);subplot(246);stem(0:N-1,Hist2);title(规定化直方图2);%2
5、. 规定化处理Project1=zeros(N);Project2=zeros(N);Hist_result1=zeros(N);Hist_result2=zeros(N);for m=1:2 Image=I;%SML处理(SML,Single Mapping Law单映射规则 for k=1:NTemp=abs(Hist_image_cumulation(k)-Hist_cumulationm); Temp1,Projectm(k)=min(Temp); end%2.2 变换后直方图 for k=1:N Temp=find(Projectm=k); if isempty(Temp) Hist
6、_resultm(k)=0; else Hist_resultm(k)=sum(Hist_image(Temp); end end subplot(2,4,(m-1)*4+3); stem(0:N-1,Hist_resultm); title(变换后的直方图,num2str(m); %2.3结果图Step=256/N;for K=1:N Index=find(I=Step*(k-1)&IStep*k); Image(Index)=Projectm(k);endsubplot(2,4,(m-1)*4+4),imshow(Image,); title(变换后的结果图,num2str(m);end执
7、行结果:图2 直方图规定化实验结果分析:由实验结果可知,采用直方图规定化技术后,原图的直方图逼近规定化的直方图,从而有相应的变换后的结果图1和变换后的结果图2。3. 灰度图像常用平常、锐化滤波程序代码:clear all;close all;%0.原图I=double(imread(lena.tiff);subplot(2,4,1);imshow(I,);title(原图);%1.均值低通滤波H=fspecial(average,5);F1=double(filter2(H,I);subplot(2,4,2);imshow(F1,);title(均值低通滤波);%2.gaussian 低通滤波
8、H=fspecial(gaussian,7,3);F2=double(filter2(H,I);subplot(2,4,3);imshow(F2,);title(高斯低通滤波);%3.增强图像=原图-均值低通滤波F3=2*I-F1;subplot(2,4,4);imshow(uint8(F3),);title(原图-均值低通滤波);%4.增强图像=原图-高斯低通滤波F4=2*I-F2;subplot(2,4,5);imshow(uint8(F4),);title(原图-高斯低通滤波);%5.prewitt边缘算子增强H=fspecial(prewitt);F5=uint8(I+filter2(
9、H,I);subplot(2,4,6);imshow(F5,);title(prewitt边缘算子增强);%6.soble边缘算子增强H=fspecial(sobel);F6=uint8(I+filter2(H,I);subplot(2,4,7);imshow(F6,);title(sobel边缘算子增强);执行结果:图3 灰色图像平滑、锐化实验结果分析:由实验结果可知,均值和高斯滤波都使原图模糊,而采用原图减去低通滤波图像方法、prewitt算子、sobel算子都可以增强图像边缘。4. 频率域滤波:对于给定图像+噪声,使用不同的频域滤波器对图像进行滤波处理。(1)用Butterworth低通
10、滤波器实现图像信号的滤波运算。程序代码:clear all;close all;%(a)读入并显示图像electric.tif;I=imread(electric.tif);subplot(2,3,1),imshow(I);title(原图像);%(b)利用imnoise 命令在图electric.tif 上加入高斯(gaussian) 噪声;J=imnoise(I,gaussian,0,0.01);subplot(2,3,2),imshow(J);title(加入高斯噪声的图像);%(c)用Butterworth低通滤波器实现图像信号的滤波运算,变换不同的截止频率dI1=fftshift(f
11、ft2(J);m,n=size(I1);N=2;d1=30;d2=50;d3=70;d4=90;n1=floor(m/2);n2=floor(n/2);for i=1:m for j=1:n d=sqrt(i-n1)2+(j-n2)2); H1=1/(1+(d/d1)(2*N); H2=1/(1+(d/d2)(2*N); H3=1/(1+(d/d3)(2*N); H4=1/(1+(d/d4)(2*N); I3(i,j)=H1*I1(i,j); I5(i,j)=H2*I1(i,j); I7(i,j)=H3*I1(i,j); I9(i,j)=H4*I1(i,j); endendI3=ifftshi
12、ft(I3);I4=real(ifft2(I3);I5=ifftshift(I5);I6=real(ifft2(I5);I7=ifftshift(I7);I8=real(ifft2(I7);I9=ifftshift(I9);I10=real(ifft2(I9);subplot(2,3,3),imshow(I4,),title(Butterworth低通滤波器d1=30);subplot(2,3,4),imshow(I6,),title(Butterworth低通滤波器d2=50);subplot(2,3,5),imshow(I8,),title(Butterworth低通滤波器d3=70);s
13、ubplot(2,3,6),imshow(I10,),title(Butterworth低通滤波器d4=90);执行结果:图4 Butterworth低通滤波器滤波结果实验结果分析:由实验结果可知,采用Butterworth低通滤波器对加噪声的图像进行滤波运算,滤波器的截止频率d越小,滤波后的图像越模糊。(2)用理想低通滤波器实现图像信号的滤波运算程序代码:clear all;close all;I=imread(electric.tif);subplot(2,3,1),imshow(I);title(原图像);F=imnoise(I,gaussian,0,0.01);subplot(2,3,
14、2),imshow(F);title(加入高斯噪声的图像);%傅里叶变换并把频谱中心移到中点F1=fft2(F);I1=fftshift(F1);%构建理想低通滤波器m,n=size(I1);d1=30;d2=50;d3=70;d4=90;n1=floor(n/2);n2=floor(m/2);for u=1:m for v=1:n if sqrt(u-n1)2+(v-n2)2)=d1 H1(u,v)=1; else H1(u,v)=0; end end endfor u=1:m for v=1:n if sqrt(u-n1)2+(v-n2)2)=d2 H2(u,v)=1; else H2(u
15、,v)=0; end end endfor u=1:m for v=1:n if sqrt(u-n1)2+(v-n2)2)=d3 H3(u,v)=1; else H3(u,v)=0; end end endfor u=1:m for v=1:n if sqrt(u-n1)2+(v-n2)2)=Step*(k-1)&IStep*k); Image(Index)=Projectm(k);endsubplot(2,4,(m-1)*4+4),imshow(Image,); title(变换后的结果图,num2str(m);end%3. 灰度图像常用平常、锐化滤波clear all;close all;
16、%0.原图I=double(imread(lena.tiff);subplot(2,4,1);imshow(I,);title(原图);%1.均值低通滤波H=fspecial(average,5);F1=double(filter2(H,I);subplot(2,4,2);imshow(F1,);title(均值低通滤波);%2.gaussian 低通滤波H=fspecial(gaussian,7,3);F2=double(filter2(H,I);subplot(2,4,3);imshow(F2,);title(高斯低通滤波);%3.增强图像=原图-均值低通滤波F3=2*I-F1;subpl
17、ot(2,4,4);imshow(uint8(F3),);title(原图-均值低通滤波);%4.增强图像=原图-高斯低通滤波F4=2*I-F2;subplot(2,4,5);imshow(uint8(F4),);title(原图-高斯低通滤波);%5.prewitt边缘算子增强H=fspecial(prewitt);F5=uint8(I+filter2(H,I);subplot(2,4,6);imshow(F5,);title(prewitt边缘算子增强);%6.soble边缘算子增强H=fspecial(sobel);F6=uint8(I+filter2(H,I);subplot(2,4,
18、7);imshow(F6,);title(sobel边缘算子增强); %4(1)Butterworth低通滤波器实现图像信号的滤波运算clear all;close all;%(a) 读入并显示图像electric.tif;I=imread(electric.tif);subplot(2,3,1),imshow(I);title(原图像);%(b) 利用imnoise 命令在图像electric.tif 上加入高斯(gaussian) 噪声;J=imnoise(I,gaussian,0,0.01);subplot(2,3,2),imshow(J);title(加入高斯噪声的图像);%(c) 用
19、Butterworth低通滤波器实现图像信号的滤波运算,变换不同的截止频率d:d1=30;d2=50;d3=70;d4=90I1=fftshift(fft2(J);m,n=size(I1);N=2;d1=30;d2=50;d3=70;d4=90;n1=floor(m/2);n2=floor(n/2);for i=1:m for j=1:n d=sqrt(i-n1)2+(j-n2)2); H1=1/(1+(d/d1)(2*N); H2=1/(1+(d/d2)(2*N); H3=1/(1+(d/d3)(2*N); H4=1/(1+(d/d4)(2*N); I3(i,j)=H1*I1(i,j); I5(i,j)=H2*I1(i,j); I7(i,j)=H3*I1(i,j); I9(i,j)=H4*I1(i,j); endendI3=ifftshift(I3);
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1