数字图像处理实验作业及代码

整理文档很辛苦,赏杯茶钱您下走!

免费阅读已结束,点击下载阅读编辑剩下 ...

阅读已结束,您可以下载文档离线阅读编辑

资源描述

数字图像处理—实验一源程序:a=imread('rice.png');figure,imshow(a),title('原图');axison;a=double(a)/256;figure,imhist(a),title('原直方图');axison;r=[0:0.001:1];s1=[r0.35].*r*0.3+[r=0.65].*[r=0.35].*(0.105+2.6333*(r-0.35))+[r0.65].*(1+0.3*(r-1));s2=[r=0.5].*(r.^5)*15.9744+[r0.5].*((r-0.5).^0.2+0.12);a1=[a0.35].*a*0.3+[a=0.65].*[a=0.35].*(0.105+2.6333*(a-0.35))+[a0.65].*(1+0.3*(a-1));a2=[a=0.5].*(a.^5)*15.9744+[a0.5].*((a-0.5).^0.2+0.12);figure,imshow(a1),title('改后一');axison;figure,imhist(a1),title('改后直方图一');axison;figure,plot(r,s1),title('变换函数一');axison;figure,imshow(a2),title('改后二');axison;figure,imhist(a2),title('改后直方图二');axison;figure,plot(r,s2),title('变换函数二');axison;imwrite(a1,'改后rice一.jpg');imwrite(a2,'改后rice二.jpg');b=imread('kids.tif');figure,imshow(b),title('原图');axison;b=double(b)/256;figure,imhist(b);title('原直方图');axison;s1=r.^0.6;s2=r.^0.4;s3=r.^0.3;b1=imadjust(b,[],[],0.6);b2=imadjust(b,[],[],0.4);b3=imadjust(b,[],[],0.3);figure,imshow(b1),title('改后一');axison;figure,imhist(b1),title('改后直方图一');axison;figure,plot(r,s1),title('变换函数一');axison;figure,imshow(b2),title('改后二');axison;figure,imhist(b2),title('改后直方图二');axison;figure,plot(r,s2),title('变换函数二');axison;figure,imshow(b3),title('改后三');axison;figure,imhist(b3),title('改后直方图三');axison;figure,plot(r,s3),title('变换函数三');axison;imwrite(b1,'改后kids一.jpg');imwrite(b2,'改后kids二.jpg');imwrite(b3,'改后kids三.jpg');c=imread('circuit.tif');figure,imshow(c),title('原图');axison;c=double(c)/256;figure,imhist(c),title('原直方图');axison;s=1-r;c=1-c;figure,imshow(c),title('变换后');axison;figure,imhist(c),title('变换后直方图');axison;figure,plot(r,s),title('变换函数');axison;imwrite(c,'改后circuit.jpg');d=imread('rice.png');figure,imshow(d),title('原图');axison;d=double(d)/256;figure,imhist(d),title('原直方图');axison;r=[0:0.001:1];s=[r=0.4].*[r=0.2]*0.6;d=[d=0.4].*[d=0.2]*0.6+[d0.4].*d+[d0.2].*d;figure,imshow(d),title('变换后');axison;figure,imhist(d),title('变换后直方图');axison;figure,plot(r,s),title('变换函数');axison;imwrite(d,'第二次改后rice.jpg');e=imread('Picture.jpg');e=e(:,:,1);e=im2double(e);figure,imshow(e),title('原图');axison;figure,imhist(e),title('原直方图');axison;r=[0:0.001:1];s=[r0.3].*r*1.1+[r0.65].*r*0.8+[r=0.3].*[r=0.65].*(0.11+r*1.5);e=[e0.3].*e*1.1+[e0.65].*e*0.8+[e=0.3].*[e=0.65].*(0.11+e*1.5);figure,imshow(e),title('变换后');axison;figure,imhist(e),title('变换后直方图');axison;figure,plot(r,s),title('变换函数');axison;imwrite(e,'改后Picture.jpg');处理前后图像:结论:不同的灰度变换对最终图像的影响效果是不同的。通过matlab灰度变化可以增加图像亮度,提高对比度,使视觉效果更好。数字图像处理—实验二源代码:I1=imread('mountain.jpg');[J1,T1]=histeq(I1,256);figure,subplot(2,3,1),imshow(I1),title('原图');axison;subplot(2,3,2),imhist(I1),title('原图直方图');axison;subplot(2,3,4),imshow(J1),title('均衡化后图像');axison;subplot(2,3,5),imhist(J1),title('均衡化后直方图');axison;subplot(2,3,6),plot(T1),title('变换函数');axison;I2=uint8(I1);r=0:1:255;n=([r=5].*r*1400+[r5].*[r=20].*(7000-r*310)+[r20].*[r=180].*(900-r*5)...+[r180].*[r=225].*(r*8-1440)+[r225].*[r=255].*(3060-r.*12));[J2,T2]=histeq(I2,n);figure,subplot(2,3,1),imshow(I2),title('原图');axison;subplot(2,3,2),imhist(I2),title('原图直方图');axison;subplot(2,3,4),imshow(J2),title('规定化后图像');axison;subplot(2,3,5),imhist(J2),title('规定化后直方图');axison;subplot(2,3,6),plot(T2),title('变换函数');axison;I3=im2double(I1);[mn]=size(I3);r1=zeros(1,256);p=r1;s1=r1;s2=r1;a=0;fork=1:256fori=1:mforj=1:nif(I3(i,j)==((k-1)/255));r1(k)=r1(k)+1;endendendp(k)=r1(k)/65536;s1(k)=a+p(k);a=s1(k);s2(k)=round(s1(k)/(1/255))/255;end[mn]=size(I3);t=0;fork=1:256t=t+1;if(k==256||s2(k)~=s2(k+1))fori=1:mforj=1:nif(I3(i,j)=(k-t)/255&&I3(i,j)=(k-1)/255)I4(i,j)=s2(k);endendendt=0;endendI3=mat2gray(I3);I4=mat2gray(I4);figure,subplot(2,3,1),imshow(I3),title('原图');axison;subplot(2,3,2),imhist(I3),title('原图直方图');axison;subplot(2,3,4),imshow(I4);title('自编函数均衡化');axison;subplot(2,3,5);imhist(I4);title('自编函数均衡化后直方图');axison;subplot(2,3,6),plot(s1),title('变换函数');axison;处理前后图像:结论:直方图均衡化通过使用累积函数对灰度值进行“调整”以实现对比度的增强,通常用来增加许多图像的局部对比度,尤其是当图像的有用数据的对比度相当接近的时候。通过这种方法,亮度可以更好地在直方图上分布。这样就可以用于增强局部的对比度而不影响整体的对比度。数字图像处理—实验三源代码:closeall;I=imread('test3_1.jpg');I=im2double(I);ticJ=nlfilter(I,[55],@mean2);tocticT=nlfilter(I,[55],@std2);tocfigure(1),subplot(2,3,1),imshow(I),title('原始图像');axison;subplot(2,3,2),imshow(J),title('邻域均值图像');axison;subplot(2,3,3),imshow(T),title('邻域均值标准差图像');axison;imwrite(J,'nlfilterl滤波后.jpg');I=imnoise(I,'gaussian',0,0.02);J=nlfilter(I,[55],@mean2);T=nlfilter(I,[55],@std2);subplot(2,3,4),imshow(I),title('加噪图像');axison;subplot(2,3,5),imshow(J),title('加噪邻域均值图像');axison;subplot(2,3,6),imshow(T),title('加噪邻域均值标准差图像');axison;imwrite(J,'加噪nlfilterl滤波后.jpg');I2=imread('test3_2.jpg');J2=im2double(I2);ticave=fspecial('average',5);J2=filter2(ave,J2);tocJ3=medfilt2(J2,[55]);ticJ4=nlfilter(J2,[55],@mean2);tocfigure(2),subplot(2,2,1),imshow(I2),title('原始图像');axison;subplot(2,2,2),imshow(J2),title('filter2处理后图像');axison;subplot(2,2,3),imshow(J3),title('medfilt2处理后图像');axison;subplot(2,2,4),imshow(J4),title('nlfilter处理后图像');axison;imwrite(J2,'filter2滤波后.jpg');imwrite(J3,'medfilt2滤波后.jpg');imwrite(J4,'nlfilter滤波

1 / 21
下载文档,编辑使用

©2015-2020 m.777doc.com 三七文档.

备案号:鲁ICP备2024069028号-1 客服联系 QQ:2149211541

×
保存成功