Reputation: 607
How can one read large images as numpy.memmap
objects so it is possible to manipulate their pixels and save them back? Thanks in advance.
Upvotes: 4
Views: 1616
Reputation: 293
Without knowing further deatils, I would use scipy.misc.imread. Scipy uses Pillow, which in turn uses mmap:
>>> from scipy import misc
>>> pix_array = misc.imread('image_fname') # read only
>>> type(pix_array)
<type 'numpy.ndarray'>
>>> # manipulate pix_array to get `altered_pix_array`
>>> misc.imsave('altered_image_fname', altered_pix_array)
If scipy.misc.imread
does not work right out of the box, try pip install pillow
to install/reinstall Pillow properly. GL+HF
Upvotes: 1