Skip to content

Commit

Permalink
Merge pull request #10 from amepproject/sym_cut_watershed
Browse files Browse the repository at this point in the history
The watershed algorithm can now detect bubbles as well.
  • Loading branch information
hechtprojects authored Apr 18, 2024
2 parents d61278e + 2188aa0 commit 41cf111
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions amep/continuum.py
Original file line number Diff line number Diff line change
Expand Up @@ -539,12 +539,15 @@ def identify_clusters(
The scale of the field. This is needed to improve the segmentation
done in the watershed algorithm. This keyword is ignored when using
`method='threshold'`. The default is 1.0.
Can also be set to negative value to make bubble detection
accesible.
pbc : bool, optional
Whether to use periodic boundary conditions. Default is True.
cutoff: float, optional
Caps the highest field values to the ratio of the data extent. Default
value 1.0 means no cut, 0.9 means the highest 10% of the field get cut
off. Needed for clusters with multiple local minima. Combats
value 1.0 means no cut, 0.9 means the highest and lowest 10%
of the field get cut off.
Needed for clusters with multiple local minima. Combats
oversegmentation. This keyword is ignored when using
`method='threshold'`. The default is 1.0.
threshold : float, optional
Expand Down Expand Up @@ -608,7 +611,8 @@ def identify_clusters(
minimum = np.min(dfield)
maximum = np.max(dfield)
upper_cut = maximum-(1-cutoff)*(maximum-minimum)
dfield_scaled = (np.clip(dfield, minimum, upper_cut) * scale).astype(int)
lower_cut = minimum+(1-cutoff)*(maximum-minimum)
dfield_scaled = (np.clip(dfield, lower_cut, upper_cut) * scale).astype(int)

# apply watershed
labels = watershed(-dfield_scaled, markers=None, mask=dfield_scaled)
Expand Down

0 comments on commit 41cf111

Please sign in to comment.