Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
deepdraw
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
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
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
medai
software
deepdraw
Commits
e20fca15
Commit
e20fca15
authored
5 years ago
by
André Anjos
Browse files
Options
Downloads
Patches
Plain Diff
[data.utils;engine.predictor] Re-use package image overlaying technique
parent
4edb6d5b
No related branches found
No related tags found
1 merge request
!12
Streamlining
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
bob/ip/binseg/data/utils.py
+9
-3
9 additions, 3 deletions
bob/ip/binseg/data/utils.py
bob/ip/binseg/engine/predictor.py
+3
-6
3 additions, 6 deletions
bob/ip/binseg/engine/predictor.py
with
12 additions
and
9 deletions
bob/ip/binseg/data/utils.py
+
9
−
3
View file @
e20fca15
...
...
@@ -54,8 +54,8 @@ def overlayed_image(
An RGB PIL image that represents the original image for analysis
label : PIL.Image.Image
A PIL image in mode
"
1
"
that represents the labelled elements in
the
image. White pixels represent the labelled object. Black pixels
A PIL image in mode
"
1
"
or
"
L
"
that represents the labelled elements in
the
image. White pixels represent the labelled object. Black pixels
represent background.
mask : py:class:`PIL.Image.Image`, Optional
...
...
@@ -95,7 +95,13 @@ def overlayed_image(
# slight "label_color" tone on top, then composite with original image, not
# to loose brightness.
retval
=
PIL
.
Image
.
blend
(
img
,
label_colored
,
alpha
)
retval
=
PIL
.
Image
.
composite
(
img
,
retval
,
invert_mode1_image
(
label
))
if
label
.
mode
==
"
1
"
:
composite_mask
=
invert_mode1_image
(
label
)
elif
label
.
mode
==
"
L
"
:
composite_mask
=
PIL
.
ImageOps
.
invert
(
label
)
else
:
raise
TypeError
(
f
"
Label image mode
{
label
.
mode
}
!= (
'
1
'
,
'
L
'
)
"
)
retval
=
PIL
.
Image
.
composite
(
img
,
retval
,
composite_mask
)
# creates a representation of the mask negative with the right color
if
mask
is
not
None
:
...
...
This diff is collapsed.
Click to expand it.
bob/ip/binseg/engine/predictor.py
+
3
−
6
View file @
e20fca15
...
...
@@ -15,6 +15,7 @@ import torchvision.transforms.functional as VF
import
h5py
from
..utils.summary
import
summary
from
..data.utils
import
overlayed_image
import
logging
logger
=
logging
.
getLogger
(
__name__
)
...
...
@@ -34,7 +35,7 @@ def _save_hdf5(stem, prob, output_folder):
Monochrome Image with prediction maps
output_folder : str
path where to store
overlayed result
s
path where to store
prediction
s
"""
...
...
@@ -101,11 +102,7 @@ def _save_overlayed_png(stem, image, prob, output_folder):
image
=
VF
.
to_pil_image
(
image
)
prob
=
VF
.
to_pil_image
(
prob
.
cpu
())
# color and overlay
prob_green
=
PIL
.
ImageOps
.
colorize
(
prob
,
(
0
,
0
,
0
),
(
0
,
255
,
0
))
overlayed
=
PIL
.
Image
.
blend
(
image
,
prob_green
,
0.4
)
_save_image
(
stem
,
'
.png
'
,
overlayed
,
output_folder
)
_save_image
(
stem
,
'
.png
'
,
overlayed_image
(
image
,
prob
),
output_folder
)
def
run
(
model
,
data_loader
,
device
,
output_folder
,
overlayed_folder
):
...
...
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