danielballan / photomosaic

Assemble thumbnail-sized images from a large collection into a tiling which, viewed at a distance, gives the impression of one large photo.
http://danielballan.github.io/photomosaic/docs/
BSD 3-Clause "New" or "Revised" License
57 stars 13 forks source link

ValueError when using scale parameter with draw_mosaic #29

Open pandaxtc opened 3 years ago

pandaxtc commented 3 years ago

When passing any scale parameter into draw_mosaic that isn't 1, a ValueError occurs:

Traceback (most recent call last):
  File ".\main.py", line 73, in <module>
    mos = pm.draw_mosaic(canvas, tiles, matches, resized_copy_cache=cache, scale=i)
  File "E:\projects\t.page\venv\lib\site-packages\photomosaic\photomosaic.py", line 494, in draw_mosaic
    image[tile] = sized_match_image
ValueError: could not broadcast input array from shape (8,16,3) into shape (8,0,3)

Here's the code snippet that produced this error, I borrowed most of it from the contents of basic_mosaic:

GRID_DIMS = (180, 120)
DEPTH = 1
SCALE = 2

image = imread('source2.jpg') # load target image
pool = pm.make_pool('tiles/*') # load tiles

# Size the image to be evenly divisible by the tiles.
image = img_as_float(image)
image = pm.rescale_commensurate(image, GRID_DIMS, DEPTH)

# Use perceptually uniform colorspace for all analysis.
converted_img = pm.perceptual(image)

# Partition the image into tiles and characterize each one's color.
tiles = pm.partition(converted_img, grid_dims=GRID_DIMS, depth=DEPTH)
tile_colors = [np.mean(converted_img[tile].reshape(-1, 3), 0)
                for tile in tqdm(tiles, desc='analyzing tiles')]

# Match a pool image to each tile.
match = pm.simple_matcher(pool)
matches = [match(tc) for tc in tqdm(tile_colors, desc='matching')]

# Draw the mosaic.
canvas = np.ones_like(image)  # white canvas same shape as input image

cache = {}
mos = pm.draw_mosaic(canvas, tiles, matches, resized_copy_cache=cache, scale=SCALE)

imsave("mosaic.png", mos)

I'm using photomosaic==0.3.1 and numpy==1.19.5.