Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ValueError when using scale parameter with draw_mosaic #29

Open
pandaxtc opened this issue Mar 8, 2021 · 0 comments
Open

ValueError when using scale parameter with draw_mosaic #29

pandaxtc opened this issue Mar 8, 2021 · 0 comments

Comments

@pandaxtc
Copy link

pandaxtc commented Mar 8, 2021

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant