lak*_*esh 0 matlab computer-vision
我打算在matlab中执行高斯边缘算子的拉普拉斯算子.
这是我的知识
LOG operators are second-order deriatives operator. Second order deriatives operator result in zero-crossing. At the step, position where 1st deriative is maximum is where the second deriative has zero crossing.
Run Code Online (Sandbox Code Playgroud)
我使用的掩码是mask = [0 1 0; 1 -4 1; 0 1 0];
原始图像是

我得到的输出来自原始图像

我的问题是为什么图像中的边缘显示为白色而不是黑色(= 0).它应该是黑色的吗?我是对还是错?谁有人解释一下?
卷积功能:
function [ I2 ] = image_convolution(I,w,G)
m= (w-1)/2;
N= size(I,1);
M=size(I,2);
for i=1:N
for j=1:M
if (i > N-m-1 || j > M-m-1 || i<m+1 || j <m+1)
I2(i,j) = 0;
continue;
end
sum1 = 0;
for u=1:w
for v=1:w
sum1 = sum1+I(i+u-m-1,j+v-m-1)*G(u,v);
end
end
I2(i,j)=sum1;
end
end
end
Run Code Online (Sandbox Code Playgroud)
一个简单的测试可以回答你的所有问题:
log_mask = [0 1 0; 1 -4 1; 0 1 0];
vertical_bar = zeros(11);
vertical_bar(:,5) = 1;
bar_filtered = image_convolution(vertical_bar, 3, log_mask)
box = zeros(11);
box(3:7,3:7) = 1;
box_filtered = image_convolution(box, 3, log_mask)
figure;
subplot(2,2,1); imshow(vertical_bar,[]); title('Vertical Bar');
subplot(2,2,2); imshow(bar_filtered,[]);title('Vertical Bar LoG Filtered');
subplot(2,2,3); imshow(box,[]);title('Box');
subplot(2,2,4); imshow(box_filtered,[]);title('Box LoG Filtered');
# Output:
#
# bar_filtered =
# 0 0 0 0 0 0 0 0 0 0 0
# 0 0 0 1 -2 1 0 0 0 0 0
# 0 0 0 1 -2 1 0 0 0 0 0
# 0 0 0 1 -2 1 0 0 0 0 0
# 0 0 0 1 -2 1 0 0 0 0 0
# 0 0 0 1 -2 1 0 0 0 0 0
# 0 0 0 1 -2 1 0 0 0 0 0
# 0 0 0 1 -2 1 0 0 0 0 0
# 0 0 0 1 -2 1 0 0 0 0 0
# 0 0 0 0 0 0 0 0 0 0 0
# 0 0 0 0 0 0 0 0 0 0 0
#box_filtered =
# 0 0 0 0 0 0 0 0 0 0 0
# 0 0 1 1 1 1 1 0 0 0 0
# 0 1 -2 -1 -1 -1 -2 1 0 0 0
# 0 1 -1 0 0 0 -1 1 0 0 0
# 0 1 -1 0 0 0 -1 1 0 0 0
# 0 1 -1 0 0 0 -1 1 0 0 0
# 0 1 -2 -1 -1 -1 -2 1 0 0 0
# 0 0 1 1 1 1 1 0 0 0 0
# 0 0 0 0 0 0 0 0 0 0 0
# 0 0 0 0 0 0 0 0 0 0 0
# 0 0 0 0 0 0 0 0 0 0 0
Run Code Online (Sandbox Code Playgroud)
过滤结果以图形方式显示:

看到?像素准确的边界上确实有负值,如你预期.另一方面,边框旁边的像素具有正值!值大于信号恒定区域的值.这些是您在结果中看到的"白色"值.
在数学上,这也很容易解释.看看你使用的面具

我已经绘制了它,因此更容易看到巨大山谷周围的小山峰.简单地说,它们使得边界周围的滤波值比其余像素具有更大的幅度,因此具有"边界识别"的效果.
我已经绘制了使用matlab函数创建的蒙版fspecial('log').在这个maks中,峰值更容易被发现.

最好的祝福