一.实验目的及要求
1、熟悉并掌握 MATLAB 图像处理工具箱的使用;
2、理解并掌握常用的图像的增强技术。
二、实验设备
MATLAB 6.5 以上版本、WIN XP 或 WIN2000 计算机
三、实验内容
(一)研究以下程序,分析程序功能;输入执行各命令行,认真观察命令执行的结果。熟悉程序中所使用函数的调用方法,改变有关参数,观察试验结果。(可将每段程序保存为一个.m文件)
1.直方图均衡化
clear all; close all % Clear the MATLAB workspace of any variables
% and close open figure windows.
I = imread('pout.tif'); % Reads the sample images ‘ pout.tif’, and stores it in
imshow(I) % an array named I.display the image
text(60,20,'李荣桉 1909290239','horiz','center','color','r')
figure, 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 equalized image, I2, in a new figure window.
text(60,20,'李荣桉 1909290239','horiz','center','color','r')
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 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 all
I = imread('cameraman.tif');
J = imadjust(I,[0 0.2],[0.5 1]);
椒盐噪声imshow(I)
text(60,20,'李荣桉 1909290239','horiz','center','color','r')
figure, imshow(J)
text(60,20,'李荣桉 1909290239','horiz','center','color','r')
[X,map] = imread('forest.tif');
figure,imshow(X,map)
text(60,20,'李荣桉 1909290239','horiz','center','color','r')
I2 = ind2gray(X,map);
J2 = imadjust(I2,[],[],0.5);
figure,imshow(I2)
text(60,20,'李荣桉 1909290239','horiz','center','color','r')
figure, imshow(J2)
text(60,20,'李荣桉 1909290239','horiz','center','color','r')
J3 = imadjust(I2,[],[],1.5);
figure, imshow(J3)
text(60,20,'李荣桉 1909290239','horiz','center','color','r')
help imadjust
.
clear all; close all
I = 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');
text(60,20,'李荣桉 1909290239','horiz','center','color','r')
figure(2), imshow(I1), title('Filtered Image With 3*3 ')
text(60,20,'李荣桉 1909290239','horiz','center','color','r')
figure(3), imshow(I2), title('Filtered Image With 5*5 ')
text(60,20,'李荣桉 1909290239','horiz','center','color','r')
% 加入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');
text(60,20,'李荣桉 1909290239','horiz','center','color','r')
subplot(2,2,2), imshow(J2), title('salt & pepper ');
text(60,20,'李荣桉 1909290239','horiz','center','color','r')
subplot(2,2,3), imshow(K1), title('average ');
text(60,20,'李荣桉 1909290239','horiz','center','color','r')
subplot(2,2,4), imshow(K2);
text(60,20,'李荣桉 1909290239','horiz','center','color','r')
K3 = medfilt2(J1,[3 3]);
K4 = medfilt2(J2,[3 3]);
figure(5);
subplot(2,2,1), imshow(J1) , title('gaussian');
text(60,20,'李荣桉 1909290239','horiz','center','color','r')
subplot(2,2,2), imshow(J2), title('salt & pepper ');
text(60,20,'李荣桉 1909290239','horiz','center','color','r')
subplot(2,2,3), imshow(K3), title(' Median filtering ');
text(60,20,'李荣桉 1909290239','horiz','center','color','r')
subplot(2,2,4), imshow(K4)
text(60,20,'李荣桉 1909290239','horiz','center','color','r')
4.空域锐化滤波
clear all; close all
I = imread('moon.tif');
w=fspecial('laplacian',0)
w8=[1,1,1;1,-8,1;1,1,1]
I1= imfilter(I,w, 'replicate');
figure(1); imshow(I), title('Original Image');
text(60,20,'李荣桉 1909290239','horiz','center','color','r')
figure(2), imshow(I1), title('Laplacian Image');
text(60,20,'李荣桉 1909290239','horiz','center','color','r')