mirror of
https://github.com/invoke-ai/InvokeAI
synced 2024-08-30 20:32:17 +00:00
fix: bypass edge pixels which cannot transform to tile size
Still need to fix this somehow
This commit is contained in:
parent
32a6b758cd
commit
3c195d74a5
@ -6,7 +6,7 @@ from PIL import Image
|
|||||||
|
|
||||||
def infill_mosaic(
|
def infill_mosaic(
|
||||||
image: Image.Image,
|
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),
|
min_color: Tuple[int, int, int, int] = (0, 0, 0, 0),
|
||||||
max_color: Tuple[int, int, int, int] = (255, 255, 255, 0),
|
max_color: Tuple[int, int, int, int] = (255, 255, 255, 0),
|
||||||
) -> Image.Image:
|
) -> Image.Image:
|
||||||
@ -34,20 +34,24 @@ def infill_mosaic(
|
|||||||
tiles = []
|
tiles = []
|
||||||
for _ in range(256):
|
for _ in range(256):
|
||||||
color = non_transparent_pixels[np.random.randint(len(non_transparent_pixels))]
|
color = non_transparent_pixels[np.random.randint(len(non_transparent_pixels))]
|
||||||
|
|
||||||
tile = np.zeros((tile_height, tile_width, 3), dtype=np.uint8)
|
tile = np.zeros((tile_height, tile_width, 3), dtype=np.uint8)
|
||||||
tile[:, :] = color
|
tile[:, :] = color
|
||||||
tiles.append(tile)
|
tiles.append(tile)
|
||||||
|
|
||||||
# Fill the transparent area with tiles
|
# Fill the transparent area with tiles
|
||||||
filled_image = np.zeros((image.height, image.width, 3), dtype=np.uint8)
|
filled_image = np.zeros((image.height, image.width, 3), dtype=np.uint8)
|
||||||
|
|
||||||
for x in range(image.width):
|
for x in range(image.width):
|
||||||
for y in range(image.height):
|
for y in range(image.height):
|
||||||
tile = tiles[np.random.randint(len(tiles))]
|
tile = tiles[np.random.randint(len(tiles))]
|
||||||
filled_image[
|
try:
|
||||||
y - (y % tile_height) : y - (y % tile_height) + tile_height,
|
filled_image[
|
||||||
x - (x % tile_width) : x - (x % tile_width) + tile_width,
|
y - (y % tile_height) : y - (y % tile_height) + tile_height,
|
||||||
] = tile
|
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
|
filled_image = Image.fromarray(filled_image) # Convert the filled tiles image to PIL
|
||||||
image = Image.composite(
|
image = Image.composite(
|
||||||
|
Loading…
Reference in New Issue
Block a user