Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
M
mu-map
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Tamino Huxohl
mu-map
Commits
ac333689
Commit
ac333689
authored
2 years ago
by
Tamino Huxohl
Browse files
Options
Downloads
Patches
Plain Diff
update visualization of mu map dataset
parent
d3b2b7c8
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
mu_map/data/datasets.py
+43
-36
43 additions, 36 deletions
mu_map/data/datasets.py
with
43 additions
and
36 deletions
mu_map/data/datasets.py
+
43
−
36
View file @
ac333689
...
@@ -44,6 +44,7 @@ class MuMapDataset(Dataset):
...
@@ -44,6 +44,7 @@ class MuMapDataset(Dataset):
images_dir
:
str
=
"
images
"
,
images_dir
:
str
=
"
images
"
,
bed_contours_file
:
Optional
[
str
]
=
DEFAULT_BED_CONTOURS_FILENAME
,
bed_contours_file
:
Optional
[
str
]
=
DEFAULT_BED_CONTOURS_FILENAME
,
discard_mu_map_slices
:
bool
=
True
,
discard_mu_map_slices
:
bool
=
True
,
align
:
bool
=
True
,
):
):
super
().
__init__
()
super
().
__init__
()
...
@@ -63,6 +64,7 @@ class MuMapDataset(Dataset):
...
@@ -63,6 +64,7 @@ class MuMapDataset(Dataset):
self
.
table
[
"
id
"
]
=
self
.
table
[
"
id
"
].
apply
(
int
)
self
.
table
[
"
id
"
]
=
self
.
table
[
"
id
"
].
apply
(
int
)
self
.
discard_mu_map_slices
=
discard_mu_map_slices
self
.
discard_mu_map_slices
=
discard_mu_map_slices
self
.
align
=
align
def
__getitem__
(
self
,
index
:
int
):
def
__getitem__
(
self
,
index
:
int
):
row
=
self
.
table
.
iloc
[
index
]
row
=
self
.
table
.
iloc
[
index
]
...
@@ -81,7 +83,8 @@ class MuMapDataset(Dataset):
...
@@ -81,7 +83,8 @@ class MuMapDataset(Dataset):
for
i
in
range
(
mu_map
.
shape
[
0
]):
for
i
in
range
(
mu_map
.
shape
[
0
]):
mu_map
[
i
]
=
cv
.
drawContours
(
mu_map
[
i
],
[
bed_contour
],
-
1
,
0.0
,
-
1
)
mu_map
[
i
]
=
cv
.
drawContours
(
mu_map
[
i
],
[
bed_contour
],
-
1
,
0.0
,
-
1
)
recon
=
align_images
(
recon
,
mu_map
)
if
self
.
align
:
recon
=
align_images
(
recon
,
mu_map
)
return
recon
,
mu_map
return
recon
,
mu_map
...
@@ -92,61 +95,65 @@ class MuMapDataset(Dataset):
...
@@ -92,61 +95,65 @@ class MuMapDataset(Dataset):
__all__
=
[
MuMapDataset
.
__name__
]
__all__
=
[
MuMapDataset
.
__name__
]
if
__name__
==
"
__main__
"
:
if
__name__
==
"
__main__
"
:
dataset
=
MuMapDataset
(
"
data/tmp
"
)
import
argparse
import
cv2
as
cv
import
cv2
as
cv
from
mu_map.util
import
to_grayscale
,
COLOR_WHITE
wname
=
"
Images
"
parser
=
argparse
.
ArgumentParser
(
description
=
"
Visualize the images of a MuMapDataset
"
,
formatter_class
=
argparse
.
ArgumentDefaultsHelpFormatter
)
parser
.
add_argument
(
"
dataset_dir
"
,
type
=
str
,
help
=
"
the directory from which the dataset is loaded
"
)
parser
.
add_argument
(
"
--unaligned
"
,
action
=
"
store_true
"
,
help
=
"
do not perform center alignment of reconstruction an mu-map slices
"
)
args
=
parser
.
parse_args
()
dataset
=
MuMapDataset
(
args
.
dataset_dir
,
align
=
not
args
.
unaligned
)
wname
=
"
Dataset
"
cv
.
namedWindow
(
wname
,
cv
.
WINDOW_NORMAL
)
cv
.
namedWindow
(
wname
,
cv
.
WINDOW_NORMAL
)
cv
.
resizeWindow
(
wname
,
1
024
,
512
)
cv
.
resizeWindow
(
wname
,
1
600
,
900
)
space
=
np
.
full
((
1
28
,
10
),
239
,
np
.
uint8
)
space
=
np
.
full
((
1
024
,
10
),
239
,
np
.
uint8
)
def
to_grayscale
(
img
:
np
.
ndarray
,
min_val
=
None
,
max_val
=
None
):
timeout
=
100
if
min_val
is
None
:
min_val
=
img
.
min
()
if
max_val
is
None
:
def
to_display_image
(
image
,
_slice
):
max_val
=
img
.
max
()
_image
=
to_grayscale
(
image
[
_slice
],
min_val
=
image
.
min
(),
max_val
=
image
.
max
())
_image
=
cv
.
resize
(
_image
,
(
1024
,
1024
),
cv
.
INTER_AREA
)
_text
=
f
"
{
str
(
_slice
)
:
>
{
len
(
str
(
image
.
shape
[
0
]))
}}
/
{
str
(
image
.
shape
[
0
])
}
"
_image
=
cv
.
putText
(
_image
,
_text
,
(
0
,
30
),
cv
.
FONT_HERSHEY_SIMPLEX
,
1
,
COLOR_WHITE
,
3
)
return
_image
_img
=
(
img
-
min_val
)
/
(
max_val
-
min_val
)
def
combine_images
(
images
,
slices
):
_img
=
(
_img
*
255
).
astype
(
np
.
uint8
)
image_1
=
to_display_image
(
images
[
0
],
slices
[
0
])
return
_img
image_2
=
to_display_image
(
images
[
1
],
slices
[
1
])
space
=
np
.
full
((
image_1
.
shape
[
0
],
10
),
239
,
np
.
uint8
)
return
np
.
hstack
((
image_1
,
space
,
image_2
))
for
i
in
range
(
len
(
dataset
)):
for
i
in
range
(
len
(
dataset
)):
ir
=
0
ir
=
0
im
=
0
im
=
0
recon
,
mu_map
=
dataset
[
i
]
recon
,
mu_map
=
dataset
[
i
]
print
(
f
"
{
i
+
1
}
/
{
len
(
dataset
)
}
-
{
recon
.
shape
}
-
{
mu_map
.
shape
}
"
)
print
(
f
"
{
(
i
+
1
)
:
>
{
len
(
str
(
len
(
dataset
)))
}}
/
{
len
(
dataset
)
}
"
,
end
=
"
\r
"
)
to_show
=
np
.
hstack
(
cv
.
imshow
(
wname
,
combine_images
((
recon
,
mu_map
),
(
ir
,
im
)))
(
key
=
cv
.
waitKey
(
timeout
)
to_grayscale
(
recon
[
ir
],
min_val
=
recon
.
min
(),
max_val
=
recon
.
max
()),
space
,
to_grayscale
(
mu_map
[
im
],
min_val
=
mu_map
.
min
(),
max_val
=
mu_map
.
max
()),
)
)
cv
.
imshow
(
wname
,
to_show
)
key
=
cv
.
waitKey
(
100
)
while
True
:
while
True
:
ir
=
(
ir
+
1
)
%
recon
.
shape
[
0
]
ir
=
(
ir
+
1
)
%
recon
.
shape
[
0
]
im
=
(
im
+
1
)
%
mu_map
.
shape
[
0
]
im
=
(
im
+
1
)
%
mu_map
.
shape
[
0
]
to_show
=
np
.
hstack
(
cv
.
imshow
(
wname
,
combine_images
((
recon
,
mu_map
),
(
ir
,
im
)))
(
to_grayscale
(
recon
[
ir
],
min_val
=
recon
.
min
(),
max_val
=
recon
.
max
()),
space
,
to_grayscale
(
mu_map
[
im
],
min_val
=
mu_map
.
min
(),
max_val
=
mu_map
.
max
()
),
)
)
cv
.
imshow
(
wname
,
to_show
)
key
=
cv
.
waitKey
(
100
)
key
=
cv
.
waitKey
(
timeout
)
if
key
==
ord
(
"
n
"
):
if
key
==
ord
(
"
n
"
):
break
break
if
key
==
ord
(
"
q
"
):
el
if
key
==
ord
(
"
q
"
):
exit
(
0
)
exit
(
0
)
elif
key
==
ord
(
"
p
"
):
timeout
=
0
if
timeout
>
0
else
100
elif
key
==
83
:
# right arrow key
continue
elif
key
==
81
:
# left arrow key
ir
=
max
(
ir
-
2
,
0
)
im
=
max
(
im
-
2
,
0
)
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