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
f11ea6fb
Commit
f11ea6fb
authored
1 year ago
by
s184058
Committed by
fima
1 year ago
Browse files
Options
Downloads
Patches
Plain Diff
Added aspectmode kwarg and changed default mode of k3d.volume
parent
e14ba9f7
Branches
Branches containing commit
No related tags found
1 merge request
!61
Added aspectmode kwarg and changed default mode of k3d.volume
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
.gitignore
+1
-0
1 addition, 0 deletions
.gitignore
qim3d/viz/k3d.py
+36
-18
36 additions, 18 deletions
qim3d/viz/k3d.py
with
37 additions
and
18 deletions
.gitignore
+
1
−
0
View file @
f11ea6fb
...
...
@@ -17,6 +17,7 @@ build/
*.swo
*.pyc
*~
*.html
# Notebook checkpoints
.ipynb_checkpoints/
This diff is collapsed.
Click to expand it.
qim3d/viz/k3d.py
+
36
−
18
View file @
f11ea6fb
...
...
@@ -10,47 +10,65 @@ Volumetric visualization using K3D
import
k3d
import
numpy
as
np
def
vol
(
img
,
show
=
True
,
save
=
False
):
def
vol
(
img
,
aspectmode
=
"
data
"
,
show
=
True
,
save
=
False
,
grid_visible
=
False
,
**
kwargs
):
"""
V
olumetric visualization of a given volume
.
V
isualizes a 3D volume using volumetric rendering
.
Args:
img (numpy.ndarray): The input 3D image data. It should be a 3D numpy array.
show (bool, optional): If True, displays the visualization. Defaults to True.
aspectmode (str, optional): Determines the proportions of the scene
'
s axes.
If
"
data
"
, the axes are drawn in proportion with the axes
'
ranges.
If
"
cube
"
, the axes are drawn as a cube, regardless of the axes
'
ranges.
Defaults to
"
data
"
.
show (bool, optional): If True, displays the visualization inline. Defaults to True.
save (bool or str, optional): If True, saves the visualization as an HTML file.
If a string is provided, it
'
s interpreted as the file path where the HTML
file will be saved. Defaults to False.
grid_visible (bool, optional): If True, the grid is visible in the plot. Defaults to False.
**kwargs: Additional keyword arguments to be passed to the k3d.plot function.
Returns:
k3d.plot: If show is False, returns the K3D plot object.
Example:
Raises:
ValueError: If aspectmode is not
"
data
"
or
"
cube
"
.
Examples:
Display a volume inline:
```python
import qim3d
vol = qim3d.examples.bone_128x128x128
# shows the volume inline
qim3d.viz.vol(vol)
```
Example:
Save a plot to an HTML file:
```python
import qim3d
vol = qim3d.examples.bone_128x128x128
# saves html plot to disk
plot = qim3d.viz.vol(vol, show=False, save=
"
plot.html
"
)
```
"""
plt_volume
=
k3d
.
volume
(
img
.
astype
(
np
.
float32
))
plot
=
k3d
.
plot
()
if
aspectmode
.
lower
()
not
in
[
"
data
"
,
"
cube
"
]:
raise
ValueError
(
"
aspectmode should be either
'
data
'
or
'
cube
'"
)
plt_volume
=
k3d
.
volume
(
img
.
astype
(
np
.
float32
),
bounds
=
(
[
0
,
img
.
shape
[
0
],
0
,
img
.
shape
[
1
],
0
,
img
.
shape
[
2
]]
if
aspectmode
.
lower
()
==
"
data
"
else
None
),
)
plot
=
k3d
.
plot
(
grid_visible
=
grid_visible
,
**
kwargs
)
plot
+=
plt_volume
if
save
:
# Save html to disk
with
open
(
str
(
save
),
'
w
'
,
encoding
=
"
utf-8
"
)
as
fp
:
with
open
(
str
(
save
),
"
w
"
,
encoding
=
"
utf-8
"
)
as
fp
:
fp
.
write
(
plot
.
get_snapshot
())
if
show
:
...
...
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