Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
qim3d
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
QIM
Tools
qim3d
Commits
ecfd7c08
Commit
ecfd7c08
authored
1 year ago
by
Christian Kento Rasmussen
Browse files
Options
Downloads
Patches
Plain Diff
Add watershed segmentation algorithm
parent
7f812a6f
Branches
3d_watershed
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
qim3d/utils/watershed.py
+26
-0
26 additions, 0 deletions
qim3d/utils/watershed.py
with
26 additions
and
0 deletions
qim3d/utils/watershed.py
0 → 100644
+
26
−
0
View file @
ecfd7c08
import
matplotlib.pyplot
as
plt
import
numpy
as
np
import
torch
from
scipy
import
ndimage
as
ndi
from
skimage.feature
import
peak_local_max
from
skimage.segmentation
import
watershed
def
watershed_segment
(
volume
):
"""
Apply watershed algorithm to a 3D volume.
Args:
volume (np.array | torch.Tensor): A 3D volume.
Returns:
np.array: Segmented watershed Connected Components.
"""
volume
=
volume
>
1
distance
=
ndi
.
distance_transform_edt
(
volume
)
coords
=
peak_local_max
(
distance
,
footprint
=
np
.
ones
((
3
,)
*
volume
.
ndim
),
labels
=
volume
)
mask
=
np
.
zeros
(
distance
.
shape
,
dtype
=
bool
)
mask
[
tuple
(
coords
.
T
)]
=
True
markers
,
_
=
ndi
.
label
(
mask
)
labels
=
watershed
(
-
distance
,
markers
,
mask
=
volume
)
return
labels
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment