Skip to content

Commit

Permalink
bugfix: merge touching labels didn't work in special geometrical situ…
Browse files Browse the repository at this point in the history
…ations. We now run it iteratively
  • Loading branch information
haesleinhuepf committed Mar 28, 2021
1 parent edd828c commit 0f23be2
Showing 1 changed file with 17 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,23 @@ public static boolean mergeTouchingLabels(CLIJ2 clij2, ClearCLBuffer input, Clea

clij2.closeIndexGapsInLabelMap(temp, output);

temp.close();
// check if none are touching
int num_labels = (int) clij2.maximumOfAllPixels(output);
ClearCLBuffer touch_matrix2 = clij2.create(new long[]{num_labels + 1, num_labels + 1}, clij2.UnsignedByte);
clij2.generateTouchMatrix(output, touch_matrix2);
clij2.setColumn(touch_matrix2, 0, 0);
clij2.setRow(touch_matrix2, 0, 0);
double num_touches = clij2.sumOfAllPixels(touch_matrix2);
touch_matrix2.close();

if (num_touches > 0) {
clij2.copy(output, temp);
mergeTouchingLabels(clij2, temp, output);
}


temp.close();

return true;
}

Expand Down Expand Up @@ -113,7 +127,8 @@ public static void main(String ... args) {
ClearCLBuffer input = clij2.pushString("" +
"1 1 0 2 0 3 0 0 0 0\n" +
"1 1 2 2 0 3 0 0 4 5\n" +
"1 0 0 2 0 0 0 0 4 5"
"1 0 0 2 0 0 0 0 4 5\n" +
"7 7 7 7 7 7 7 7 7 6"
);

ClearCLBuffer output = clij2.create(input);
Expand Down

0 comments on commit 0f23be2

Please sign in to comment.