Skip to content

Commit

Permalink
Fix cutline handling for cases with multiple resolutions
Browse files Browse the repository at this point in the history
  • Loading branch information
yellowcap committed Apr 27, 2023
1 parent a6e70d9 commit 093b9cb
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions rio_tiler/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -422,23 +422,28 @@ def create_from_list(cls, data: Sequence["ImageData"]) -> "ImageData":
"""
h, w = zip(*[(img.height, img.width) for img in data])

# Get cutline mask at highest resolution.
max_h, max_w = max(h), max(w)
cutline_mask = next(
img.cutline_mask
for img in data
if img.height == max_h and img.width == max_w
)

if len(set(h)) > 1 or len(set(w)) > 1:
warnings.warn(
"Cannot concatenate images with different size. Will resize using max width/heigh",
UserWarning,
)
max_h, max_w = max(h), max(w)
for img in data:
if img.height == max_h and img.width == max_w:
cutline_mask = img.cutline_mask
continue
arr = numpy.ma.MaskedArray(
resize_array(img.array.data, max_h, max_w),
mask=resize_array(img.array.mask * 1, max_h, max_w).astype("bool"),
mask=cutline_mask,
)
img.array = arr
else:
cutline_mask = data[0].cutline_mask

arr = numpy.ma.concatenate([img.array for img in data])

Expand Down

0 comments on commit 093b9cb

Please sign in to comment.