Skip to content

Commit da850b0

Browse files
committed
Fix overlay
1 parent c954e6c commit da850b0

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

superannotate/db/images.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -471,6 +471,7 @@ def download_image(
471471
local_dir_path=".",
472472
include_annotations=False,
473473
include_fuse=False,
474+
include_overlay=False,
474475
variant='original'
475476
):
476477
"""Downloads the image (and annotation if not None) to local_dir_path
@@ -515,10 +516,12 @@ def download_image(
515516
annotations_filepaths = download_image_annotations(
516517
project, image_name, local_dir_path
517518
)
518-
if include_fuse:
519+
if include_fuse or include_overlay:
519520
classes = search_annotation_classes(project, return_metadata=True)
520521
project_type = project_type_int_to_str(project["type"])
521-
fuse_path = create_fuse_image(filepath, classes, project_type)
522+
fuse_path = create_fuse_image(
523+
filepath, classes, project_type, output_overlay=include_overlay
524+
)
522525
logger.info("Downloaded image %s to %s.", image_name, filepath)
523526

524527
return (str(filepath), annotations_filepaths, fuse_path)
@@ -1034,7 +1037,6 @@ def create_fuse_image(
10341037
)
10351038
new_array_ovl = np.array(fi_pil_ovl)
10361039
new_array_ovl[:, :, :-1] += temp_ovl
1037-
new_array_ovl[:, :, 3] += temp_mask
10381040
fi_pil_ovl = Image.fromarray(new_array_ovl)
10391041
draw_ovl = ImageDraw.Draw(fi_pil_ovl)
10401042
cv2.ellipse(
@@ -1105,7 +1107,7 @@ def create_fuse_image(
11051107
fi_pil.save(fuse_path)
11061108
if output_overlay:
11071109
overlay_path = str(image) + "___overlay.jpg"
1108-
fi_pil_ovl.save(overlay_path)
1110+
fi_pil_ovl.convert("RGB").save(overlay_path, subsampling=0, quality=100)
11091111
return (fuse_path, overlay_path)
11101112
else:
1111-
return (fuse_path)
1113+
return (fuse_path, )

tests/test_fuse_gen.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,12 +71,13 @@ def test_fuse_image_create_vector(tmpdir):
7171
"example_image_1.jpg",
7272
tmpdir,
7373
include_annotations=True,
74-
include_fuse=True
74+
include_fuse=True,
75+
include_overlay=True
7576
)
7677
im1 = Image.open(tmpdir / "export" / "example_image_1.jpg___fuse.png")
7778
im1_array = np.array(im1)
7879

79-
im2 = Image.open(paths[2])
80+
im2 = Image.open(paths[2][0])
8081
im2_array = np.array(im2)
8182

8283
assert im1_array.shape == im2_array.shape
@@ -123,10 +124,11 @@ def test_fuse_image_create_pixel(tmpdir):
123124
include_annotations=True,
124125
include_fuse=True
125126
)
127+
print(paths, paths[2])
126128
im1 = Image.open(tmpdir / "export" / "example_image_1.jpg___fuse.png")
127129
im1_array = np.array(im1)
128130

129-
im2 = Image.open(paths[2])
131+
im2 = Image.open(paths[2][0])
130132
im2_array = np.array(im2)
131133

132134
assert im1_array.shape == im2_array.shape

0 commit comments

Comments
 (0)