Matlab课程设计
题目:
二、利用混合空间法增强锐化图像仿真
将原始图像增强,最终增强为如下类似图像。
可参考如下过程
源程序:
clc
clear all
%读取图像
J=imread('E:\工作台\MATLAB\2016课程设计\仿真2附件
\Fig0343(a)(skeleton_orig).tif');
%拉普拉斯变换得到M1
[m,n]=size(J);
I=im2double(J);
h1=[0,-1,0;-1,4,-1;0,-1,0];
M1=imfilter(I,h1);
%与原图相加得到M2,锐化原图
M2=M1+I;
%sobel算子运算结果得到M3,保留边缘去除噪声
h2=[1,0,-1;2,0,-2;1,0,-1];
h3=[-1,-2,-1;0,0,0;1,2,1];
Sx=imfilter(I,h2);
Sy=imfilter(I,h3);
for i=1:m
for j=1:n
M3(i,j)=sqrt((Sx(i,j))^2+(Sy(i,j))^2);
end
end
%作3*3模板的均值平滑
M4=zeros(m,n);
for x=2:m-1
for y=2:n-1
for a=-1:1
for b=-1:1
M4(x,y)=(M4(x,y)+M3(x+a,y+b))/9;
end
end
end
end
for c=1:m
for d=1:n
M4(c,1)=M3(c,1);
M4(1,d)=M3(1,d);
end
end
%作幂次变换,提升亮度2倍,提升对比度
for e=1:m
for f=1:n
M5(e,f)=M2(e,f)*M4(e,f);
end
end
M6=I+M5;
for g=1:m
for h=1:n
M7(g,h)=2*(M6(g,h))^1.15;
end
end
subplot(241);imshow(I);
subplot(242);imshow(M1);
subplot(243);imshow(M2);
subplot(244);imshow(M3);
subplot(245);imshow(M4);
subplot(246);imshow(M5);
subplot(247);imshow(M6);
subplot(248);imshow(M7);
分析:
1.读取图像
2.利用 Laplacian 变换得到M1,在与原图相处理得到锐化的图像
3.用 Sobel 算子运算,保留边缘去除噪声
4.用3*3的模板均值平滑化图像
5.用幂律定理,提高图像亮度,提高对比度
截图:。