Skip to content

Commit

Permalink
Increase range of threshold sigma parameter (#134)
Browse files Browse the repository at this point in the history
Addressing #131 with the proposed solution of creating a threshold
proportional to the max value of the image
  • Loading branch information
Pablo1990 committed Sep 22, 2023
1 parent 3fabc06 commit 78b2623
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
6 changes: 5 additions & 1 deletion src/epitools/analysis/segmentation.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def thresholded_local_minima_seeded_watershed(
image: npt.NDArray[np.float64],
spot_sigma: float = 3,
outline_sigma: float = 0,
minimum_intensity: float = 500,
minimum_intensity: float = 0.01,
) -> tuple[list[list[Any]], npt.NDArray[np.uint32]]:
"""
Segment cells in images with marked membranes that have a high signal intensity.
Expand All @@ -63,6 +63,7 @@ def thresholded_local_minima_seeded_watershed(
Afterwards, all objects are removed that have an average intensity below a given
minimum_intensity
"""

spots, labels = local_minima_seeded_watershed(
image, spot_sigma=spot_sigma, outline_sigma=outline_sigma
)
Expand All @@ -75,6 +76,9 @@ def thresholded_local_minima_seeded_watershed(
stats = regionprops(labels, image)
intensities = [r.mean_intensity for r in stats]

# Normalise intensities based on the max
minimum_intensity = minimum_intensity * max(np.asarray(intensities))

# filter labels with low intensity
new_label_indices, _, _ = relabel_sequential(
(np.asarray(intensities) > minimum_intensity) * np.arange(1, labels.max() + 1)
Expand Down
3 changes: 2 additions & 1 deletion src/epitools/widgets/segmentation.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,13 @@ def create_segmentation_widget() -> magicgui.widgets.Container:

threshold_tooltip = "Cells with an average intensity below `threshold` are ignored."
threshold = magicgui.widgets.create_widget(
value=3.0,
value=0.01,
name="threshold",
label="threshold sigma",
widget_type="FloatSpinBox",
options={
"tooltip": threshold_tooltip,
"max": 1.0,
},
)

Expand Down
2 changes: 1 addition & 1 deletion tests/test_segmentation.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

SPOT_SIGMA = 4.0
OUTLINE_SIGMA = 3.0
THRESHOLD = 3.0
THRESHOLD = 0.04


def test_add_segmentation_widget(
Expand Down

0 comments on commit 78b2623

Please sign in to comment.