研究了基于灰度图像的边缘检测问题,针对传统边缘检测方法对噪声极为敏感的问题,提出了基于灰度图像的积累加权边缘检测方法。该方法采用了积累加权的办法,不仅有效滤除了随机噪声,而且图像细节也得到了很好的保留。理论分析和仿真试验结果表明,该方法抗噪性好,各向同性,实时性好,边缘保持性好。较之传统的模板法,该方法的边缘检测效果更好。
在图像分割中,边缘检测方法是人们研究得最多的方法,它试图通过检测包含不同区域的边缘来解决图像分割问题。图像的大部分主要信息都存在于图像的边缘中,主要表现为图像局部特征的不连续性,是图像中灰度变化比较剧烈的地方,亦即通常所说的信号发生奇异变化的地方。奇异信号沿边缘走向的灰度变化剧烈,通常将边缘划分为阶跃状和屋顶状两种类型。阶跃边缘中边缘两边的灰度值有明显的变化;而屋顶状边缘中边缘位于灰度增加与减少的交界处。在数学上可利用灰度的导数来刻画边缘点的变化,对阶跃边缘、屋顶状边缘分别求其一阶、二阶导数。可见,对阶跃边缘点其灰度变化曲线的一阶导数在边缘点达到极大值,二阶导数在边缘点与零交叉。对屋顶状边缘点,其灰度变化曲线的一阶导数在边缘点与零交叉,二阶导数在边缘点达到极值。经典的边缘检测方法,是对原始图像中像素的某小邻域构造边缘检测算子。首先通过平滑来滤除图像中的噪声,然后进行一阶微分或二阶微分运算,求得梯度最大值或二阶导数的过零点,最后选取适当的阈值来检测边界。由于各种原因,图像常常受到随机噪声的干扰。经典的边缘检测方法由于引入了各种形式的微分运算,从而必然引起对噪声的极度敏感,再加上性[1]。针对传统边缘检测方法抗噪性小的问题,本文提出了积累加权边缘检测方法。该方法既有良好的噪声抑制能力,同时又能有效保持图像的边缘特性。介绍了经典的边缘检测方法,提出了积累加权边缘检测法及其实现步骤,对积累加权边缘检测法进行了仿真,并与传统的Laplace和Sobel方法进行了比较,最后对积累加权边缘检测法的优点进行了讨论。执行边缘检测的结果常常是把噪声当做边缘检测出来,而真正的边缘也由于受到噪声干扰而没有被检测出来。因而对于有噪图像来说,一种好的边缘检测方法应具有良好的噪声抑制能力,同时又有完备的边缘保持特
function [img_LH_recomp,img_HL_recomp]=img_LH_and_HL_recomp(LH,HL,it,lphaar2,hphaar2)
for j=1:it
approx = zeros(size(HL{j},1),size(HL{j},2));
for i = j:-1:1
[m,n] = size(HL{i});
if(i==j)
approx = [approx,zeros(m,n);HL{i},zeros(m,n)];
else
approx = [approx,zeros(m,n);zeros(m,n),zeros(m,n)];
end
end
img_HL_recomp{j} = img_recomp(approx,j,lphaar2,hphaar2);
end
for j=1:it
approx = zeros(size(LH{j},1),size(LH{j},2));
for i = j:-1:1
[m,n] = size(LH{i});
if(i==j)
approx = [approx,LH{i};zeros(m,n),zeros(m,n)];
else
approx = [approx,zeros(m,n);zeros(m,n),zeros(m,n)];
end
end
img_LH_recomp{j} = img_recomp(approx,j,lphaar2,hphaar2);
end
end
%Cumulative weighted edge detection
lpdb2 =[ -0.12940952255092145 0.22414386804185735 0.83651630373746899 0.48296291314469025 ]
hpdb2= [-0.48296291314469025 0.83651630373746899 -0.22414386804185735 -0.12940952255092145 ]
lpdb22=[0.48296291314469025 0.83651630373746899 0.22414386804185735 -0.12940952255092145 ]
hpdb22 =[-0.12940952255092145 -0.22414386804185735 0.83651630373746899 -0.48296291314469025 ]
x = imread('lena.jpg');
I = im2double(x);
it = 3;
it2= 2;
LH=img_lh(I,it,lpdb2,hpdb2);
HL=img_hl(I,it,lpdb2,hpdb2);
[LH_recomp,HL_recomp]=img_LH_and_HL_recomp(LH,HL,it,lpdb22,hpdb22)
for i=1:it
LH_recomp_decomposed{i}=rec_decomp(LH_recomp{i},it2,lpdb2,hpdb2);
HL_recomp_decomposed{i}=rec_decomp(HL_recomp{i},it2,lpdb2,hpdb2);
end
for i=1:it
fused{i}=img_fusion(LH_recomp{i},HL_recomp{i},lpdb2,hpdb2,lpdb22,hpdb22,it2);
figure
imshow(fused{i},[]);
end
%The scale multiplication is implemented using the corelation of two adjacent dwt scales
%in this case, the correlation is computed using the two adjacent levels , 2 and 3
scale2= (4*fused{2}+2*fused{3})/4.4721;
%in this case, the correlation is computed using the two adjacent levels , 1 and 2
scale1= (8*fused{1}+4*fused{2})/8.944;
figure
subplot(131)
imshow(I);
subplot(132)
imshow(im2bw(scale1,0.70));%noise suppressed at this treshold
subplot(133)
imshow(im2bw(scale2,0.70));
clear;
img = imread('tt.jpg'); %
img_gray = rgb2gray(img); %
[m,n] = size(img_gray); %
new_img_gray = img_gray; %
pxValue = 0; %
for threshold_value=5:5:90
for i=1:m-1
for j=1:n-1
pxValue = abs(img_gray(i,j)-img_gray(i+1,j+1))+...
abs(img_gray(i+1,j)-img_gray(i,j+1));
if(pxValue > threshold_value)
new_img_gray(i,j) = 255;
else
new_img_gray(i,j) = 0;
end
end
end
subplot(3,6,threshold_value/5);
imshow(new_img_gray);
title(['thresholdvalue=',num2str(threshold_value)])
end
function Final=img_fusion(LH_out,HL_out,lphaar,hphaar,lphaar2,hphaar2,it2)
%LH_output here
it2=1;
LL=[];LH=[];HL=[];HH=[];
app_img = LH_out; % Initializing the Approximation Image.
for i = 1:it2
[LL{i}, LH{i} ,HL{i} , HH{i}] = img_decomp(app_img, lphaar, hphaar);
app_img = LL{i};
end
LH_final = LL{it2};
for i = it2:-1:1
LH_final = [LH_final,LH{i};HL{i},HH{i}];
end
LH_final=(LH_final-min(min(LH_final)))/(max(max(LH_final)) - min(min(LH_final)));
%HL_output here
app_img = HL_out; % Initializing the Approximation Image.
for i = 1:it2
[LL{i}, LH{i} ,HL{i} , HH{i}] = img_decomp(app_img, lphaar, hphaar);
app_img = LL{i};
end
HL_final = LL{it2};
for i = it2:-1:1
HL_final = [HL_final,LH{i};HL{i},HH{i}];
end
HL_final=(HL_final-min(min(HL_final)))/(max(max(HL_final)) - min(min(HL_final)));
Final = img_fuse(LH_final, HL_final);
Final = img_recomp(Final, it2, lphaar2, hphaar2);
Final=(Final-min(min(Final)))/(max(max(Final)) - min(min(Final)));
end
function recomp_decomposed=rec_decomp(recomposed,it2,lphaar,hphaar)
app_img = recomposed;
for i = 1:it2
[LL{i}, LH{i} ,HL{i} , HH{i}] = img_decomp(app_img, lphaar, hphaar);
app_img = LL{i};
end
subband = LL{it2};
for i = it2:-1:1
subband = [subband,LH{i};HL{i},HH{i}];
end
recomp_decomposed=subband;
end
[1]焦京峰, 肖怀铁, 付强. 基于灰度图像的积累加权边缘检测方法[J]. 电子工程师, 2005, 31(10):4.
部分理论引用网络文献,若有侵权联系博主删除。