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
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
QIM
Tools
qim3d
Commits
0b8b4672
Commit
0b8b4672
authored
1 year ago
by
Christian Kento Rasmussen
Browse files
Options
Downloads
Patches
Plain Diff
added option to crop volume to cc
parent
30283388
Branches
Branches containing commit
No related tags found
1 merge request
!48
Implemented 3D connected components as wrapper class for scipy.ndimage.label
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
qim3d/utils/connected_components.py
+11
-3
11 additions, 3 deletions
qim3d/utils/connected_components.py
with
11 additions
and
3 deletions
qim3d/utils/connected_components.py
+
11
−
3
View file @
0b8b4672
...
...
@@ -35,23 +35,31 @@ class ConnectedComponents:
"""
return
self
.
_num_connected_components
def
get_connected_component
(
self
,
index
=
None
):
def
get_connected_component
(
self
,
index
=
None
,
crop
=
False
):
"""
Get the connected component with the given index, if index is None selects a random component.
Args:
index (int): The index of the connected component. If none selects a random component.
crop (bool): If True, the volume is cropped to the bounding box of the connected component.
Returns:
np.ndarray: The connected component as a binary mask.
"""
if
index
is
None
:
return
self
.
connected_components
==
np
.
random
.
randint
(
volume
=
self
.
connected_components
==
np
.
random
.
randint
(
1
,
self
.
num_connected_components
+
1
)
else
:
assert
1
<=
index
<=
self
.
num_connected_components
,
"
Index out of range.
"
return
self
.
connected_components
==
index
volume
=
self
.
connected_components
==
index
if
crop
:
# As we index get_bounding_box element 0 will be the bounding box for the connected component at index
bbox
=
self
.
get_bounding_box
(
index
)[
0
]
volume
=
volume
[
bbox
]
return
volume
def
get_bounding_box
(
self
,
index
=
None
):
"""
Get the bounding boxes of the connected components.
...
...
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