【发布时间】:2021-12-19 07:44:06
【问题描述】:
我实现了 Prewitt 边缘检测器,并将我的输出与 Matlab 的内置 Prewitt 边缘检测器进行了比较,我注意到我的输出提供了更厚的边缘。可能是什么原因?
input = imread('pic.png');
input = double(rgb2gray(input));
kernel_x = [-1, 0, 1; -1, 0, 1; -1, 0, 1];
kernel_y = [1, 1, 1; 0, 0, 0; -1, -1, -1];
[length, width] = size(input);
new = input;
for i = 1:length - 2
for j = 1:width - 2
Gx = sum(sum(kernel_x.*input(i:i+2, j:j+2)));
Gy = sum(sum(kernel_y.*input(i:i+2, j:j+2)));
new(i+1, j+1) = sqrt(Gx.^2 + Gy.^2);
end
end
new = uint8(new);
% binarizing image and setting threshold
edge = imbinarize(edge, 100); % final output from implementation
我使用的内置函数是edge(input, 'Prewitt')
我的实现与内置运算符的输出:
这可能是什么原因?
我也尝试更改阈值,但仍然没有成功。
【问题讨论】:
-
我认为是
edge(edge==100) = 0行。我认为您想使用<而不是==。 -
@CrisLuengo 我使用了 Matlab edge() 函数。边缘(输入,'prewitt')
-
@DrewHall 我更改了代码。我没有使用 3 行进行阈值处理,而是使用了 imbinarize(edge, threshold)。不过,我的边缘很厚。
标签: matlab image-processing computer-vision edge-detection