From 3c195d74a54e663a2d19c0d4ac037371e7ab93b7 Mon Sep 17 00:00:00 2001 From: blessedcoolant <54517381+blessedcoolant@users.noreply.github.com> Date: Wed, 20 Mar 2024 13:17:45 +0530 Subject: [PATCH] fix: bypass edge pixels which cannot transform to tile size Still need to fix this somehow --- .../backend/image_util/infill_methods/mosaic.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/invokeai/backend/image_util/infill_methods/mosaic.py b/invokeai/backend/image_util/infill_methods/mosaic.py index 3a29fc3a17..2715a100d2 100644 --- a/invokeai/backend/image_util/infill_methods/mosaic.py +++ b/invokeai/backend/image_util/infill_methods/mosaic.py @@ -6,7 +6,7 @@ from PIL import Image def infill_mosaic( image: Image.Image, - tile_shape: Tuple[int, int] = (64, 16), + tile_shape: Tuple[int, int] = (64, 64), min_color: Tuple[int, int, int, int] = (0, 0, 0, 0), max_color: Tuple[int, int, int, int] = (255, 255, 255, 0), ) -> Image.Image: @@ -34,20 +34,24 @@ def infill_mosaic( tiles = [] for _ in range(256): color = non_transparent_pixels[np.random.randint(len(non_transparent_pixels))] - tile = np.zeros((tile_height, tile_width, 3), dtype=np.uint8) tile[:, :] = color tiles.append(tile) # Fill the transparent area with tiles filled_image = np.zeros((image.height, image.width, 3), dtype=np.uint8) + for x in range(image.width): for y in range(image.height): tile = tiles[np.random.randint(len(tiles))] - filled_image[ - y - (y % tile_height) : y - (y % tile_height) + tile_height, - x - (x % tile_width) : x - (x % tile_width) + tile_width, - ] = tile + try: + filled_image[ + y - (y % tile_height) : y - (y % tile_height) + tile_height, + x - (x % tile_width) : x - (x % tile_width) + tile_width, + ] = tile + except ValueError: + # Need to handle edge cases - literally + pass filled_image = Image.fromarray(filled_image) # Convert the filled tiles image to PIL image = Image.composite(