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
bcf9831d
Commit
bcf9831d
authored
1 year ago
by
fima
Browse files
Options
Downloads
Plain Diff
Merge branch 'k3d' into 'main'
K3d See merge request
!54
parents
3ed9de45
b99816cf
No related branches found
No related tags found
1 merge request
!54
K3d
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
qim3d/utils/cli.py
+28
-1
28 additions, 1 deletion
qim3d/utils/cli.py
qim3d/viz/__init__.py
+1
-0
1 addition, 0 deletions
qim3d/viz/__init__.py
qim3d/viz/k3d.py
+47
-0
47 additions, 0 deletions
qim3d/viz/k3d.py
with
76 additions
and
1 deletion
qim3d/utils/cli.py
+
28
−
1
View file @
bcf9831d
import
argparse
import
argparse
import
qim3d
import
webbrowser
from
qim3d.gui
import
data_explorer
,
iso3d
,
annotation_tool
,
local_thickness
from
qim3d.gui
import
data_explorer
,
iso3d
,
annotation_tool
,
local_thickness
def
main
():
def
main
():
parser
=
argparse
.
ArgumentParser
(
description
=
'
Qim3d command-line interface.
'
)
parser
=
argparse
.
ArgumentParser
(
description
=
'
Qim3d command-line interface.
'
)
subparsers
=
parser
.
add_subparsers
(
title
=
'
Subcommands
'
,
dest
=
'
subcommand
'
)
subparsers
=
parser
.
add_subparsers
(
title
=
'
Subcommands
'
,
dest
=
'
subcommand
'
)
#
subcommand
s
#
GUI
s
gui_parser
=
subparsers
.
add_parser
(
'
gui
'
,
help
=
'
Graphical User Interfaces.
'
)
gui_parser
=
subparsers
.
add_parser
(
'
gui
'
,
help
=
'
Graphical User Interfaces.
'
)
gui_parser
.
add_argument
(
'
--data-explorer
'
,
action
=
'
store_true
'
,
help
=
'
Run data explorer.
'
)
gui_parser
.
add_argument
(
'
--data-explorer
'
,
action
=
'
store_true
'
,
help
=
'
Run data explorer.
'
)
...
@@ -15,6 +17,11 @@ def main():
...
@@ -15,6 +17,11 @@ def main():
gui_parser
.
add_argument
(
'
--host
'
,
default
=
'
0.0.0.0
'
,
help
=
'
Desired host.
'
)
gui_parser
.
add_argument
(
'
--host
'
,
default
=
'
0.0.0.0
'
,
help
=
'
Desired host.
'
)
gui_parser
.
add_argument
(
'
--platform
'
,
action
=
'
store_true
'
,
help
=
'
Use QIM platform address
'
)
gui_parser
.
add_argument
(
'
--platform
'
,
action
=
'
store_true
'
,
help
=
'
Use QIM platform address
'
)
# K3D
viz_parser
=
subparsers
.
add_parser
(
'
viz
'
,
help
=
'
Volumetric visualization.
'
)
viz_parser
.
add_argument
(
'
--source
'
,
default
=
False
,
help
=
'
Path to the image file
'
)
viz_parser
.
add_argument
(
'
--destination
'
,
default
=
'
k3d.html
'
,
help
=
'
Path to save html file.
'
)
viz_parser
.
add_argument
(
'
--no-browser
'
,
action
=
'
store_true
'
,
help
=
'
Do not launch browser.
'
)
args
=
parser
.
parse_args
()
args
=
parser
.
parse_args
()
...
@@ -47,5 +54,25 @@ def main():
...
@@ -47,5 +54,25 @@ def main():
else
:
else
:
interface
=
local_thickness
.
Interface
()
interface
=
local_thickness
.
Interface
()
interface
.
launch
()
interface
.
launch
()
if
args
.
subcommand
==
"
viz
"
:
if
not
args
.
source
:
print
(
"
Please specify a source file using the argument --source
"
)
return
# Load the data
print
(
f
"
Loading data from
{
args
.
source
}
"
)
volume
=
qim3d
.
io
.
load
(
str
(
args
.
source
))
print
(
f
"
Done, volume shape:
{
volume
.
shape
}
"
)
# Make k3d plot
print
(
"
\n
Generating k3d plot...
"
)
qim3d
.
viz
.
vol
(
volume
,
show
=
False
,
save
=
str
(
args
.
destination
))
print
(
f
"
Done, plot available at <
{
args
.
destination
}
>
"
)
if
not
args
.
no_browser
:
print
(
"
Opening in default browser...
"
)
webbrowser
.
open_new_tab
(
args
.
destination
)
if
__name__
==
'
__main__
'
:
if
__name__
==
'
__main__
'
:
main
()
main
()
\ No newline at end of file
This diff is collapsed.
Click to expand it.
qim3d/viz/__init__.py
+
1
−
0
View file @
bcf9831d
from
.visualizations
import
plot_metrics
from
.visualizations
import
plot_metrics
from
.img
import
grid_pred
,
grid_overview
,
slices
from
.img
import
grid_pred
,
grid_overview
,
slices
from
.k3d
import
vol
This diff is collapsed.
Click to expand it.
qim3d/viz/k3d.py
0 → 100644
+
47
−
0
View file @
bcf9831d
"""
Volumetric visualization using K3D
"""
import
k3d
import
numpy
as
np
def
vol
(
img
,
show
=
True
,
save
=
False
):
"""
Volumetric visualization of a given volume.
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.
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.
Returns:
k3d.plot: If show is False, returns the K3D plot object.
Examples:
```python
import qim3d
vol = qim3d.examples.fly_150x256x256
# shows the volume inline
qim3d.viz.vol(vol)
# 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
()
plot
+=
plt_volume
if
save
:
# Save html to disk
with
open
(
str
(
save
),
'
w
'
,
encoding
=
"
utf-8
"
)
as
fp
:
fp
.
write
(
plot
.
get_snapshot
())
if
show
:
plot
.
display
()
else
:
return
plot
\ 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