数字图像处理实验一(附源程序)

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

数字图像处理—实验一

一.实验内容:

图像灰度变换

二.实验目的:

学会用Matlab 软件对图像灰度进行变换;感受各种不同的灰度变换方法对最终图像效果的影响。

三.实验步骤:

1.获取实验用图像:rice.jpg. 使用imread 函数将图像读入Matlab 。

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 函数保存处理后的新图像。

3.产生灰度变换函数T2,使得:

s =

用T2对原图像rice.jpg 进行处理,使用imwrite 保存处理后的新图像。 4.分别用 s = r 0.6; s = r 0.4; s = r 0.3 对kids.tiff 图像进行处理。为简便起见,请

使用Matlab 中的imadjust 函数。使用imwrite 保存处理后的新图像。

5.对circuit.jpg 图像实施反变换(Negative Transformation )。s =1-r; 使用

imwrite 保存处理后的新图像。

6.对rice.jpg 图像实施灰度切片(Gray-level slicing )。具体要求如下:

当0.2 ≤ r ≤ 0.4时,将r 置为0.6, 当r 位于其他区间时, 保持其灰度与原图像一样。使用imwrite 保存处理后的新图像。

7.利用灰度变换对Picture.jpg 做增强处理,突出图中的人物,改善整个图像过

于灰暗的背景。通过调节参数,观察变换后的图像与原始图像的变化,寻找出最佳的灰度变换结果。写出所采用的拉伸表达式。(提示:用imhist 观察图像直方图,利用分段线性灰度变换。

)

四.实验报告要求:

用imshow, plot等函数生成各类图像,提交原图像和各种变换函数的曲线,以及按各种变换函数处理后的图像。

%%%%%%%% 班级:0410201

%%%%%%%% 姓名:xx

%%%%%%%% 学号:041010329

clear all;

clc;

close all;

%%%%%%%%处理rice.png

a=imread('rice.png');

figure,imshow(a),title('原图');axis on;

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)); %产生灰度变换函数T1

s2=[r<=0.5].*(r.^5)*15.9744+[r>0.5].*((r-0.5).^0.2+0.12); %产生灰度变换函数T2

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));

a2=[a<=0.5].*(a.^5)*15.9744+[a>0.5].*((a-0.5).^0.2+0.12);

figure,imshow(a1),title('改后一');axis on;

figure,imhist(a1),title('改后直方图一');axis on;

figure,plot(r,s1),title('变换函数一');axis on;

figure,imshow(a2),title('改后二');axis on;

figure,imhist(a2),title('改后直方图二');axis on;

figure,plot(r,s2),title('变换函数二');axis on;

imwrite(a1,'改后rice一.jpg');

imwrite(a2,'改后rice二.jpg'); %%%%%%%%处理kids.tif

b=imread('kids.tif');

figure,imshow(b),title('原图');axis on;

b=double(b)/256;

figure,imhist(b);title('原直方图');axis on;

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('改后一');axis on; figure,imhist(b1),title('改后直方图一');axis on; figure,plot(r,s1),title('变换函数一');axis on; figure,imshow(b2),title('改后二');axis on; figure,imhist(b2),title('改后直方图二');axis on; figure,plot(r,s2),title('变换函数二');axis on; figure,imshow(b3),title('改后三');axis on; figure,imhist(b3),title('改后直方图三');axis on; figure,plot(r,s3),title('变换函数三');axis on; imwrite(b1,'改后kids一.jpg');

imwrite(b2,'改后kids二.jpg');

imwrite(b3,'改后kids三.jpg'); %%%%%%%%处理circuit.tif

c=imread('circuit.tif');

figure,imshow(c),title('原图');axis on;

c=double(c)/256;

figure,imhist(c),title('原直方图');axis on;

s=1-r;

相关文档
最新文档