Skip to content
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

Support contours in future.manual_segmentation #2966

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

aaronsnoswell
Copy link

@aaronsnoswell aaronsnoswell commented Feb 16, 2018

Description

This PR updates the functions future.manual_segmentation.manual_polygon_segmentation and future.manual_segmentation.manual_lasso_segmentation. The changes add a second return parameter that is the actual list of contour points. This is sometimes more useful to an end user than the mask only.

NB: This will break previous APIs that depended on these functions. Old code might have looked like this (from the docstrings);

camera = data.camera()
mask = manual_segmentation.manual_lasso_segmentation(camera)
io.imshow(mask)  
io.show()

Now, users will have to add a temporary variable to catch the contour, even if they are not interested in it; viz.

mask, _ = manual_segmentation.manual_lasso_segmentation(camera)

Docstrings are updated and the changes were fairly minimal - I haven't read all of PEP8, but I believe it should still be compatible (unless multiple return statements are a no-no).

Checklist

[It's fine to submit PRs which are a work in progress! But before they are merged, all PRs should provide:]

Release notes message:

 ``future.manual_segmentation.manual_polygon_segmentation`` and
  ``future.manual_segmentation.manual_lasso_segmentation`` were updated to also
  return the contour points picked, not just a mask image.

@pep8speaks
Copy link

pep8speaks commented Feb 16, 2018

Hello @aaronsnoswell! Thanks for updating the PR.

Cheers ! There are no PEP8 issues in this Pull Request. 🍻

Comment last updated on February 16, 2018 at 06:49 Hours UTC

@soupault soupault added the ⏩ type: Enhancement Improve existing features label Feb 16, 2018
Copy link
Member

@soupault soupault left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Quite useful enhancement! Couple of remarks from me, otherwise ok

@@ -49,6 +50,9 @@ def manual_polygon_segmentation(image, alpha=0.4, return_all=False):
labels : array of int, shape ([Q, ]M, N)
The segmented regions. If mode is `'separate'`, the leading dimension
of the array corresponds to the number of regions that the user drew.
contours : array of float, shape (Q, 2)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The shape of contours is clearly not correct here. Has to be a list of lists or something similar.



def manual_lasso_segmentation(image, alpha=0.4, return_all=False):
"""Return a label image based on freeform selections made with the mouse.
"""Return a label image and list of contours based on freeform selections
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Keep it a one-liner. If more detailed description is required, put it 2 lines below.
Also, fix a double whitespace.

@@ -160,6 +171,9 @@ def manual_lasso_segmentation(image, alpha=0.4, return_all=False):
labels : array of int, shape ([Q, ]M, N)
The segmented regions. If mode is `'separate'`, the leading dimension
of the array corresponds to the number of regions that the user drew.
contours : array of float, shape (Q, 2)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same for the shape here.

@@ -212,6 +227,11 @@ def _on_lasso_selection(vertices):
labels = (_mask_from_vertices(vertices, image.shape[:2], i)
for i, vertices in enumerate(list_of_vertex_lists, start=1))
if return_all:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update return_all parameter description for both functions to include also info on contours.

@soupault soupault added this to the 0.14.1 milestone Feb 21, 2018
@soupault
Copy link
Member

@aaronsnoswell hi! Did you have time to make the requested changes?

@soupault soupault modified the milestones: 0.14.1, 0.14 Apr 27, 2018
@soupault soupault modified the milestones: 0.14, 0.15 May 23, 2018
@soupault soupault self-assigned this Jul 29, 2018
@soupault soupault modified the milestones: 0.15, 0.16 Apr 20, 2019
Base automatically changed from master to main February 18, 2021 18:23
Aaron Snoswell added 3 commits October 24, 2023 21:21
This commit adds support for optoinally returning contours from the functions manual_lasso_segmentation and manual_polygon_segmentation. Sometimes a contour is more useful to you than a mask.
@soupault soupault force-pushed the support-contours-manual-segmentation branch from 5acf2aa to 579fa1e Compare October 24, 2023 18:23
@soupault
Copy link
Member

While returning polygon vertices (PVs) / contour points (CPs) would be a nice addition to the manual segmentation functions, it comes here with a challenge. With return_all set to False, the polygons/masks are post-processed in a way that the polygons/masks drawn later zero out the areas of the ones drawn earlier when they overlap. In such cases, the returned PVs/CPs are not correct, since they are recorded from the regions before post-processing. The correct implementation would first post-process the polygons/masks and then recompute the PVs/CPs. For polygon vertices, this becomes quite complicated already, and I am not sure whether we want to go further in the direction of implementing advanced parts of image editing tools in skimage.

I would advocate for keeping the manual segmentaiton tools as simple as possible (or, perhaps, even removing them at some point) and encouraging users to learn and utilize the professional tools for image annotation (such as Napari, ITK-SNAP, Slicer3D, etc).

Since there has been no activity on this PR for a while and the implementation is somewhat early-stage, I propose to close the PR until further notice.

@soupault soupault removed their assignment Oct 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants