-
Notifications
You must be signed in to change notification settings - Fork 1
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
Add function to mask tissue regions #104
base: main
Are you sure you want to change the base?
Conversation
Looks like a great start already! In what form does the user need to provide a shape at the moment? can this be done interactively in Napari?
I would implement this as a method to the project object so that we can e.g. call: Under the hood this would then access the spatialdata object that is associated with the project file. You can get it via: So I guess an implementation along the lines of:
Currently the _write_image_sdata is still a function belonging to project but it needs to be relocated (and improved) to the filehandler. (the filehandler was introduced more recently when I realized that we otherwise encounter issues with multithreading some operations but the migration has not been completed in full yet).
So far we have never worked with RGB images. @namsaraeva is working on this for the first time now.
Should be completely resized as this will improve run time of all downstream steps. We have some checks where code is not executed if an area only contains 0 pixels, but these checks only go into effect if NO non-zero values are contained.
mask_filtering module here refers to operations to filter generated segmentation masks (e.g. to only keep masks with a min cell size). I think the best place for it would be under
I think it would be nice to have the possibility for users to plug in their own methods, but I think this is a functionality which will only be used by a few more advanced users. So the default as you implemented it now with a thresholding should be sufficient. |
Polygon containing the detected regions. | ||
""" | ||
if image.shape[0] == 1: | ||
image = image[0] |
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.
to improve thresholding here a little we could calculate this on a downsampled version of the image which has also been blurred slightly. This should make it a little easier to detect macro structures (like e.g. tissue) somewhat smoothly.
Once ready, closes #50
Adds a function to mask an image. Given a user-provided shape, either crop the image such that only pixels within the mask remain or if
Invert=False
mask the image (only keep pixels outside the shape).example calls for image masking with user provided shape:
mask_image(sdata, "test", "mask", invert=True)
mask_image(sdata, "test", "mask", invert=False)
Alternatively one can use a threshold + watershed approach to automatically segment and mask the image.
E.g. given the following test image:
mask_image(sdata, "test_2", None, invert=True, automatic_masking=True, threshold=50)
yields
with
threshold=80
:For automatic region detection the threshold is image-specific.
Right now the code is still a draft, since i wasn't sure how to properly embed it into your current codebase, so the main questions are:
mask_filtering
module the correct place for this function?