【问题标题】:Prewitt edge detector implemented with Matlab gives thick edges than the in-built function使用 Matlab 实现的 Prewitt 边缘检测器提供的边缘比内置函数厚
【发布时间】: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


【解决方案1】:

文档中没有明确说明,但是对于 Sobel、Prewitt 和 Roberts 方法,edge 应用了细化。有an optional input argument 'nothinning',它跳过了细化步骤。不幸的是,这是文档中唯一表明此步骤正在发生的部分。

如果您有使用bwmorph(bw,'thin') 的图像处理工具箱,则可以应用细化。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-09-20
    • 1970-01-01
    • 1970-01-01
    • 2012-09-17
    • 2012-04-16
    • 2014-08-25
    • 1970-01-01
    • 2014-08-02
    相关资源
    最近更新 更多