数字图像处理实验报告

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

数字图像处理实验报告
数字图像处理实验报告
161420230 蔡讴实验一
1.获取实验用图像:rice.jpg. 使用imread函数将图像读入Matlab。

a=imread('D\:rice.png');
figure;
title(‘原图’);
axis on;
imshow(a);
2.产生灰度变换函数T1,使得:
0.3r r < 0.35
s = 0.105 + 2.6333(r –0.35) 0.35 ≤r ≤0.65
1 + 0.3(r – 1) r > 0.65
用T1对原图像rice.jpg进行处理,使用imwrite函数保存处理后的新图像。

a=double(a)/256;
figure,imhist(a),title('原直方图');
axis on;
r=[0:0.001:1];
s1=[r<0.35].*r*0.3+[r<=0.65].*[r>=0.35].*(0.105+2.6333*(r-0.35))+[ r>0.65].*(1+0.3*(r-1));
a1=[a<0.35].*a*0.3+[a<=0.65].*[a>=0.35].*(0.105+2.6333*(a -0.35)) +[a>0.65].*(1+0.3*(a-1));
figure,imshow(a1),title('改后一');
axis on;
figure,imhist(a1),title('改后直方图一');
axis on;
imwrite(a1,'改后rice一.jpg');
3.产生灰度变换函数T2,使得:
s =
用T2对原图像rice.jpg 进行处理,使用imwrite 保存处理后的新
图像。

r2=[0:0.001:1];
t2=[r2<=0.5].*(15.9744*r2.^5)+[r2>0.5].*((r2-
0.5).^0.2+0.12); subplot(2,3,5); plot(r2,t2,'r'); title('更改后直方图');
subplot(2,3,4); imshow(a); title('更改后');
A3=[a<=0.5].*(15.9744*a.^5)+[a>0.5].*((a-0.5).^0.2+0.12); subplot(2,3,6); imshow(A3); title('更改后');
imwrite(A3,'更改_3.jpg','jpg');
15.9744r 5 r ≤ 0.5 (r – 0.5)0.2+ 0.12 r > 0.5
4.分别用s = r0.6; s = r0.4; s = r0.3对kids.tiff图像进行处理。

为简便起见,请使用Matlab中的imadjust函数。

使用imwrite保存处理后的新图像。

