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

Improved large_nuclei splitting #244

Merged
merged 5 commits into from
Oct 6, 2020
Merged

Conversation

ngreenwald
Copy link
Member

If you haven't already, please read through our contributing guidelines before opening your PR

What is the purpose of this PR?

Additional tweaks to the nuclei split logic. One issue that came up was if the nuclear mask was just a tiny bit bigger than the cell mask. For example, one pixel larger on one side. This resulted in potentially a single pixel being cut from the mask, relabeled, and given a new ID. This creates tons of new, tiny nuclear objects, which we don't want.

How did you implement your changes

  1. setting a threshold of 5 pixels before splitting the nucleus. This means that if there is only a small portion outside of the cell, it's unmodified.
  2. Removing small objects after the split has been performed. The above works if all of the pixels are in the same spot. But if there are multiple small regions on both sides of the nucleus that are larger, the above still fails, so we remove any small objects after the split.

Copy link
Contributor

@alex-l-kong alex-l-kong left a comment

Choose a reason for hiding this comment

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

Looks great! I just had one comment about the call to remove_small_objects.

@@ -77,6 +78,8 @@ def compute_marker_counts(input_images, segmentation_masks, nuclear_counts=False
nuc_mask = segmentation_utils.split_large_nuclei(cell_segmentation_mask=cell_mask,
nuc_segmentation_mask=nuc_mask,
cell_ids=unique_cell_ids)
nuc_mask = remove_small_objects(ar=nuc_mask, min_size=5)
Copy link
Contributor

Choose a reason for hiding this comment

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

An alternative would be to put the call to remove_small_objects inside split_large_nuclei and add a parameter to split_large_nuclei to control the min_size parameter of remove_small_objects. If min_size is not None, then we make the additional call. This would be helpful if we plan on calling remove_small_objects every time after split_large_nuclei is called.

Copy link
Contributor

@ackagel ackagel left a comment

Choose a reason for hiding this comment

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

Looks good. Just one nag about hardcoding.

# only proceed if parts of the nucleus are outside of the cell
if nuc_count != np.sum(nuc_mask):
# only proceed if a non-negligible part of the nucleus is outside of the cell
if np.sum(nuc_mask) - nuc_count > 5:
Copy link
Contributor

Choose a reason for hiding this comment

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

this 5 should probably be a min_size parameter in the split_large_nuclei function.

Copy link
Contributor

@alex-l-kong alex-l-kong left a comment

Choose a reason for hiding this comment

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

Looks good!

@ngreenwald ngreenwald merged commit 526ea6d into master Oct 6, 2020
@ngreenwald ngreenwald deleted the nuclei_split_threshold branch October 6, 2020 18:31
alex-l-kong added a commit that referenced this pull request Jan 14, 2021
* tweak logic for large nuclei

* no hardcoding

Co-authored-by: alex-l-kong <31424707+alex-l-kong@users.noreply.github.com>
y2kbugger pushed a commit that referenced this pull request Jul 29, 2021
* tweak logic for large nuclei

* no hardcoding

Co-authored-by: alex-l-kong <31424707+alex-l-kong@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants