ValueError: could not broadcast input array from shape (157,102) into shape (157,102,3)
vincenthawke opened this issue · 3 comments
Hello. Your script forks for most images I tested it with, but with some albums I am running into the following error:
C:\collage\collage-generator>python collage_generator.py "L:\folder1" --output out.jpg --width 400 --height 850
Loading images...
Generating tree...
Building image...
Traceback (most recent call last):
File "C:\collage\collage-generator\collage_generator.py", line 178, in <module>
to_image(img, tree, 0, 0, args.height)
File "C:\collage\collage-generator\collage_generator.py", line 148, in to_image
to_image(img, node.left, x, y, math.floor(height * alpha/l_alpha))
File "C:\collage\collage-generator\collage_generator.py", line 146, in to_image
to_image(img, node.right, x + math.floor(width * l_alpha/alpha), y, height)
File "C:\collage\collage-generator\collage_generator.py", line 146, in to_image
to_image(img, node.right, x + math.floor(width * l_alpha/alpha), y, height)
File "C:\collage\collage-generator\collage_generator.py", line 149, in to_image
to_image(img, node.right, x, y + math.floor(height * alpha/l_alpha), math.floor(height * alpha/r_alpha))
File "C:\collage\collage-generator\collage_generator.py", line 138, in to_image
img[y:height+y, x:new_width+x] = res[:target_shape[0], :target_shape[1]]
ValueError: could not broadcast input array from shape (157,102) into shape (157,102,3)
I think it was caused when I used a lot of landscape images and then had only one in portrait mode.
Python version: 3.9.5
Thanks for looking into it.
Hi, I am currently on vacation, I could check out your problem at earliest in 2 weeks, sorry for that.
Hi @vincenthawke I am sorry for the late response. It looks like that error is due to your images only having a single channel (potentially grey images?).
No problem. I didn't have any grey images, but I did notice that once I removed 1 or 2 images that had totally different aspect ratio compared to the rest of the images (which were all same dimensions), that the problem went away. If that played any role, I don't know, could be a coincidence.