Fix upper bound for number of labels in Grana and Wu algorithms#7608
Fix upper bound for number of labels in Grana and Wu algorithms#7608sokian wants to merge 2 commits intoopencv:masterfrom
Conversation
…Components computation
|
Hi @sokian,
is absolutely enough!! I will explain it in the following with some examples. First of all it is important to highlight that Grana’s algorithm treats only 8-way connectivity. So, for example, considering a binary image of 6x6 some of the worst cases (i.e. in which the maximum number of labels will be generated) are given by configurations reported in figures 1, 2, 3 and 4. In that cases the maximum number of labels is given by the following formula: (h*w)/4 + 1 (1) one label for every 2x2 block + one label for the background. Now, if we consider the case of images with odd number of columns, rows or both (6x5 or 5x6 or 5x5) some examples of the worst cases are the ones presented in figures 5, 6, 7. In such cases, the formula (1) may fails because some of 2x2 blocks are “incomplete”. In these cases, just adding one to the matrix width and height (i.e h+1 and w+1 in the general formula above) we solve the issue obtaining an effective general upper bound.
|
|
Hi @prittt, Oh, I see, if this algorithm will be used only for 8-connectivity case, then there should be an Assert CV_Assert(connectivity == 8);But now it has Assert: CV_Assert(connectivity == 8 || connectivity == 4);And, of course, I agree with you for upper bound in 8-connectivity case, it's obvious right (thanks for such beautiful explanation with example images). |
…belingWu and LabelingGrana to right formulas
15417c7 to
8e8b1f1
Compare
|
👍 |
|
There is another PR with complete rewrite of connectedComponents pending. Let's merge that one first, and then, if this one is still relevant, it should be updated. |
|
ok, let's close this one for now. please, reopen if it's still relevant |







This pullrequest changes
resolves #7607
Fix upper bound for the maximimum number of labels in LabelingGrana.
…Components computation