Reputation: 415
I have a script for creating mazes and saving them as a .png files. Also I have another script for solving the created mazes. The script for solving mazes opens those .png files and converts them to array. Then it saves the solved maze as a .png file too.
maze = np.array(Image.open('maze.png'))
And it works perfectly. But when I edit the crated maze, the solving script creates a .png file that looks like diagonal lines of random colors.
img = Image.fromarray(maze, 'RGB')
img.save('solved.png')
But when I draw my own maze in Paint, the script works fine. Why is that?
Upvotes: 0
Views: 79
Reputation: 207465
Your PNG image is probably palettised as it has only two colours and that is economically saved with a palette (1 byte of index into palette per pixel instead of 3 bytes of RGB triplet per pixel).
Ensure it is RGB with:
maze = np.array(Image.open('maze.png').convert('RGB'))
Upvotes: 1