Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

python PIL Image open isn't RGB

i've been trying to open a .jpg image using

im = Image.open('file.jpg').

my problem is that for some reason the "im" is not an RGB image, i.e the channels are not R,G,B. this also cause the im.convert('L') (rgb2gray) give a very bad result.

channel 0 image, attemped gray sacale.

Im using: Python 2.7.12 |Anaconda 4.1.1 (64-bit)

I would very much appreciate any help figuring this out.

edit: it seems the problem is that the matplotlib color map isn't set right. does anyone know why? and how to fix?

like image 241
Nadav Avatar asked Aug 23 '16 21:08

Nadav


People also ask

Is PIL image BGR or RGB?

The basic difference between OpenCV image and PIL image is OpenCV follows BGR color convention and PIL follows RGB color convention and the method of converting will be based on this difference.

How do I get RGB in Python?

getrgb() Convert a color string to an RGB tuple. If the string cannot be parsed, this function raises a ValueError exception. Another Example:– Here used different colors.


1 Answers

You can find current mode in im.mode and do convert with im.convert('RGB').

like image 178
homm Avatar answered Feb 13 '23 05:02

homm