Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion dexpv2/segmentation.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,10 @@ def reconstruction_by_dilation(


def fancy_otsu_threshold(
image: ArrayLike, remove_hist_mode: bool = False, min_foreground: float = 0.0
image: ArrayLike,
remove_hist_mode: bool = False,
min_foreground: float = 0.0,
max_foreground: float = 0.0,
Comment thread
dsundarraman marked this conversation as resolved.
Outdated
) -> float:
"""
Compute Otsu threshold with some additional features.
Expand All @@ -61,6 +64,8 @@ def fancy_otsu_threshold(
Removes histogram mode before computing otsu threshold, useful when background regions are being detected.
min_foreground : float, optional
Minimum threshold value, by default 0.0
max_foreground: float, optional
Maximum threshold value, by default max value of image

Returns
-------
Expand All @@ -86,6 +91,11 @@ def fancy_otsu_threshold(

hist, bin_centers = exposure.histogram(image, nbins)

# clip bins and histogram beyond max_foreground value
if max_foreground != 0.0:
hist = [hist[i] for i in range(len(hist)) if bins[i] < max_foreground]
bins = [bin for bin in bins if bin < max_foreground]
Comment thread
dsundarraman marked this conversation as resolved.
Outdated

# histogram disconsidering pixels we are sure are background
if remove_hist_mode:
remaining_background_idx = hist.argmax() + 1
Expand Down