I have a camera that takes high resolution images and stores them as large matrices. I am trying to construct an image from the data. (And it must be done in Python-32 bit.)
The data is saved in HDF5 and I am using h5py to access it, but I am unable to plot the data without a memory error because all of the methods that I know require all of the data to be dumped into the computer's memory. (I am only familiar with the usual matplotlib and scipy libraries.)
Also, I have the same issue when I try to generate images from the data, but I have been told that GDAL would be able to generate an image from the data in a previous question I asked (Constructing high resolution images in Python).
I have done some research (it seems that GDAL for python is not very well documented) and came across this question: Can you loop through pixels in an image without loading the whole image?. The answer provided gives a quick script that imports an image row-by-row. Is there a way to do the opposite of this and save the image row-by-row? Then I would not have to load all of the data into the memory to save an image.
Or is there a method to generate a image (preferably a PNG) from a HDF5 dataset that is too large to load into the memory?
Here is some example code I have been working with:
import tables
import Image
import matplotlib.pyplot as plt
import scipy.misc
data = numpy.random.random_integers(0, 262143, (10000, 10000))
fileName = "array1.h5"
h5f = tables.openFile(fileName, "w")
array = h5f.createArray(h5f.root, "array1", data)
h5f.close()
fileName = "array1.h5"
h5f = tables.openFile(fileName, "r")
array_read = h5f.root.array1
print array_read[:]
#Method 1
scipy.misc.imsave('Test_random.png', array_read[:])
#Method 2
plt.imshow(array_read[:])
plt.show()
#Method 3
plt.pcolormesh(array_read[:])
plt.show()
It generates a 10000x10000 matrix and saves it in an H5 file with h5py. I close the file and reopen it. Then I try to save an image or plot the data (I comment out two of the three methods to test each one).
If someone could provide some example code that would allow me to save this array stored in an H5 file to a PNG image, I would greatly appreciate it.