[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[pygame] [PATCH] fix incorrect behavior and performance in mask.get_bounding_rects()



In testing some computer vision stuff I was writing, I found that
mask.get_bounding_rects() often split a connected component into
multiple bounding boxes.  Specifically in the following case:

0011
1111

It would split the 11 in the first row and the 1111 in the second row
into separate connected components, and therefore separate bounding
boxes.

I wrote a new version of it based on the algorithm I used in
mask.connected_component.  It correctly detects connected components,
and there is also a side benefit of an, on average, 2x increase in
performance.

I attached the functions that I changed, and the full mask.c is
available in my repo, though it also contains other functions that I'm
proposing for 1.9.
http://git.n0r.org/?p=pygame-nrp;a=blob;f=src/mask.c

Nirav

Attachment: get_bounding_rects
Description: Binary data