【问题标题】:Sobel Operator not working [closed]Sobel算子不工作[关闭]
【发布时间】:2012-03-09 05:42:41
【问题描述】:

过去两个小时我一直在研究它,但没有意识到问题出在哪里,您能帮帮我吗?

public static void sobel(Img img) {

    int[][][] myArray = img.getmyArray();
    int[][][] sobelX = img.copyMyArray();
    int[][][] sobelY = img.copyMyArray();

    //itearates through the matrix to apply the Sobel Operator
    for (int line = 1; line < myArray.length -2; line++)
        for (int column = 1; column < myArray[line].length -2; column++)
            for(int color = 0; color < 3; color++){

            sobelX[line][column][color] =
                    -1 * myArray[line-1][column-1][color] +
                    -2 * myArray[line-1][column][color] +
                    -1 * myArray[line-1][column+1][color] +

                     0 * myArray[line][column-1][color] +
                     0 * myArray[line][column][color] +
                     0 * myArray[line][column+1][color] +

                     1 * myArray[line+1][column-1][color] +
                     2 * myArray[line+1][column][color] +
                     1 * myArray[line+1][column+1][color];

            sobelY[line][column][color] =
                    -1 * myArray[line-1][column-1][color] +
                     0 * myArray[line-1][column][color] +
                     1 * myArray[line-1][column+1][color] +

                    -2 * myArray[line][column-1][color] +
                     0 * myArray[line][column][color] +
                     2 * myArray[line][column+1][color] +

                    -1 * myArray[line+1][column-1][color] +
                     0 * myArray[line+1][column][color] +
                     1 * myArray[line+1][column+1][color];


            //Final Calculation
            myArray[line][column][color] = check_0_255_limit((int)Math.sqrt(
                    sobelX[line][column][color] * sobelX[line][column][color]
                    +
                    sobelY[line][column][color] * sobelY[line][column][color]
                    ));

        }// end for loop
}

没有错误消息,代码正在编译和运行,但是我得到了一个错误的输出,这不是我所期望的..

【问题讨论】:

  • -1 代码中没有错误消息,没有有用的线索,没有一条有用的注释。
  • 问题似乎是你的问题没有问题。
  • 实际上问题似乎是:“你能帮帮我吗?”我的回答是:“当然,有什么问题?”

标签: java arrays image-processing matrix computer-vision


【解决方案1】:

您正在独立计算每个通道的梯度;你真的需要,因为你的输出不是彩色的吗? 此外,在给定 0..255 通道值输入的情况下,运算符的输出将为 -1020..1020,因此您需要在使用 Sqrt 获得幅度之前或之后对其进行缩放,以使其回到 0..255 范围.

但主要问题可能是“最终计算”输出覆盖了您正在循环的数组(即过滤器正在重新处理已处理的值),因此将其放入自己的数组中。这就是产生酷抖动效果的原因!

【讨论】:

  • 对不起,我没有意识到这个问题“不能以目前的形式得到合理的回答”,我很确定我理解了!!
猜你喜欢
  • 2017-01-12
  • 2017-06-21
  • 2018-01-31
  • 2019-12-04
  • 2022-01-23
  • 2021-08-31
  • 2018-07-23
  • 2018-01-16
  • 2014-04-18
相关资源
最近更新 更多