Made sure generated patches are not bigger than the ortho itself

This commit is contained in:
Marcus Str. 2024-12-18 10:37:16 +01:00
parent 5cc9819dba
commit b07caba79d
2 changed files with 10 additions and 0 deletions

View File

@ -387,6 +387,11 @@ class mstr_layergen:
pick = randrange(0, len(masks)) pick = randrange(0, len(masks))
patchmask = Image.open(masks[pick]) patchmask = Image.open(masks[pick])
patchmask = patchmask.rotate(randrange(0, 360), expand=True) 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() patchpix = patchmask.load()
# Pick from possible tags and values for the patches # Pick from possible tags and values for the patches
numbers = list(range(1, 16)) numbers = list(range(1, 16))

View File

@ -126,6 +126,11 @@ class mstr_photogen:
pick = randrange(0, len(masks)) pick = randrange(0, len(masks))
patchmask = Image.open(masks[pick]) patchmask = Image.open(masks[pick])
patchmask = patchmask.rotate(randrange(0, 360), expand=True) 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() patchpix = patchmask.load()
# Pick from possible tags and values for the patches # Pick from possible tags and values for the patches