【问题标题】:Best high/low canny threshold to find Arbitrary number of pixel找到任意像素数的最佳高/低精明阈值
【发布时间】:2015-10-07 06:32:48
【问题描述】:

我想在我的隐写算法中使用 canny 边缘检测,所以当我需要例如 250 像素来隐藏信息时,我必须找到 canny 的最佳低/高阈值,以便在图像中找到至少 250 个最清晰的像素。

另一个例子,当我需要 500 像素来隐藏信息时,我必须找到低/高阈值才能在图像中找到至少 500 像素。

我认为我可以使用二分搜索,但它没有返回最佳阈值。这是我的二分搜索功能:

function [ th ] = getThreshold( I, N, w )
 % limit is set to 1% of the message
 % length
 % no. of edge pixels,ne ? N + 0.01 × N
 % and ne ? N
 % ne = number of edge pixels in I, when
 % Canny edge detector is used on I with
 % high threshold th and low threshold
 % tl = 0.4 ? th and width w

 limit = (0.01 * N);

 tmax = 0.8;
 tmin = 0;
 set = true;

 while(set)
   th = double((tmax + tmin)/2);
   BW = edge(I,'canny',[tmin tmax],'both',w);
   % it returns the number of pixels in the edges obtained through  Canny
   %     edge detector
   ne = getEdgePixelCount(BW);

   diff = ne - N;
   if diff > limit
      tmin = th;
   elseif diff < 0
      tmax = th;
   else
      set = false;
 end  
end

【问题讨论】:

  • 计算sobel震级怎么样,保持N最高?

标签: matlab image-processing


【解决方案1】:

您是否检查过 MATLAB 本身应用的优化阈值?从 MATLAB 文档中你有:

在所有情况下,edge 都会根据输入数据启发式地选择默认阈值。改变阈值的最佳方法是运行一次边缘,将计算的阈值捕获为第二个输出参数。然后,从edge计算的值开始,将阈值调高(边缘像素少)或调低(边缘像素多)。>>

因此,为了获得 MATLAB 优化的 Canny 阈值,您可以使用

   [~, th] = edge(yourpicture,'canny');

然后应用优化的阈值 th 乘以某个因子 f(根据我的经验 f 应该在 1-3 之间),你必须尝试一下:

edgepict=edge(yourpicture,'canny',f*th,'both', sigma);

注意 th 实际上是一个包含 th_low 和 th_high 的向量。 Th_low 默认为 0.4*th_high(如果我没记错的话),我不会改变它。除了因子 f,您还可以使用默认为 sqrt(2) 的 sigma。 Sigma指的是canny算法第一步应用的高斯模糊的半径。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-10-13
    • 2012-06-11
    • 1970-01-01
    • 1970-01-01
    • 2021-02-10
    • 1970-01-01
    相关资源
    最近更新 更多