实验二图像直方图分析_第1页
实验二图像直方图分析_第2页
实验二图像直方图分析_第3页
实验二图像直方图分析_第4页
实验二图像直方图分析_第5页
已阅读5页,还剩5页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、姓名:马晓正 学号:201215502实验二 图像直方图分析一实验目的及要求1了解MATLAB的操作环境和基本功能。2掌握MATLAB中图像增强与平滑的函数的使用方法。3加深理解图像增强与平滑的算法原理。二、实验内容(一)研究以下程序,分析程序功能;输入执行各命令行,认真观察命令执行的结果。熟悉程序中所使用函数的调用方法,改变有关参数,观察试验结果。(可将每段程序保存为一个.m文件)1直方图均衡化clear all; close all % Clear the MATLAB workspace of any variables % and close open figure windows.I

2、 = imread(pout.tif); % Reads the sample images pout.tif, and stores it in imshow(I) % an array named I.display the imagefigure, imhist(I) % Create a histogram of the image and display it in % a new figure window.I2,T = histeq(I); % Histogram equalization.figure, imshow(I2) % Display the new equalize

3、d image, I2, in a new figure window.figure, imhist(I2) % Create a histogram of the equalized image I2.figure,plot(0:255)/255,T); % plot the transformation curve.imwrite (I2, pout2.png); % Write the newly adjusted image I2 to a disk file named% pout2.png.imfinfo(pout2.png) % Check the contents of the

4、 newly written file注意:imadjust()功能:调整图像灰度值或颜色映像表,也可实现伽马校正。语法:J = imadjust(I,low_in high_in,low_out high_out,gamma)newmap = imadjust(map,low_in high_in,low_out high_out,gamma)RGB2 = imadjust(RGB1,.)2直接灰度变换clear all; close allI = imread(cameraman.tif);J = imadjust(I,0 0.2,0.5 1);imshow(I)figure, imsho

