Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
model_server
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
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
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Christopher Randolph Rhodes
model_server
Commits
006a1e35
Commit
006a1e35
authored
1 year ago
by
Christopher Randolph Rhodes
Browse files
Options
Downloads
Patches
Plain Diff
Moved patch box annotation to annotators module
parent
5515df64
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
extensions/chaeo/annotators.py
+11
-1
11 additions, 1 deletion
extensions/chaeo/annotators.py
extensions/chaeo/products.py
+10
-5
10 additions, 5 deletions
extensions/chaeo/products.py
with
21 additions
and
6 deletions
extensions/chaeo/annotators.py
+
11
−
1
View file @
006a1e35
import
numpy
as
np
from
PIL
import
Image
,
ImageDraw
,
ImageFont
from
model_server.process
import
rescale
def
draw_boxes_on_2d_image
(
img
,
boxes
,
**
kwargs
):
pilimg
=
Image
.
fromarray
(
np
.
copy
(
img
))
# drawing modifies array in-place
draw
=
ImageDraw
.
Draw
(
pilimg
)
...
...
@@ -41,4 +43,12 @@ def draw_boxes_on_3d_image(img, boxes, draw_full_depth=False, **kwargs):
assert
clip
>=
0.0
and
clip
<=
1.0
annotated
=
rescale
(
annotated
,
clip
=
clip
)
return
annotated
\ No newline at end of file
return
annotated
def
draw_box_on_patch
(
patch
,
bbox
,
linewidth
=
1
):
assert
len
(
patch
.
shape
)
==
2
((
x0
,
y0
),
(
x1
,
y1
))
=
bbox
pilimg
=
Image
.
fromarray
(
patch
)
# drawing modifies array in-place
draw
=
ImageDraw
.
Draw
(
pilimg
)
draw
.
rectangle
([(
x0
,
y0
),
(
x1
,
y1
)],
outline
=
'
white
'
,
width
=
linewidth
)
return
np
.
array
(
pilimg
)
\ No newline at end of file
This diff is collapsed.
Click to expand it.
extensions/chaeo/products.py
+
10
−
5
View file @
006a1e35
...
...
@@ -6,6 +6,7 @@ from PIL import Image, ImageDraw
from
skimage.io
import
imsave
from
tifffile
import
imwrite
from
extensions.chaeo.annotators
import
draw_box_on_patch
from
model_server.accessors
import
GenericImageDataAccessor
from
model_server.process
import
pad
,
rescale
,
resample_to_8bit
...
...
@@ -67,10 +68,14 @@ def export_patches_from_zstack(
y1
=
rbb
[
'
y1
'
]
for
zi
in
range
(
0
,
patch
.
shape
[
3
]):
pilimg
=
Image
.
fromarray
(
patch
[:,
:,
0
,
zi
])
# drawing modifies array in-place
draw
=
ImageDraw
.
Draw
(
pilimg
)
draw
.
rectangle
([(
x0
,
y0
),
(
x1
,
y1
)],
outline
=
'
white
'
,
width
=
kwargs
.
get
(
'
linewidth
'
,
1
))
patch
[:,
:,
0
,
zi
]
=
np
.
array
(
pilimg
)
# pilimg = Image.fromarray(patch[:, :, 0, zi]) # drawing modifies array in-place
# draw = ImageDraw.Draw(pilimg)
# draw.rectangle([(x0, y0), (x1, y1)], outline='white', width=kwargs.get('linewidth', 1))
# patch[:, :, 0, zi] = np.array(pilimg)
patch
[:,
:,
0
,
zi
]
=
draw_box_on_patch
(
patch
[:,
:,
0
,
zi
],
((
x0
,
y0
),
(
x1
,
y1
)),
)
if
pad_to
:
patch
=
pad
(
patch
,
pad_to
)
...
...
@@ -79,4 +84,4 @@ def export_patches_from_zstack(
fname
=
f
'
{
prefix
}
-la
{
obj
.
label
:
04
d
}
-zi
{
obj
.
zi
:
04
d
}
.
{
ext
}
'
success
=
_write_patch_to_file
(
where
,
fname
,
resample_to_8bit
(
patch
))
exported
.
append
(
fname
)
return
success
,
exported
\ No newline at end of file
return
success
,
exported
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