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
a18ea21f
Commit
a18ea21f
authored
1 year ago
by
Christian Kento Rasmussen
Browse files
Options
Downloads
Patches
Plain Diff
Created skeleton for 3d connected components class
parent
09beb209
No related branches found
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/3d_connected_components.py
+66
-0
66 additions, 0 deletions
qim3d/utils/3d_connected_components.py
with
66 additions
and
0 deletions
qim3d/utils/3d_connected_components.py
+
66
−
0
View file @
a18ea21f
import
numpy
as
np
from
scipy.ndimage
import
label
class
ConnectedComponents
:
def
__init__
(
self
,
connected_components
,
num_connected_components
):
"""
Initializes a ConnectedComponents object.
Args:
connected_components (np.ndarray): The connected components.
num_connected_components (int): The number of connected components.
"""
self
.
_connected_components
=
connected_components
self
.
_num_connected_components
=
num_connected_components
@property
def
connected_components
(
self
):
"""
Get the connected components.
Returns:
np.ndarray: The connected components.
"""
return
self
.
_connected_components
@property
def
num_connected_components
(
self
):
"""
Get the number of connected components.
Returns:
int: The number of connected components.
"""
return
self
.
_num_connected_components
def
get_connected_component
(
self
,
index
=
None
):
"""
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.
Returns:
np.ndarray: The connected component as a binary mask.
"""
assert
1
<=
index
<=
self
.
_num_connected_components
,
"
Index out of range.
"
if
index
:
return
self
.
_connected_components
==
index
else
:
return
self
.
_connected_components
==
np
.
random
.
randint
(
1
,
self
.
_num_connected_components
+
1
)
def
get_3d_connected_components
(
image
,
connectivity
=
1
):
"""
Get the connected components of a 3D binary image.
Args:
image (np.ndarray): The 3D binary image.
connectivity (int, optional): The connectivity of the connected components. Defaults to 1.
Returns:
class: Returns class object of the connected components.
"""
connected_components
,
num_connected_components
=
label
(
image
,
connectivity
)
return
ConnectedComponents
(
connected_components
,
num_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