Mentions légales du service
Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
V
vt-python
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Terraform modules
Monitor
Service Desk
Analyze
Value stream analytics
Contributor analytics
Repository analytics
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
morpheme
vt-python
Commits
6121b5b6
Commit
6121b5b6
authored
5 years ago
by
MALANDAIN Gregoire
Browse files
Options
Downloads
Patches
Plain Diff
examples/image_visu.py: add conversion from 'XYZ' to 'ZYX' and conversely
parent
5506d55b
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
examples/image_visu.py
+47
-14
47 additions, 14 deletions
examples/image_visu.py
with
47 additions
and
14 deletions
examples/image_visu.py
+
47
−
14
View file @
6121b5b6
...
...
@@ -19,12 +19,12 @@ def plot_2D_array(arr, cmap='gray', order='ZYX', title=""):
"""
if
arr
.
flags
.
c_contiguous
is
True
or
order
is
'
ZYX
'
:
if
order
is
'
ZYX
'
:
import
matplotlib.pyplot
as
plt
plt
.
figure
()
plt
.
imshow
(
arr
,
cmap
=
cmap
)
ltitle
=
title
+
"
- ZYX-ordered
"
elif
arr
.
flags
.
f_contiguous
is
True
or
order
is
'
XYZ
'
:
elif
order
is
'
XYZ
'
:
import
matplotlib.pyplot
as
plt
plt
.
figure
()
plt
.
imshow
(
np
.
transpose
(
arr
),
cmap
=
cmap
)
...
...
@@ -60,7 +60,7 @@ def plot_3D_array_z_slice(arr, z_slice=None, cmap='gray', order='ZYX', title="")
if
arr
.
ndim
<=
1
:
print
(
"
not an image
"
)
elif
arr
.
ndim
==
2
:
plot_2D_array
(
arr
,
cmap
=
cmap
,
title
=
title
)
plot_2D_array
(
arr
,
cmap
=
cmap
,
order
=
order
,
title
=
title
)
elif
arr
.
ndim
==
3
:
if
order
is
'
ZYX
'
:
if
z_slice
is
None
:
...
...
@@ -107,10 +107,10 @@ def _plot_handmade_3D(order='XYZ'):
lorder
=
'
ZYX
'
print
(
"
2D array is C-contiguous:
"
,
arr_2d
.
flags
.
c_contiguous
)
print
(
"
3D array is C-contiguous:
"
,
arr_3d
.
flags
.
c_contiguous
)
print
(
"
Z-slice of 3D array is C-contiguous:
"
,
arr_3d
[:,
:,
1
].
flags
.
c_contiguous
)
print
(
"
Z-slice copy of 3D array is C-contiguous:
"
,
arr_3d
[:,
:,
1
].
copy
().
flags
.
c_contiguous
)
#
print("2D array is C-contiguous:", arr_2d.flags.c_contiguous)
#
print("3D array is C-contiguous:", arr_3d.flags.c_contiguous)
#
print("Z-slice of 3D array is C-contiguous:", arr_3d[:, :, 1].flags.c_contiguous)
#
print("Z-slice copy of 3D array is C-contiguous:", arr_3d[:, :, 1].copy().flags.c_contiguous)
print
(
"
- type q to quit
"
)
...
...
@@ -141,6 +141,12 @@ def _plot_example_data(img_name, order='ZYX'):
#
# ------------------------------------------------------------------------------
def
_print_array_information
(
arr
):
print
(
"
- Array shape is: {}
"
.
format
(
arr
.
shape
))
print
(
"
- Array strides is: {}
"
.
format
(
arr
.
strides
))
print
(
"
- Array flags are: {}
"
.
format
(
arr
.
flags
))
print
(
"
- Array data is: {}
"
.
format
(
arr
.
data
))
print
(
""
)
def
_build_array
(
x
,
y
,
z
=
1
,
dtype
=
np
.
ubyte
,
order
=
'
ZYX
'
):
a
=
None
...
...
@@ -174,22 +180,49 @@ def _build_array(x, y, z=1, dtype=np.ubyte, order='ZYX'):
def
_plot_build_array
(
x
,
y
,
z
=
1
,
dtype
=
np
.
ubyte
,
order
=
'
ZYX
'
):
arr
=
_build_array
(
x
=
x
,
y
=
y
,
z
=
z
,
dtype
=
dtype
,
order
=
order
)
print
(
"
Array shape is: {}
"
.
format
(
arr
.
shape
))
print
(
"
Array strides is: {}
"
.
format
(
arr
.
strides
))
print
(
"
Array flags are: {}
"
.
format
(
arr
.
flags
))
if
z
>
1
:
plot_3D_array_z_slice
(
arr
,
cmap
=
'
gray
'
,
order
=
order
)
else
:
plot_2D_array
(
arr
,
cmap
=
'
gray
'
,
order
=
order
)
def
_XYZ_ZYX_convert
(
arr
):
if
arr
.
ndim
<=
1
:
print
(
"
not an image
"
)
elif
arr
.
ndim
==
2
:
return
arr
.
transpose
([
1
,
0
])
elif
arr
.
ndim
==
3
:
return
arr
.
transpose
([
2
,
1
,
0
])
else
:
print
(
"
not an image
"
)
def
_test_plot_build_array
(
x
,
y
,
z
=
1
,
dtype
=
np
.
ubyte
):
print
(
"
1. build a
'
ZYX
'
-array
"
)
arr
=
_build_array
(
x
=
x
,
y
=
y
,
z
=
z
,
dtype
=
dtype
,
order
=
'
ZYX
'
)
_print_array_information
(
arr
)
plot_3D_array_z_slice
(
arr
,
cmap
=
'
gray
'
,
order
=
'
ZYX
'
)
print
(
"
2. convert it into a
'
XYZ
'
-array
"
)
brr
=
_XYZ_ZYX_convert
(
arr
)
_print_array_information
(
brr
)
plot_3D_array_z_slice
(
brr
,
cmap
=
'
gray
'
,
order
=
'
XYZ
'
)
print
(
"
3. back to a
'
ZYX
'
-array
"
)
crr
=
_XYZ_ZYX_convert
(
brr
)
_print_array_information
(
crr
)
plot_3D_array_z_slice
(
crr
,
cmap
=
'
gray
'
,
order
=
'
ZYX
'
)
# ------------------------------------------------------------------------------
# main
# ------------------------------------------------------------------------------
_plot_handmade_3D
()
_plot_handmade_3D
(
order
=
'
ZYX
'
)
_plot_example_data
(
'
p58-t0_INT_down_interp_2x.inr
'
)
# _plot_build_array(19, 9)
# _plot_build_array(19, 17)
_plot_build_array
(
19
,
17
,
13
)
_plot_build_array
(
19
,
17
,
13
,
order
=
'
XYZ
'
)
# _plot_build_array(19, 17, 13)
# _plot_build_array(19, 17, 13, order='XYZ')
_test_plot_build_array
(
9
,
7
,
5
)
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