different results when openning an image into numpy array using cv2.imread (OpenCV) and PIL.Image.open (Pillow)

I am trying to open an image and turn it into a numpy array.

I have tried: 1) cv2.imread which gives you a numpy array directly 2) and PIL.Image.open then do a numpy.asarray to convert the image object.

Then i realise the resulting array from the same picture is different, please see the attached screenshots. cv2.imread PIL.Image.open

I would expect the color channel should always have the same sequence, no matter the package, but I do not seem to be able find any documentation for pillow reagarding this.

Or am I just being silly? Thanks in advance for any suggestion!!!

1 answer

  • answered 2017-08-12 11:43 SSteve

    I don't know anything about PIL but, contrary to just about every other system in the world, OpenCV stores images in BGR order, not RGB. That catches every OpenCV beginner by surprise and it looks like that's the case with your example.