Conversation
|
Hello @arnaudbrejeon thanks for the bug report and fix! |
|
@arnaudbrejeon Well done! Thanks for the reproducer! Reference on original patch: #8789 (#7705).
Your guess seems correct. Perhaps "odd" case is not expected at all by processing code:
and finally:
Last statements trying to guarantee that subtask size is not less than 2 rows (or may be even "even"). There is similar problem with 4 connectivity stripes:
Q: Why are we observing crash instead of incorrect result? A: Uninitialized array with garbage after the first element: There is one more similar place in Additional commits will be pushed shortly. |
resolves #16410
Here is what is happening. In order to do the parallelization, the image is split in stripes and labelling is done on each stripe. In order for stripes to be independent, each stripe starting at height
yand with widthwgets a startLabel defined as:startLabel = (y+1)/2 * (w+1)/2 + 1The formula comes from the fact that for an image of height
hand widthw, an upper bound of the number of labels is:(h+1)/2 * (w+1)/2 + 1The startLabels are too close to each other in some cases and create labels overlapping. Here is why:
let's say a stripe starts in
y0and finishes iny1, we can writey0 = 2*y + 1andy1 = 2*y + 1 + hThe maximum number of labels is
(h+1)/2 * (w+1)/2 + 1The number of labels for the stripe is:
( (2*y+1+h+1)/2 * (w+1)/2 + 1 ) - ( (2*y+1+1)/2 * (w+1)/2 + 1 )which is equal to((h+2)/2 - 1) * (w+1)/2 = (h/2) * (w+1)/2If
his odd, then the number of allowed labels in the stripe is not large enough.In order to make sure there is enough labels for each stripe, I suggest we use the formula:
startLabel = (y+2)/2 * (w+1)/2 + 1