subplot(2,3,1);
k=imread('Fig3.08(a).jpg');
imshow(k);title('Fig3.08(a)
subplot(2,3,2);
ss1=r.^0.6;
ss2=r.^0.4;
ss3=r.^0.2;
plot(r,ss1,r,ss2,r,ss3);title('4p,');
subplot(2,3,3);
s1=imadjust(k,[],[],0.6);
imshow(s1);title('41i,');
subplot(2,3,4);
s2=imadjust(k,[],[],0.4);
imshow(s2);title('42i,');
subplot(2,3,5);
s3=imadjust(k,[],[],0.3);
imshow(s3);title('43i,');
5.对circuit.jpg图像实施反变换(Negative Transformation)。

s =1-r; 使用imwrite保存处理后的新图像。

s =1-r;
r=imread('Fig3.04(a).jpg');
r=im2double(r);
imshow(r);title('5i,');
s=1-r;
imwrite(s,'Fig3.10(a)_ss.jpg','jpg');
6.对rice.jpg图像实施灰度切片(Gray-level slicing)。

具体要求如下:当0.2 ≤r ≤0.4时,将r置为0.6, 当r位于其他区间时, 保持其灰度与原图像一样。

使用imwrite保存处理后的新图像。

subplot(2,1,1);
r=[0:0.001:1];
s=[r<=0.4].*[r>=0.2]*0.6;
plot(r,s);title('6p,');
subplot(2,1, 2);
s6=[i<=0.4].*[i>=0.2]*0.6+[i>0.4].*i+[i<0.2].*i;
imshow(s6);title('6i,');
imwrite(s6,'Fig3.10(b)_s6.jpg','jpg');
实验二
1.仔细阅读Matlab帮助文件中有关以上函数的使用说明,能充分理解其使用方法并能运用它们完成实验内容。

2.将mountain.jpg图像文件读入Matlab,对其作直方图均衡化。

显示运算前后该图像的直方图,处理后的图像和灰度变换函数。

figure;
subplot(2,2,1);
i1=imread('D:\images\mountain.jpg');
i1=im2double(i1);
imshow(i1);title('Input Image');
subplot(2,2,2);
imhist(i1);
subplot(2,2,3);
T1=histeq(i1);
imshow(T1);title('Out Image');
imwrite(T1,'adjusted.jpg','jpg');
subplot(2,2,4);
imhist(T1);
3.对mountain.jpg 图像做直方图匹配运算,显示运算前后该图像的直方图,处理后的图像和灰度变换函数。

直方图反映灰度等级的
分布情况,本实验指定的直方图如下:
1400×r
r ≤5 7000-310×r
5<r ≤20 900-5×r
20<r ≤180 -1440+8×r 180<r ≤225 3060-12×r 225<r ≤255
subplot(2,3,3); r=[0:1:255];
n=[r<=5].*(r.*1400)+[r>5].*[r<=20].*(7000-310.*r)+[r>20].*[r<=180
n =
].*(900-5.*r)+[r>180].*[r<=225].*(8.*r-
1440)+[r>225].*[r<=255].*(3 060-12.*r);
plot(r,n);title('r-n');
subplot(2,3,4);
T1=histeq(i1,n);
imshow(T1);title('Out Image');
imwrite(T1,'adjusted.jpg','jpg');
subplot(2,3,5);
imhist(T1);
4.利用mountain.jpg图像的直方图(imhist函数可生成),编写直方图均衡化函数。

%1
figure;
subplot(2,3,1);
i1=imread('D:\images\mountain.jpg');
i1=im2double(i1);
imshow(i1);title('Input Image');
subplot(2,3,2);
imhist(i1);title('原直方图')
subplot(2,3,3);
T1=histeq(i1);
imshow(T1);
%2
subplot(2,3,4);
r=[0:5:255];
n=[r<=5].*(r.*50+550)+[r>5].*[r<=20].*(r.*4+600)+[r>20].*[r <=180 ].*(1000-0.8.*r)+[r>180].*[r<=225].*(5.*r-200)+[r>225].*[r<=255].* (200+2.*r);;
plot(r,n);title('r-n');
subplot(2,3,5);
T2=histeq(i1,n);
imshow(T2);
imwrite(T2,'adjusted.jpg','jpg');
subplot(2,3,6);
imhist(T1);title('均衡化后直方图')
实验三
1.仔细阅读Matlab帮助文件中有关以上函数的使用说明,能充分理解其使用方法并能运用它们完成实验内容。

2.将test3_1.jpg图像文件读入Matlab,用nlfilter对其进行5?5邻域平均和计算邻域标准差。

显示邻域平均处理后的结果,以及邻域标准差图像。

源程序:
figure;
subplot(1,3,1);
i1=imread('D:\images\test3_1.jpg');
i1=im2double(i1);
imshow(i1);title('Input Image');
subplot(1,3,2);
T1=imnoise(i1,'gaussian',0,0.2)
imshow(T1);title('
加高斯噪声
');
subplot(1,3,3);
T2=nlfilter(i1,[5 5],@mean2);
imshow(T2);title('
处理后结果
');
3.在test3_1.jpg图像中添加均值为0,方差为0.02的高斯噪声,对噪声污染后的图像用nlfilter进行5?5邻域平均。

显示处理后的结果。

(使用imnoise命令)
源程序:
figure;
subplot(1,3,1);
i1=imread('D:\images\test3_1.jpg');
i1=im2double(i1);
imshow(i1);title('Input Image');
subplot(1,3,2);
T1=imnoise(i1,'gaussian',0,0.2)
imshow(T1);title('加高斯噪声');
subplot(1,3,3);
T2=nlfilter(i1,[5 5],@mean2);
imshow(T2);title('处理后结果');
4.将test3_2.jpg图像文件读入Matlab,用fspecial函数生成一5 5邻域平均窗函数,再用filter2函数求邻域平均,试比较与用nlfilter 函数求邻域平均的速度。

源程序:
figure;
subplot(1,2,1);
i1=imread('D:\images\test3_2.jpg');
i1=im2double(i1);
imshow(i1);title('Input Image');
T1=fspecial('average',[5 5]);
subplot(1,2,2);
T2=filter2(T1,i1);
imshow(T2);title('处理后结果');
5.用medfilt2函数对test3_2.jpg图像进行中值滤波。

显示处理结果。

源程序:
figure;
subplot(1,2,1);
i1=imread('D:\images\test3_2.jpg');
i1=im2double(i1);
imshow(i1);title('Input Image');
subplot(1,2,2);
T1=medfilt2(i1);
imshow(T1);title('处理后结果');
6.编写中值滤波程序(函数)。

对test3_2.jpg图像进行中值滤波。

显示处理结果。

源程序:
figure;
subplot(1,3,1);
i1=imread('D:/images/test3_2.jpg'); imshow(i1);title('Input Image');
i2=double(i1);
subplot(1,3,2);
[h,w]=size(i1);
a(1:25)=0;
T1=i2;
for i=3:h-2;
for j=3:w-2;
for ii=-2:2;
for jj=-2:2;
a((ii+2)+5*(jj+2)+1)=i2(i+ii,j+jj); end;
end;
a=sort(a);
T1(i,j)=a(13);
end;
end;
T2=uint8(T1);
imshow(T2);title('编程中值滤波'); subplot(1,3,3);
T3=medfilt2(i1);
imshow(T3);title('自带中值滤波(比较)');。

相关文档
最新文档