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
52d01622
Commit
52d01622
authored
2 years ago
by
Tamino Huxohl
Browse files
Options
Downloads
Patches
Plain Diff
add functions to remove/add bed to remove_bed module
parent
3819bfae
Loading
Loading
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
mu_map/data/remove_bed.py
+42
-7
42 additions, 7 deletions
mu_map/data/remove_bed.py
with
42 additions
and
7 deletions
mu_map/data/remove_bed.py
+
42
−
7
View file @
52d01622
import
json
import
json
from
typing
import
Dict
,
List
from
typing
import
Dict
,
List
import
cv2
as
cv
import
numpy
as
np
import
numpy
as
np
from
mu_map.dataset.util
import
align_images
DEFAULT_BED_CONTOURS_FILENAME
=
"
bed_contours.json
"
DEFAULT_BED_CONTOURS_FILENAME
=
"
bed_contours.json
"
...
@@ -29,25 +32,57 @@ def load_contours(filename: str, as_ndarry: bool = True) -> Dict[int, np.ndarray
...
@@ -29,25 +32,57 @@ def load_contours(filename: str, as_ndarry: bool = True) -> Dict[int, np.ndarray
return
dict
(
_map
)
return
dict
(
_map
)
def
scale_points
(
points
:
List
[
List
[
int
]],
scale
:
float
):
def
remove_bed
(
mu_map
:
np
.
ndarray
,
bed_contour
:
np
.
ndarray
):
for
i
in
range
(
len
(
points
)):
"""
for
j
in
range
(
len
(
points
[
i
])):
Remove the bed defined by a contour from all slices.
points
[
i
][
j
]
=
round
(
points
[
i
][
j
]
*
scale
)
def
remove_bed
(
mu_map
:
np
.
ndarray
,
contour
:
np
.
ndarray
):
:param mu_map: the mu_map from which the bed is removed.
:param bed_contour: the contour describing where the bed is found
:return: the mu_map with the bed removed
"""
_mu_map
=
mu_map
.
copy
()
_mu_map
=
mu_map
.
copy
()
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
)
return
_mu_map
return
_mu_map
def
add_bed
(
without_bed
:
np
.
ndarray
,
with_bed
:
np
.
ndarray
,
bed_contour
:
np
.
ndarray
):
"""
Add the bed to every slice of a mu_map.
:param without_bed: the mu_map without the bed
:param with_bed: the mu_map with the bed
:param bed_contour: the contour defining the location of the bed
:return: the mu_map with the bed added
"""
with_bed
,
without_bed
=
align_images
(
with_bed
,
without_bed
)
for
_slice
in
range
(
with_bed
.
shape
[
0
]):
with_bed_i
=
with_bed
[
_slice
]
without_bed_i
=
without_bed
[
_slice
]
cnt_img
=
np
.
zeros
(
without_bed_i
.
shape
,
dtype
=
np
.
uint8
)
cnt_img
=
cv
.
drawContours
(
cnt_img
,
[
bed_contour
],
-
1
,
255
,
-
1
)
without_bed
[
_slice
]
=
np
.
where
(
cnt_img
>
0
,
with_bed_i
,
without_bed_i
)
return
without_bed
if
__name__
==
"
__main__
"
:
if
__name__
==
"
__main__
"
:
def
scale_points
(
points
:
List
[
List
[
int
]],
scale
:
float
):
"""
Utility function to scale all points in a list of points.
"""
for
i
in
range
(
len
(
points
)):
for
j
in
range
(
len
(
points
[
i
])):
points
[
i
][
j
]
=
round
(
points
[
i
][
j
]
*
scale
)
import
argparse
import
argparse
from
enum
import
Enum
from
enum
import
Enum
import
os
import
os
import
cv2
as
cv
from
mu_map.data.prepare
import
headers
from
mu_map.data.prepare
import
headers
from
mu_map.dataset.default
import
MuMapDataset
from
mu_map.dataset.default
import
MuMapDataset
from
mu_map.util
import
to_grayscale
,
COLOR_BLACK
,
COLOR_WHITE
from
mu_map.util
import
to_grayscale
,
COLOR_BLACK
,
COLOR_WHITE
...
...
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