NumPy Folks, I want to load images with PIL and then operate on them with NumPy. According to the PIL and NumPy documentation, I would expect the following to work, but it is not. Python 2.7.4 (default, Apr 19 2013, 18:28:01) [GCC 4.7.3] on linux2 Type "help", "copyright", "credits" or "license" for more information.
import numpy numpy.version.version
import Image Image.VERSION '1.1.7'
im = Image.open('big-0.png') im.size (2550, 3300)
ar = numpy.asarray(im) ar.size 1 ar.shape () ar array(<PIL.PngImagePlugin.PngImageFile image mode=LA size=2550x3300 at 0x1E5BA70>, dtype=object)
By "not working" I mean that I would have expected the data to be loaded/available in ar. PIL and NumPy/SciPy seem to be working fine independently of each other. Any guidance? Brady
NumPy Folks, Sorry for the self-reply, but I have determined that this may have something to do with an alpha channel being present. When I remove the alpha channel, things appear to work as I expect. Any discussion on the matter? Brady On Fri, Jul 12, 2013 at 10:00 PM, Brady McCary <brady.mccary@gmail.com> wrote:
NumPy Folks,
I want to load images with PIL and then operate on them with NumPy. According to the PIL and NumPy documentation, I would expect the following to work, but it is not.
Python 2.7.4 (default, Apr 19 2013, 18:28:01) [GCC 4.7.3] on linux2 Type "help", "copyright", "credits" or "license" for more information.
import numpy numpy.version.version
import Image Image.VERSION '1.1.7'
im = Image.open('big-0.png') im.size (2550, 3300)
ar = numpy.asarray(im) ar.size 1 ar.shape () ar array(<PIL.PngImagePlugin.PngImageFile image mode=LA size=2550x3300 at 0x1E5BA70>, dtype=object)
By "not working" I mean that I would have expected the data to be loaded/available in ar. PIL and NumPy/SciPy seem to be working fine independently of each other. Any guidance?
Brady
On Jul 12, 2013, at 8:51 PM, Brady McCary <brady.mccary@gmail.com> wrote:
something to do with an alpha channel being present.
I'd check and see how PIL is storing the alpha channel. If it's RGBA, then I'd expect it to work. But I'd PIL is storing the alpha channel as a separate band, then I'm not surprised you have an issue. Can you either drop the alpha or convert to RGBA? There is also a package called something line "imageArray" that loads and saves image formats directly to/from numpy arrays-maybe that would be helpful. CHB
When I remove the alpha channel, things appear to work as I expect. Any discussion on the matter?
Brady
On Fri, Jul 12, 2013 at 10:00 PM, Brady McCary <brady.mccary@gmail.com> wrote:
NumPy Folks,
I want to load images with PIL and then operate on them with NumPy. According to the PIL and NumPy documentation, I would expect the following to work, but it is not.
Python 2.7.4 (default, Apr 19 2013, 18:28:01) [GCC 4.7.3] on linux2 Type "help", "copyright", "credits" or "license" for more information.
import numpy numpy.version.version
import Image Image.VERSION '1.1.7'
im = Image.open('big-0.png') im.size (2550, 3300)
ar = numpy.asarray(im) ar.size 1 ar.shape () ar array(<PIL.PngImagePlugin.PngImageFile image mode=LA size=2550x3300 at 0x1E5BA70>, dtype=object)
By "not working" I mean that I would have expected the data to be loaded/available in ar. PIL and NumPy/SciPy seem to be working fine independently of each other. Any guidance?
Brady
NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion
Dear Brady On Fri, 12 Jul 2013 22:00:08 -0500, Brady McCary wrote:
I want to load images with PIL and then operate on them with NumPy. According to the PIL and NumPy documentation, I would expect the following to work, but it is not.
Reading images as PIL is a little bit trickier than one would hope. You can find an example of how to do it (taken scikit-image) here: https://github.com/scikit-image/scikit-image/blob/master/skimage/io/_plugins... Stéfan
participants (3)
-
Brady McCary -
Chris Barker - NOAA Federal -
Stéfan van der Walt