实验四 图像增强
一、实验目的:掌握图像灰度变换、图像平滑和图像锐化的方法。
二、实验原理:(见课本)
三、实验内容及步骤(注意实验中选用库中灰度图像)
1 采用灰度变换的方法增强图像的对比度
clc
I=imread('pout.tif');
subplot(2,2,1),imshow(I);title('原图象');
subplot(2,2,2),imhist(I);title('原图象直方图');
J=imadjust(I,[0.15 0.9], [0 1]);
subplot(2,2,3),imshow(J);title('灰度变换图象');
subplot(2,2,4),imhist(J);title('变换后直方图');
2 对图象进行均衡化和规定化,观察结果。
I=imread('tire.tif'); % 读取 MATLAB 自带的 tire.tif 图像
subplot(3,2,1),imshow(I),title('原图象')
subplot(3,2,2),imhist(I),title('原图象直方图')
[J,T]=histeq(I,64); % 均衡化图象,图像灰度扩展到 0~255,但是只有 64 个灰度级
subplot(3,2,3),imshow(J),title('均衡化图象');
subplot(3,2,4),imhist(J),title('均衡图象直方图')
hgram=50:2:250;
K=histeq(I,hgram);%规定化函数
subplot(3,2,5),imshow(K),title('规定化后所得图象')
subplot(3,2,6),imhist(K),title('规定化图象直方图')
3 对椒盐噪声图像、高斯噪声图像分别进行均值滤波和中值滤波,并观察结果。
I=imread('eight.tif');
J1=imnoise(I,'salt & pepper',0.02);
J2 =imnoise(I,'gaussian',0,0.02);
K1=filter2(fspecial('average',3),J1)/255; %生成 3×3 邻域平均窗函数并进行均值滤波
K2=filter2(fspecial('average',3),J2)/255;
L1=medfilt2(J1,[3 3]);%中值滤波
L2=medfilt2(J2,[3 3]);
subplot(2,3,1),imshow(J1), title('椒盐噪声图像');
subplot(2,3,2),imshow(K1),title('均值滤波图像');
subplot(2,3,3),imshow(L1),title('中值滤波');
subplot(2,3,4),imshow(J2), title('高斯噪声图像');
subplot(2,3,5),imshow(K2),title('均值滤波图像');
subplot(2,3,6),imshow(L2),title('中值滤波');
4 对图像分别进行 laplacian,prewitt, Roberts, Sobel 算子进行锐化,观察结果。
I=imread('rice.png');
subplot(2,2,1),imshow(I),title('原图像');
K=fspecial('laplacian');%应用 laplacian 算子滤波锐化图像
K1=filter2(K,I)/100;
评论1