I am attempting to write a 3D numpy array to a png file (i.e. a color
image). But I get the following error:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "visual_cortex.py", line 118, in build_cortex
ret_v1_p.save_as_image('../data/ret_v1.png',ret_v1_n)
File "visual_cortex.py", line 86, in save_as_image
png.fromarray(image,'RGB').save(filename)
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/
lib/python2.7/site-packages/png.py", line 1232, in from_array
assert not threed
AssertionError
I then went and looked at the source code, and it looks like this
isn't implemented. Are there plans to finish this functionality?
It's actually really cool that you want this, and i guess it will be
implemented at some point, especially now that i know that at least
one person might use it. And as the cliché goes, patches welcome.
Using numpy.reshape to get a 2D array should be an easy workaround.
Which makes justifying the implementation a bit harder.
Cheers,
drj
If I were to use numpy.reshape, could I still get a color image? Wouldn't that make the image grayscale? In this case, the goal is color output.
Lewis
It's intended to work. So yes. For example, this code:
png.from_array([[1,0,0, 0,1,0, 0,0,1]],'RGB;1').save('foo.png')
produces a 3 by 1 colour image, not a 9 by 1 greyscale image.
the mode will force the file to be colour.
Cheers,
drj