-
Notifications
You must be signed in to change notification settings - Fork 47
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Vectorize labels into polygons #560
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #560 +/- ##
==========================================
- Coverage 92.55% 92.52% -0.03%
==========================================
Files 42 42
Lines 6003 6086 +83
==========================================
+ Hits 5556 5631 +75
- Misses 447 455 +8
|
mask = np.pad(region_props.image, 1) | ||
contours = skimage.measure.find_contours(mask, 0.5) | ||
|
||
polygons = [Polygon(contour[:, [1, 0]]) for contour in contours if contour.shape[0] >= 4] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would add a comment explaining the choice of 4.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added a comment in the code.
When the number of vertices is 3, the shape is basically a line (2 points + repetition of the first point), which would raise a Shapely error. This is why I added this filtering.
Though, we should never have a shape with less than three coordinates: even a single pixel would be converted into a square. I just added this filtering for safety, but I'm not sure if skimage can produce a shape with less than 3 coordinates.
Excellent PR! I just added a minor comment, but otherwise looks great! I will check/implement the following minor cases (copying them from the hackmd): small things
other small things
I will merge after I complete them. |
Converting a mask (2D Labels, multiscale or not) into shapes, i.e. a GeoDataFrame.
Speed test
1 min on 300k cells locally
Notes
scikit_image
is used to find contours (for each label, a cropped view is extracted, then vectorized, and then translated according to the bounding box coords)dissolve
methodFuture steps