Open IgorPotoc opened 8 years ago
I'd guess you haven't got a colour image; matplotlib's probably applying a default colormap (probably jet if the image looks ridiculously colourful) to the Y values. Pick a different colormap (see the cmap
parameter under that link) like 'greys' and you should see something a bit more sane.
Yes, thank you, that was it. I apologize for asking you for some more help here but it's somehow connected (if you like, I can move it to another issue) ... I wanted to compress & decompress this image I captured but I needed uncompressed one to start with (that one is in PNG format). So I saved that numpy array lum_Y to image_Y.data (is this sensible?), like in Advanced Recipes, by adding under plt.show():
with open('image_Y.data', 'wb') as f:
lum_Y.tofile(f)
Then I wrote a separate code:
import zlib, sys
import numpy as np
import matplotlib.pyplot as plt
unencod = open('image_Y.data','rb').read() # open saved unencoded image
comprim = open('image_Y_comprim.data','wb') # open new image file
comprim.write(zlib.compress(unencod,9)) # and write compressed image to it
comprim.close()
comprim = open('image_Y_comprim.data','rb').read()
decomprim = zlib.decompress(comprim) # decompress image
decompr = open('image_Y_decomprim.data','wb') # open new image file
decompr.write(decomprim) # and write decompressed image to it
print('Size of uncompressed Y:', sys.getsizeof(unencod))
print('Size of compressed Y (9):', sys.getsizeof(comprim))
print('Size of decompressed Y (9):', sys.getsizeof(decomprim))
Y_dec = np.fromfile('image_Y_decomprim.data', dtype=np.uint8)
plt.imshow(Y_dec)
plt.show()
But that produced error:
File "/home/pi/Zlib_comp_image.py", line 17, in
TypeError: Invalid dimensions for image data
Can you suggest how to view the images stored in .data files (I used programs in Advanced Recipes that produced such files, also ...)? I tried with Gimp but I got unrecognizable images. I also tried with numpy.save and load, but as a beginner, I'm obviously doing mistakes that I'm not aware of. Compression and decompression worked (decompressed image is the same size as original and compressed one is smaller) but I would like to visualize decompressed image, too. Thank you.
Hello,
I used this program (from Advanced recipes with included matplotlib):
How come I got colour image? (I have picamera 1.12 ...)
file:///home/pi/figure_1.png