From b07caba79de94fa10417de66433c4eab87076214 Mon Sep 17 00:00:00 2001 From: "Marcus Str." Date: Wed, 18 Dec 2024 10:37:16 +0100 Subject: [PATCH] Made sure generated patches are not bigger than the ortho itself --- layergen.py | 5 +++++ photogen.py | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/layergen.py b/layergen.py index fc2db4e..5f6aa96 100644 --- a/layergen.py +++ b/layergen.py @@ -387,6 +387,11 @@ class mstr_layergen: pick = randrange(0, len(masks)) patchmask = Image.open(masks[pick]) patchmask = patchmask.rotate(randrange(0, 360), expand=True) + + # Make sure patch is within bounds + if patchmask.width > self._imgsize or patchmask.height > self._imgsize: + patchmask.resize((mstr_photores, mstr_photores), Image.Resampling.BILINEAR) + patchpix = patchmask.load() # Pick from possible tags and values for the patches numbers = list(range(1, 16)) diff --git a/photogen.py b/photogen.py index ce2decf..17b6b0f 100644 --- a/photogen.py +++ b/photogen.py @@ -126,6 +126,11 @@ class mstr_photogen: pick = randrange(0, len(masks)) patchmask = Image.open(masks[pick]) patchmask = patchmask.rotate(randrange(0, 360), expand=True) + + # Make sure patch is within bounds + if patchmask.width > self._tile.width or patchmask.height > self._tile.height: + patchmask.resize((mstr_photores, mstr_photores), Image.Resampling.BILINEAR) + patchpix = patchmask.load() # Pick from possible tags and values for the patches