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
aa3f3119
Commit
aa3f3119
authored
2 years ago
by
Tamino Huxohl
Browse files
Options
Downloads
Patches
Plain Diff
fix remove bed contours script
parent
37d8e021
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
mu_map/data/remove_bed.py
+24
-4
24 additions, 4 deletions
mu_map/data/remove_bed.py
with
24 additions
and
4 deletions
mu_map/data/remove_bed.py
+
24
−
4
View file @
aa3f3119
...
@@ -7,18 +7,22 @@ import numpy as np
...
@@ -7,18 +7,22 @@ import numpy as np
DEFAULT_BED_CONTOURS_FILENAME
=
"
bed_contours.json
"
DEFAULT_BED_CONTOURS_FILENAME
=
"
bed_contours.json
"
def
load_contours
(
filename
:
str
)
->
Dict
[
int
,
np
.
ndarray
]:
def
load_contours
(
filename
:
str
,
as_ndarry
:
bool
=
True
)
->
Dict
[
int
,
np
.
ndarray
]:
"""
"""
Load contours from a json file.
Load contours from a json file.
The structure of the file is a dict where the key is the id of the according
The structure of the file is a dict where the key is the id of the according
image and the value is a numpy array of the contour.
image and the value is a numpy array of the contour.
:param filename: filename of a json file containing contours
:param filename: filename of a json file containing contours
:param as_ndarry: directly parse contours as numpy arrays
:return: a dict mapping ids to contours
:return: a dict mapping ids to contours
"""
"""
with
open
(
filename
,
mode
=
"
r
"
)
as
f
:
with
open
(
filename
,
mode
=
"
r
"
)
as
f
:
contours
=
json
.
load
(
f
)
contours
=
json
.
load
(
f
)
if
not
as_ndarry
:
return
contours
_map
=
map
(
lambda
item
:
(
int
(
item
[
0
]),
np
.
array
(
item
[
1
]).
astype
(
int
)),
contours
.
items
())
_map
=
map
(
lambda
item
:
(
int
(
item
[
0
]),
np
.
array
(
item
[
1
]).
astype
(
int
)),
contours
.
items
())
return
dict
(
_map
)
return
dict
(
_map
)
...
@@ -65,7 +69,14 @@ if __name__ == "__main__":
...
@@ -65,7 +69,14 @@ if __name__ == "__main__":
dataset
=
MuMapDataset
(
args
.
dataset_dir
,
bed_contours_file
=
None
)
dataset
=
MuMapDataset
(
args
.
dataset_dir
,
bed_contours_file
=
None
)
# TODO: implement that existing contours are loaded so that labeling can be continued?
# TODO: implement that existing contours are loaded so that labeling can be continued?
bed_contours
=
{}
if
os
.
path
.
isfile
(
args
.
output_file
):
try
:
bed_contours
=
load_contours
(
args
.
output_file
,
as_ndarry
=
False
)
except
:
print
(
f
"
JSON file
{
args
.
output_file
}
is corrupted! Create a new one.
"
)
bed_contours
=
{}
else
:
bed_contours
=
{}
class
VisualMode
(
Enum
):
class
VisualMode
(
Enum
):
DRAW_CONTOURS
=
1
DRAW_CONTOURS
=
1
...
@@ -73,6 +84,12 @@ if __name__ == "__main__":
...
@@ -73,6 +84,12 @@ if __name__ == "__main__":
window_name
=
"
Bed Removal
"
window_name
=
"
Bed Removal
"
for
i
,
(
_
,
mu_map
)
in
enumerate
(
dataset
):
for
i
,
(
_
,
mu_map
)
in
enumerate
(
dataset
):
_id
=
str
(
int
(
dataset
.
table
.
loc
[
i
,
"
id
"
]))
if
_id
in
bed_contours
:
print
(
f
"
Skip
{
_id
}
because file already contains these contours
"
)
continue
print
(
f
"
Image
{
str
(
i
+
1
)
:
>
{
len
(
str
(
len
(
dataset
)))
}}
/
{
len
(
dataset
)
}
"
,
end
=
"
\r
"
)
print
(
f
"
Image
{
str
(
i
+
1
)
:
>
{
len
(
str
(
len
(
dataset
)))
}}
/
{
len
(
dataset
)
}
"
,
end
=
"
\r
"
)
# select the center slice for display (the bed location is constant over all slices)
# select the center slice for display (the bed location is constant over all slices)
mu_map
=
mu_map
[
mu_map
.
shape
[
0
]
//
2
]
mu_map
=
mu_map
[
mu_map
.
shape
[
0
]
//
2
]
...
@@ -124,6 +141,9 @@ if __name__ == "__main__":
...
@@ -124,6 +141,9 @@ if __name__ == "__main__":
cv
.
imshow
(
window_name
,
to_show
)
cv
.
imshow
(
window_name
,
to_show
)
key
=
cv
.
waitKey
(
100
)
key
=
cv
.
waitKey
(
100
)
if
key
==
ord
(
"
q
"
):
if
key
==
ord
(
"
q
"
):
# write current contours to output file
with
open
(
args
.
output_file
,
mode
=
"
w
"
)
as
f
:
f
.
write
(
json
.
dumps
(
bed_contours
,
indent
=
2
,
sort_keys
=
True
))
exit
(
0
)
exit
(
0
)
elif
key
==
ord
(
"
d
"
):
elif
key
==
ord
(
"
d
"
):
points
=
points
[:
-
1
]
points
=
points
[:
-
1
]
...
@@ -140,8 +160,8 @@ if __name__ == "__main__":
...
@@ -140,8 +160,8 @@ if __name__ == "__main__":
cv
.
destroyWindow
(
window_name
)
cv
.
destroyWindow
(
window_name
)
# save current contour in dict
# save current contour in dict
bed_contours
[
int
(
dataset
.
table
.
loc
[
i
,
"
id
"
])
]
=
points
bed_contours
[
_id
]
=
points
# write contours to output file
# write contours to output file
with
open
(
args
.
output_file
,
mode
=
"
w
"
)
as
f
:
with
open
(
args
.
output_file
,
mode
=
"
w
"
)
as
f
:
f
.
write
(
json
.
dumps
(
data
,
indent
=
2
,
sort_keys
=
True
))
f
.
write
(
json
.
dumps
(
bed_contours
,
indent
=
2
,
sort_keys
=
True
))
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