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
a1af32a9
Commit
a1af32a9
authored
1 year ago
by
ofhkr
Committed by
fima
1 year ago
Browse files
Options
Downloads
Patches
Plain Diff
Implementation of slice_viz
parent
13e4e70a
No related branches found
No related tags found
1 merge request
!12
Implementation of slice_viz
Changes
3
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
docs/notebooks/Unet.ipynb
+46
-19
46 additions, 19 deletions
docs/notebooks/Unet.ipynb
qim3d/viz/__init__.py
+1
-1
1 addition, 1 deletion
qim3d/viz/__init__.py
qim3d/viz/img.py
+68
-1
68 additions, 1 deletion
qim3d/viz/img.py
with
115 additions
and
21 deletions
docs/notebooks/Unet.ipynb
+
46
−
19
View file @
a1af32a9
This diff is collapsed.
Click to expand it.
qim3d/viz/__init__.py
+
1
−
1
View file @
a1af32a9
from
.img
import
grid_pred
,
grid_overview
\ No newline at end of file
from
.img
import
grid_pred
,
grid_overview
,
slice_viz
\ No newline at end of file
This diff is collapsed.
Click to expand it.
qim3d/viz/img.py
+
68
−
1
View file @
a1af32a9
...
...
@@ -5,7 +5,7 @@ from matplotlib import cm
import
torch
import
numpy
as
np
from
qim3d.io.logger
import
log
from
qim3d.io.load
import
load
def
grid_overview
(
data
,
num_images
=
7
,
cmap_im
=
"
gray
"
,
cmap_segm
=
"
viridis
"
,
alpha
=
0.5
):
"""
Displays an overview grid of images, labels, and masks (if they exist).
...
...
@@ -192,4 +192,71 @@ def grid_pred(in_targ_preds, num_images=7, cmap_im="gray", cmap_segm="viridis",
fig
.
show
()
def
slice_viz
(
input
,
position
=
'
mid
'
,
cmap
=
"
viridis
"
,
axis
=
False
,
img_height
=
2
,
img_width
=
2
):
"""
Displays one or several slices from a 3d array.
Args:
input (str, numpy.ndarray): Path to the file or 3-dimensional array.
position (str, int, list, array, optional): One or several slicing levels.
cmap (str, optional): Specifies the color map for the image.
axis (bool, optional): Specifies whether the axes should be included.
Raises:
ValueError: If provided string for
'
position
'
argument is not valid (not upper, middle or bottom).
Usage:
image_path =
'
/my_image_path/my_image.tif
'
slice_viz(image_path)
"""
# Filepath input
if
isinstance
(
input
,
str
):
vol
=
load
(
input
)
# Function has its own ValueErrors
dim
=
vol
.
ndim
if
dim
==
3
:
pass
else
:
raise
ValueError
(
f
"
Given array is not a volume! Current dimension:
{
dim
}
"
)
# Numpy array input
elif
isinstance
(
input
,
np
.
ndarray
):
dim
=
input
.
ndim
if
dim
==
3
:
vol
=
input
else
:
raise
ValueError
(
f
"
Given array is not a volume! Current dimension:
{
dim
}
"
)
# Position is a string
if
isinstance
(
position
,
str
):
if
position
.
lower
()
in
[
'
mid
'
,
'
middle
'
]:
height
=
[
int
(
vol
.
shape
[
-
1
]
/
2
)]
elif
position
.
lower
()
in
[
'
top
'
,
'
upper
'
,
'
start
'
]:
height
=
[
0
]
elif
position
.
lower
()
in
[
'
bot
'
,
'
bottom
'
,
'
end
'
]:
height
=
[
vol
.
shape
[
-
1
]
-
1
]
else
:
raise
ValueError
(
'
Position not recognized. Choose an integer, list, array or
"
start
"
,
"
mid
"
,
"
end
"
.
'
)
# Position is an integer
elif
isinstance
(
position
,
int
):
height
=
[
position
]
# Position is a list or array of integers
elif
isinstance
(
position
,(
list
,
np
.
ndarray
)):
height
=
position
num_images
=
len
(
height
)
fig
=
plt
.
figure
(
figsize
=
(
img_width
*
num_images
,
img_height
),
constrained_layout
=
True
)
axs
=
fig
.
subplots
(
nrows
=
1
,
ncols
=
num_images
)
for
col
,
ax
in
enumerate
(
np
.
atleast_1d
(
axs
)):
ax
.
imshow
(
vol
[:,:,
height
[
col
]],
cmap
=
cmap
)
ax
.
set_title
(
f
'
Slice
{
height
[
col
]
}
'
,
fontsize
=
8
)
if
not
axis
:
ax
.
axis
(
'
off
'
)
fig
.
show
()
\ 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