【问题标题】:Sobel edge-detection, weird outputSobel边缘检测,奇怪的输出
【发布时间】:2016-11-07 17:13:30
【问题描述】:

我正在尝试为 YUV 相机流的边缘检测实现 Sobel 算法。最初看起来很容易,但我不确定这种方法是否正确:

  • 我将过滤器仅应用于 Y 像素分量,并将 U 和 V = 0(黑白图像)。
  • 之后,为了检查结果,我通过串行端口发送帧,但在将图像从 YUV 转换为 jpg 之前。

黑白图像完美运行,我可以在我编写的 PC 应用程序上看到它,但是当我将 Sobel 过滤器应用于 Y 组件时,我得到了这个:

代码:

    #define index(xx, yy)  ((yy * width + xx) * 2) & 0xFFFFFFFE  // address multiple of 2

(...............)

for (y=1, y < height-1; y++){
    for (x=1, y < width-1; y++){
        pixel_valueY_h=0.0;
        pixel_valueY_v=0.0;
      for (j= -1; j<2; j++){
         for (i= -1; i<2; i++){

            offset= index(x+1, y+1);
            pixel_valueY_h += (sobel_h[j + 1][i + 1])* input[offset+1]; //offset+1=> Y component
            pixel_valueY_v += (sobel_v[j + 1][i + 1])* input[offset+1]; 

         }
      }
        offset = index(x,y);
        pixel_value= sqrt1((pixel_valueY_h * pixel_valueY_h)+(pixel_valueY_v * pixel_valueY_v));

        if (pixel_value > 255) pixel_value=255;
        if (pixel_value < 0) pixel_value=0;

        //output frame
        output[offset] &=0x00; //U and V components = 0
        output[offset+1] &=(255- (unsigned char)pixel_value );
    }
}

(...............)

关于发生了什么的任何线索? 提前致谢。

【问题讨论】:

  • 请将源代码直接复制到帖子正文中。这使其他 SO 用户更容易阅读、运行和编辑您的代码。
  • 我们能看到Sobel之前的图像吗?

标签: edge-detection sobel


【解决方案1】:

终于我搞定了,问题是使用宏进行内存寻址:#define index(xx, yy) ((yy * width + xx) * 2) & 0xFFFFFFFE 由于某种原因给出了不正确的地址. 相反,我在代码中添加了 (((yy * width + xx) * 2) & 0xFFFFFFFE) 行,并且这样(没有修改)工作得很好。

谢谢。

【讨论】:

    猜你喜欢
    • 2016-10-03
    • 2018-05-17
    • 1970-01-01
    • 1970-01-01
    • 2011-02-25
    • 2015-01-02
    • 1970-01-01
    • 2021-06-02
    • 2020-04-06
    相关资源
    最近更新 更多