图像增强
灰度变换
可以提高图像对比度,常用matlab函数包括:imadjust、对数变换等
%灰度变换
close all;clear all;clc;
%通过函数stretchlim()和imadjust()进行图像增强
I=imread('Fig1.tif');
M=stretchlim(I); %获取最佳区间
g=imadjust(I,M,[]); %调整灰度范围
figure,
subplot(121);imshow(uint8(I));title('原图');
subplot(122);imshow(uint8(g));title('增强后的图');
直方图均衡化与直方图匹配
可以提高图像对比度,相关matlab函数包括:imhist查看图像直方图、histeq直方图均衡化、直方图匹配。
%直方图均衡化
close all;clear all;clc;
I = imread('Fig2.tif');
J=imread('Fig1.tif');
H= histeq(I,256);%将直方图分为256个等级均衡化
subplot(321);imshow(I);title('原图');
subplot(322);imhist(I);title('原图像直方图分布情况');
subplot(323);imshow(H);title('均衡化后');
subplot(324);imhist(H);title('均衡化后直方图分布情况');
%直方图匹配
[hspec,x]=imhist(J);
P=histeq(I,hspec);%匹配图1
subplot(325);imshow(P);title('匹配后图形');
subplot(326);imhist(P);title('均衡化后直方图分布情况');
空间滤波
可去除噪声,分为线性空间滤波(imfilter函数)、非线性空间滤波(排序统计滤波器ordfilt2、中值滤波器medfilt2)
%空间滤波
close all;clear all;clc;
I = imread('Fig3.tif');
h = fspecial('average',3);%创建一个均值滤波器
K1= imfilter(I,h); %进行空域滤波
K2= medfilt2(I);%中值滤波
K3 = ordfilt2(I, 5, ones(3)); %排序统计滤波相当于窗口3*3的中值滤波
figure;
subplot(221);imshow(I);title('原灰度图');
subplot(222);imshow(K1);title('空域滤波');
subplot(223);imshow(K2);title('中值滤波');
subplot(224);imshow(K3);title('排序统计滤波');