直方图均衡化和直方图规定化-实验报告

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

一、实验目的

掌握直方图均衡化和直方图规定化的图像增强方法

掌握图像平滑滤波和锐化滤波的模板计算方法

二、实验内容:

1. 使用IPT中imhist,histeq函数进行直方图的均衡化和规定化,并显示结果

2. 编写myhisteq函数实现直方图均衡化,与1中结果进行对比

3. 给读取的图像叠加椒盐噪音(imnoise),分别使用均值滤波和中值滤波进行去噪,并对比图像处理的结果(使用IPT函数)

4. 自定义3*3模板矩阵F,编写myfilter函数实现模板和图像的卷积运算,设计模板矩阵,实现图像的平滑和锐化。

三、实验代码及结果

(1) 直方图的均衡化和规定化

clc;

clear;

I= imread('H:\image\jpg\flower.jpg');

I= rgb2gray(I) ; %将图像转换为灰度图像

J= histeq( I) ; %对I 进行直方图均衡化

figure,subplot( 2,2,1) ,imshow(I) ,title('原始图像') ;

subplot (2,2,2), imshow(J), title('直方图均衡化后的图像');

subplot( 2,2,3) ,imhist(I, 64), title( '原始的直方图');

subplot( 2,2,4) ,imhist(J,64) ,title(' 均衡化后的直方图');

clc;

clear;

I= imread('H:\image\jpg\flower.jpg');

I= rgb2gray(I) ; %将图像转换为灰度图像

h=0:255;h=1-h/255;

J= histeq( I,h) ;

figure,subplot( 2,3,1) ,imshow(I) ,title('原图像') ; subplot( 2,3,2) ,imhist(I, 64), title( '原图像的直方图'); subplot (2,3,3), stem(h), title('目标直方图');

subplot( 2,3,4) ,imshow(I, 64), title( '规定化后的图像'); subplot( 2,3,5) ,imhist(J,64) ,title(' 规定化后的直方图');

二、myhisteq函数实现直方图均衡化

I = imread('j:\image\jpg\flower.jpg');

I = rgb2gray(I);

[height,width] = size(I);

figure

subplot(2,2,1)

imshow(I)%显示原始图像

title('原图像');

subplot(2,2,2)

imhist(I)%显示原始图像直方图

title('原图像直方图');

%进行像素灰度统计;

s = zeros(1,256);%统计各灰度数目,共256个灰度级

for i = 1:height

for j = 1: width

s(I(i,j) + 1) = s(I(i,j) + 1) + 1;%对应灰度值像素点数量增加一end

end

%计算灰度分布密度

p = zeros(1,256);

for i = 1:256

p(i) = s(i) / (height * width * 1.0);

end

%计算累计直方图分布

c = zeros(1,256);

c(1) = p(1);

for i = 2:256

c(i) = c(i - 1) + p(i);

end

%累计分布取整,将其数值归一化为1~256

c = uint8(255 .* c + 0.5);

%对图像进行均衡化

for i = 1:height

for j = 1: width

I(i,j) = c(I(i,j)+1);

end

end

subplot(2,2,3)

imshow(I)%显示均衡化后的图像

title('均衡化后图像');

subplot(2,2,4)

imhist(I)%显显示均衡化后的图像的直方图

title('均衡化后图像的直方图');

三、使用均值滤波和中值滤波进行去噪

I= imread('j:\image\jpg\flower.jpg');

I= rgb2gray(I) ; %将图像转换为灰度图像

I1 = imnoise(I,'salt & pepper',0.02);%0.02是噪声强度,其值越大噪声越多

h=fspecial('average',5);

J1=filter2(h,I1,'valid');

J2= imfilter(I1,h,'full');

figure,subplot(3,3,1),imshow(I1);title('原始椒盐噪声图像图1');

subplot(3,3,2),imshow(uint8(J1));title('filter2均值滤波图2');

subplot(3,3,3),imshow(J2);title('imfilter均值滤波图3');

J3 = medfilt2(I1,[5,5]);

subplot(3,3,4),imshow(J3),title('中值滤波效果图4');

G1= histeq(I1);subplot(3,3,5),imhist(G1,64),title('原图均衡化后的直方图');

G2= histeq(J1);subplot(3,3,6),imhist(uint8(G2),64),title('图2均衡化后直方图'); G3= histeq(J2);subplot(3,3,7),imhist(G3,64),title('图3均衡化后直方图');

G4= histeq(J3);subplot(3,3,8),imhist(G4,64),title('图4均衡化后直方图');

相关文档
最新文档