>>> im = im.convert(‘RGB’, rgb2yiq)
Traceback (most recent call last):
File “<stdin>”, line 1, in <module>
File “/usr/lib/python2.7/dist-packages/PIL/Image.py“, line 685, in convert
im = self.im.convert_matrix(mode, data)
ValueError: image has wrong mode
Now, when can you actually compare the images by using the function
First, both images have to have pixels that can be stored in an unsigned byte.
This is a very common type of image, but this excludes comparison between images even if they are the same mode. So, you cannot compare an image
y when one or /both/ of them have a mode of:
BGR;32. Just to make it clear: it doesn’t matter if both images are in the same mode if they happen to be in one of the modes above, the function will refuse to work.
So, the comparison can be done when the images are in the modes
YCbCr as long as they have the same number of bands. This means the images don’t have to have the same mode to be compared. For instance,
difference(x.convert('CMYK'), x.convert('RGBA')) or
difference(x.convert('1'), x.convert('P')) work just fine. Of course this means
difference(x.convert('LA'), x.convert('L')), fails. Finally, the resulting image will always have the mode equal to the first image passed to the function.
This is valid at least for the PIL 1.1.7.
16-bit BGR is listed as
"BGR;16" and creates a
image_file = image_file.convert('1') # convert image to black and white
>>> import Image
>>> im = Image.open(path)
- RGBA stands for R ed G reen B lue A lpha, incorporates the alpha value into the actual colour result based on an opaque background colour (or ‘matte’ as it’s referred to).
Assuming that 0 is opaque and 255 is transparent, then 255,255,255,127 RGBA with a black matte will result in 127,127,127 RGB value.
PNG is an image format that uses RGBA.