5、w(J)X,map = imread(forest.tif);figure,imshow(X,map)I2 = ind2gray(X,map);J2 = imadjust(I2,0.5); figure,imshow(I2)figure, imshow(J2)J3 = imadjust(I2,1.5); figure, imshow(J3)help imadjust % Display the imadjust() function information.3空域平滑滤波(模糊、去噪)clear all; close allI = imread(eight.tif);h1 = ones(3,3

6、) / 9;h2 = ones(5,5) / 25;I1 = imfilter(I,h1);I2 = imfilter(I,h2);figure(1), imshow(I), title(Original Image);figure(2), imshow(I1), title(Filtered Image With 3*3 )figure(3), imshow(I2), title(Filtered Image With 5*5 )% 加入Gaussian 噪声J1 = imnoise(I,gaussian,0,0.005);% 加入椒盐噪声J2 = imnoise(I,salt & pepp

7、er,0.02);% 对J1、J2进行平均值平滑滤波K1 = imfilter(J1,fspecial(average,3);K2 = imfilter(J2,fspecial(average,3);figure(4);subplot(2,2,1), imshow(J1) , title(gaussian);subplot(2,2,2), imshow(J2), title(salt & pepper );subplot(2,2,3), imshow(K1), title(average );subplot(2,2,4), imshow(K2);% 对J1、J2进行中值滤波K3 = medfi

8、lt2(J1,3 3);K4 = medfilt2(J2,3 3);figure(5);subplot(2,2,1), imshow(J1) , title(gaussian);subplot(2,2,2), imshow(J2), title(salt & pepper );subplot(2,2,3), imshow(K3), title( Median filtering );subplot(2,2,4), imshow(K4)4空域锐化滤波clear all; close allI = imread(moon.tif);w=fspecial(laplacian,0)w8=1,1,1;1

9、,-8,1;1,1,1I1= imfilter(I,w, replicate);figure(1); imshow(I), title(Original Image);figure(2), imshow(I1), title(Laplacian Image);f = im2double(I);f1= imfilter(f,w, replicate);figure(3), imshow(f1,), title(Laplacian Image);f2= imfilter(f,w8, replicate);f4 = f-f1;f8 = f-f2;figure(4), imshow(f4);figur

10、e(5), imshow(f8);(二)采用MATLAB底层函数编程实现1灰度变换之动态范围扩展假定原图像f(x, y)的灰度范围为a, b,希望变换后图像 g(x, y)的灰度范围扩展至c, d,则线性变换可表示为: 用MATLAB底层函数编程实现上述变换函数。观察图像 pout.tif的灰度直方图,选择合适的参数a, b、c, d对图像pout.tif进行灰度变换,以获得满意的视觉效果。2非锐化掩蔽和高斯滤波从原图像中减去其非锐化(平滑过的)图像的过程称为非锐化掩蔽,其基本步骤为:对原图像进行平滑滤波得到模糊图像;从原图像中减去模糊图像,产生的差值图像称为模板;将模板加到原图像上,得到锐化

11、后的图像。 即,用MATLAB函数编程实现上述功能。三、实验设备1计算机;2MATLAB6.5及以上;四、预习与思考1预习实验内容,阅读教材熟悉实验原理;2查阅资料,熟悉MATLAB的操作环境和基本功能。熟悉实验中涉及的有关函数。3利用课余时间,用MATLAB底层函数编程实现实验内容(二)中的灰度线性变换。4你能否给出实现样例程序功能的其它方法?五、实验报告要求1. 简述试验的目的和试验原理;2. 叙述各段程序功能,改变有关函数的参数,分析比较实验结果;3. 打印出所编写的实验程序。4. 写出本实验的心得体会及意见。1直方图均衡化I = imread(pout.tif); imshow(I)

12、figure, imhist(I) I2,T = histeq(I); figure, imshow(I2) figure, imhist(I2) figure,plot(0:255)/255,T); imwrite (I2, pout2.png); imfinfo(pout2.png) 注意:imadjust()功能:调整图像灰度值或颜色映像表,也可实现伽马校正。语法:J = imadjust(I,low_in high_in,low_out high_out,gamma)newmap = imadjust(map,low_in high_in,low_out high_out,gamma)

13、RGB2 = imadjust(RGB1,.)2直接灰度变换clear all; close allI = imread(cameraman.tif);J = imadjust(I,0 0.2,0.5 1);imshow(I)figure, imshow(J)X,map = imread(forest.tif);figure,imshow(X,map)I2 = ind2gray(X,map);J2 = imadjust(I2,0.5); figure,imshow(I2)figure, imshow(J2)J3 = imadjust(I2,1.5); figure, imshow(J3)hel

14、p imadjust 3空域平滑滤波(模糊、去噪)clear all; close allI = imread(eight.tif);h1 = ones(3,3) / 9;h2 = ones(5,5) / 25;I1 = imfilter(I,h1);I2 = imfilter(I,h2);figure(1), imshow(I), title(Original Image);figure(2), imshow(I1), title(Filtered Image With 3*3 )figure(3), imshow(I2), title(Filtered Image With 5*5 )%

15、加入Gaussian 噪声J1 = imnoise(I,gaussian,0,0.005);% 加入椒盐噪声J2 = imnoise(I,salt & pepper,0.02);% 对J1、J2进行平均值平滑滤波K1 = imfilter(J1,fspecial(average,3);K2 = imfilter(J2,fspecial(average,3);figure(4);subplot(2,2,1), imshow(J1) , title(gaussian);subplot(2,2,2), imshow(J2), title(salt & pepper );subplot(2,2,3),

16、 imshow(K1), title(average );subplot(2,2,4), imshow(K2);% 对J1、J2进行中值滤波K3 = medfilt2(J1,3 3);K4 = medfilt2(J2,3 3);figure(5);subplot(2,2,1), imshow(J1) , title(gaussian);subplot(2,2,2), imshow(J2), title(salt & pepper );subplot(2,2,3), imshow(K3), title( Median filtering );subplot(2,2,4), imshow(K4) 4空域锐化滤波clear all; close allI = imread(moon.tif);w=fspecial(laplacian,0)w8=1,1,1;1,-8,1;1,1,1I1= imfilter(I,w, replicate);figure(1); imshow(I), title(Original Image);figure(2), imshow(I1), title(Laplacian Image);f = im2double(I);f1= imfilter(f,w, repli

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

最新文档

评论

0/150

提交评论