Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/image-processing/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/windows/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java映像连接组件_Java_Image Processing_Bufferedimage - Fatal编程技术网

Java映像连接组件

Java映像连接组件,java,image-processing,bufferedimage,Java,Image Processing,Bufferedimage,我有一个程序来检测二值化BuffereImage中的对象,该图像是一个多选答案表。 我正在尝试使用4-Connectivity as in来检测每个对象(答案在工作表上)。 到目前为止,我手头上的资料是: 我根据维基百科的指示提出了这个建议: if(getPixel(image, x, y) != 0){ if(getPixel(image, x-1, y) !=0){ System.out.println("we are in the same region");

我有一个程序来检测二值化BuffereImage中的对象,该图像是一个多选答案表。
我正在尝试使用4-Connectivity as in来检测每个对象(答案在工作表上)。
到目前为止,我手头上的资料是:

  • 我根据维基百科的指示提出了这个建议:

    if(getPixel(image, x, y) != 0){
        if(getPixel(image, x-1, y) !=0){
            System.out.println("we are in the same region");
            region[x][y] = region[x-1][y];
        } 
        else if(getPixel(image, x-1, y) !=0 && getPixel(image, x, y-1) !=0){
            System.out.println("North and West pixels belong to the same region and must be merged");
            region[x][y] = Math.min(region[x-1][y], region[x][y-1]);
        }
        else if( getPixel(image, x-1, y) ==0 && getPixel(image, x, y-1) !=0){
            System.out.println("Assign the label of the North pixel to the current pixel");
            region[x][y] = region[x][y-1];
        }
        else if(getPixel(image, x-1, y) ==0 && getPixel(image, x, y-1) ==0){
            System.out.println("Create a new label id and assign it to the current pixel");
            cpt++;
            region[x][y] = cpt;
        }
    
    但问题是它创造了51个区域!并且它只打印每个对象的几个顶部像素(不是所有像素)。
    有谁能帮我找出问题所在以及如何检测我的物体吗?

    如果您能提供帮助,我将不胜感激。

    虽然我不能完全确定这是否能回答您的问题,但我会修改您的代码,使其如下所示:

    if(getPixel(image, x, y) != 0){
        if(getPixel(image, x-1, y) !=0){
            if(getPixel(image, x, y-1) !=0) {
                System.out.println("North and West pixels belong to the same region and must be merged");
                region[x][y] = Math.min(region[x-1][y], region[x][y-1]);
            } else {
                System.out.println("we are in the same region");
                region[x][y] = region[x-1][y];
            }
        } else if(getPixel(image, x-1, y) ==0) {
            if(getPixel(image, x, y-1) !=0) {
                System.out.println("Assign the label of the North pixel to the current pixel");
                region[x][y] = region[x][y-1];
            } else if (getPixel(image, x, y-1) ==0) {
                System.out.println("Create a new label id and assign it to the current pixel");
                cpt++;
                region[x][y] = cpt;
            }
        }
    

    虽然我不能完全确定这是否能回答您的问题,但我会修改您的代码,使其看起来像这样:

    if(getPixel(image, x, y) != 0){
        if(getPixel(image, x-1, y) !=0){
            if(getPixel(image, x, y-1) !=0) {
                System.out.println("North and West pixels belong to the same region and must be merged");
                region[x][y] = Math.min(region[x-1][y], region[x][y-1]);
            } else {
                System.out.println("we are in the same region");
                region[x][y] = region[x-1][y];
            }
        } else if(getPixel(image, x-1, y) ==0) {
            if(getPixel(image, x, y-1) !=0) {
                System.out.println("Assign the label of the North pixel to the current pixel");
                region[x][y] = region[x][y-1];
            } else if (getPixel(image, x, y-1) ==0) {
                System.out.println("Create a new label id and assign it to the current pixel");
                cpt++;
                region[x][y] = cpt;
            }
        }
    

    您可能会得到很多区域,因为您似乎没有合并相等的标签。没有用于在代码段中存储相等标签的代码。该算法是两遍算法,其中第一遍分配标签,第二遍合并相等的标签

    以下是维基百科页面引用的条件检查:

    检查条件:

  • 左侧(西部)的像素是否与当前像素具有相同的值?
  • ——我们在同一地区。将同一标签指定给当前像素
  • –检查下一个条件
  • 当前像素北部和西部的两个像素是否与当前像素的值相同,但标签不同?
  • –我们知道北部和西部像素属于同一区域,必须合并。为当前像素指定“北”和“西”标签的最小值,并记录它们的等效关系
  • –检查下一个条件
  • 左侧(西部)的像素是否具有不同的值,而北部的像素是否具有与当前像素相同的值?
  • –将北像素的标签指定给当前像素
  • –检查下一个条件
  • 像素的北邻域和西邻域是否与当前像素具有不同的像素值?
  • –创建新标签id并将其分配给当前像素
  • 你的第二次状况检查

    else if(getPixel(image, x-1, y) !=0 && getPixel(image, x, y-1) !=0)
    
    不检查左像素和上像素是否具有不同的标签

    此外,正如supersam654在评论中提到的那样,将永远不会调用第一个
    else if
    。看起来维基百科页面上的条件检查(1)和(2)的顺序应该相反。也就是说,首先检查左上像素是否与当前像素具有相同的值,但标签不相同。然后,如果检查失败,请检查左侧像素是否与当前像素具有相同的值

    因此,请尝试以下方法:

  • 将标签条件添加到第二个条件检查中
  • 切换前两个条件检查的顺序
  • 跟踪相等的标签(即,哪些标签表示相同的区域)
  • 对图像进行第二次扫描并合并相等的标签

  • 我希望这有帮助。

    您可能会得到很多区域,因为您似乎没有合并相同的标签。没有用于在代码段中存储相等标签的代码。该算法是两遍算法,其中第一遍分配标签,第二遍合并相等的标签

    以下是维基百科页面引用的条件检查:

    检查条件:

  • 左侧(西部)的像素是否与当前像素具有相同的值?
  • ——我们在同一地区。将同一标签指定给当前像素
  • –检查下一个条件
  • 当前像素北部和西部的两个像素是否与当前像素的值相同,但标签不同?
  • –我们知道北部和西部像素属于同一区域,必须合并。为当前像素指定“北”和“西”标签的最小值,并记录它们的等效关系
  • –检查下一个条件
  • 左侧(西部)的像素是否具有不同的值,而北部的像素是否具有与当前像素相同的值?
  • –将北像素的标签指定给当前像素
  • –检查下一个条件
  • 像素的北邻域和西邻域是否与当前像素具有不同的像素值?
  • –创建新标签id并将其分配给当前像素
  • 你的第二次状况检查

    else if(getPixel(image, x-1, y) !=0 && getPixel(image, x, y-1) !=0)
    
    不检查左像素和上像素是否具有不同的标签

    此外,正如supersam654在评论中提到的那样,将永远不会调用第一个
    else if
    。看起来维基百科页面上的条件检查(1)和(2)的顺序应该相反。也就是说,首先检查左上像素是否与当前像素具有相同的值,但标签不相同。然后,如果检查失败,请检查左侧像素是否与当前像素具有相同的值

    因此,请尝试以下方法:

  • 将标签条件添加到第二个条件检查中
  • 切换前两个条件检查的顺序
  • 跟踪相等的标签(即,哪些标签表示相同的区域)
  • 对图像进行第二次扫描并合并相等的标签

  • 我希望这有帮助。

    根据
    if/else if
    代码的顺序,第二个代码块(第一个
    else if
    )将永远不会被调用。我不认为这是你想要的。@supersam654是的,你是对的,它从未被调用过,我应该把它放在哪里?感谢根据
    if/else if
    代码的顺序,第二个代码块(第一个
    el