Skip to content

Fix organoid segmentation #44

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

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

Conversation

MikeLippincott
Copy link
Member

This PR adds critical functionality that scans an image for the largest object possible to segment across a dynamic range for whole organoid segmentation.

Copy link

Check out this pull request on  ReviewNB

See visual diffs & provide feedback on Jupyter Notebooks.


Powered by ReviewNB

@MikeLippincott MikeLippincott requested a review from Copilot May 9, 2025 03:39
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR fixes organoid segmentation by adding a recursive segmentation function and updating hardcoded parameters for whole organoid segmentation. Key changes include:

  • Renaming of hardcoded parameters such as well_fov and compartment in multiple scripts.
  • Introduction of the recursive function segment_with_diameter with dynamic diameter reduction.
  • Updates to notebook cell execution metadata and output messages.

Reviewed Changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
2.segment_images/scripts/7.clean_up_segmentation.py Updated cell indices in notebook run code.
2.segment_images/scripts/4.reconstruct_3D_masks.py Changed well_fov and compartment values to support organoid segmentation.
2.segment_images/scripts/3.segmentation_decoupling.py Modified well_fov and compartment values for organoid segmentation.
2.segment_images/scripts/2.segment_whole_organoids.py Added segment_with_diameter and updated segmentation flow and parameters.
2.segment_images/scripts/0.segment_nuclei_organoids.py Adjusted well_fov for proper path setup in notebook mode.
2.segment_images/notebooks/7.clean_up_segmentation.ipynb Updated execution counts and output messages for consistency.
Comments suppressed due to low confidence (1)

2.segment_images/scripts/2.segment_whole_organoids.py:308

  • [nitpick] The variable 'slice' shadows a built-in Python name. Consider renaming it (e.g., 'img_slice') to improve code clarity and prevent potential confusion.
for slice in tqdm.tqdm(range(imgs.shape[0])):


if labels is None:
print(f"Labels are empty for diameter {diameter}. Trying smaller diameter...")
return segment_with_diameter(img, model, channels, z_axis, diameter - 250)
Copy link
Preview

Copilot AI May 9, 2025

Choose a reason for hiding this comment

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

The recursive call passes parameters in an incorrect order; the function expects diameter as the third argument, so it should be called as segment_with_diameter(img, model, diameter - 250, z_axis, channels).

Suggested change
return segment_with_diameter(img, model, channels, z_axis, diameter - 250)
return segment_with_diameter(img, model, diameter - 250, z_axis, channels)

Copilot uses AI. Check for mistakes.

# In[2]:


def segment_with_diameter(
Copy link
Member

Choose a reason for hiding this comment

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

Loving the definition of this function - looks like it's useful. Consider adding a software test to confirm this works with something rudimentary, like a generated egg shape, or something similar. Generally, once a capability becomes firm enough to functionalize I recommend adding at least one test. We might theorize that this could be developed at a later point, but we may forget the context of which test confirmations are most important to the work.

diameter: int,
z_axis: int = 0,
channels: tuple = [1, 0],
):
Copy link
Member

Choose a reason for hiding this comment

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

Consider adding the return type here (it looks well documented below!).

The labels of the segmented image.
details : dict
The details of the segmentation.
_ : None
Copy link
Member

Choose a reason for hiding this comment

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

Consider removing this value and relying instead on a Dict. This would allow you to expand the work through a type without getting caught in a specific number of return values.

_ : None
Placeholder for additional return values.
"""
if diameter < 250:
Copy link
Member

Choose a reason for hiding this comment

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

Would it make sense to make the minimum diameter a parameter? I imagine this could change from dataset to dataset.

----------
img : np.ndarray
The image to segment. Can be 3D in the format of (z, y, x).
model : models.Cellpose
Copy link
Member

Choose a reason for hiding this comment

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

Neat!

Comment on lines +180 to +182
# cyto1, # ER
cyto2, # AGP
# cyto3, # Mito
Copy link
Member

Choose a reason for hiding this comment

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

Consider renaming to channel_agp or something similar to help make this more specific. Also - why only this channel?

squared_butterworth=True,
)

# add a guassian blur to the image
Copy link
Member

Choose a reason for hiding this comment

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

Why do we add guassian blur to the image? Consider answering within the code comment. Also - could this impact the data integrity at all?

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.

2 participants