Re: Converting from "CMYK" to "RGB"

Hajime Nakagami <[email protected]> Fri, 5 Jul 2013 22:56:11 +0900
Newsgroups gmane.comp.python.image
Message-ID <CADgq5KAoPcVR-gdJB0jLHw7yaXi1G9T5Es-Hv0VuuWLH4GW7vg@mail.gmail.com>
--===============1638739305==
Content-Type: multipart/alternative; boundary=047d7b873a0aaf400d04e0c40e16

--047d7b873a0aaf400d04e0c40e16
Content-Type: text/plain; charset=ISO-8859-1

Hi Matti

> image.convert('RGB')
this code return converted image but abandoned

Please rewrite as below
> image = image.convert('RGB')



2013/7/1 Matti Viljamaa <[email protected]>

> I'm trying to handle CMYK images by converting them to RGB. I'm using the
> following code snippet:
>
> import sys
> from PIL import Image
>
> def loadImage(self, imageFileName):
>     imageFile = open(imageFileName)
>     image = Image.open(imageFile)
>
>     if(image.mode == 'CMYK' ):
>         image.convert('RGB')
>
> However the image is not converted to RGB, although its mode is recognized
> as CMYK.
>
> Later when loading this image into a QImage (of the Qt GUI library), the
> compiler produces an error indicating that the mode is still CMYK:
>     ValueError: unsupported image mode 'CMYK'
>
> So how can CMYK images be handled?
>
> My PIL is of version 1.1.6.
>
> _______________________________________________
> Image-SIG maillist  -  [email protected]
> http://mail.python.org/mailman/listinfo/image-sig
>

--047d7b873a0aaf400d04e0c40e16
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">Hi Matti<div><br></div><div>&gt;<span style=3D"border-coll=
apse:collapse;font-family:arial,sans-serif;font-size:14px">=A0image.convert=
(&#39;RGB&#39;)</span></div><div><font face=3D"arial, sans-serif"><span sty=
le=3D"border-collapse:collapse;font-size:14px">this code return converted i=
mage but abandoned</span></font></div>


<div><font face=3D"arial, sans-serif"><span style=3D"border-collapse:collap=
se;font-size:14px"><br></span></font></div><div><font face=3D"arial, sans-s=
erif"><span style=3D"border-collapse:collapse;font-size:14px">Please rewrit=
e as below</span></font></div>


<div><font face=3D"arial, sans-serif"><span style=3D"border-collapse:collap=
se;font-size:14px">&gt; image =3D image.convert(&#39;RGB&#39;)</span></font=
></div><div><span style=3D"border-collapse:collapse;font-family:arial,sans-=
serif;font-size:14px"><br>


</span></div></div><div class=3D"gmail_extra"><br><br><div class=3D"gmail_q=
uote">2013/7/1 Matti Viljamaa <span dir=3D"ltr">&lt;<a href=3D"mailto:mvilj=
[email protected]" target=3D"_blank">[email protected]</a>&gt;</span><br><bloc=
kquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1px #cc=
c solid;padding-left:1ex">
I&#39;m trying to handle CMYK images by converting them to RGB. I&#39;m usi=
ng the following code snippet:<br>
<br>
import sys<br>
from PIL import Image<br>
<br>
def loadImage(self, imageFileName):<br>
=A0 =A0 imageFile =3D open(imageFileName)<br>
=A0 =A0 image =3D Image.open(imageFile)<br>
<br>
=A0 =A0 if(image.mode =3D=3D &#39;CMYK&#39; ):<br>
=A0 =A0 =A0 =A0 image.convert(&#39;RGB&#39;)<br>
<br>
However the image is not converted to RGB, although its mode is recognized =
as CMYK.<br>
<br>
Later when loading this image into a QImage (of the Qt GUI library), the co=
mpiler produces an error indicating that the mode is still CMYK:<br>
=A0 =A0 ValueError: unsupported image mode &#39;CMYK&#39;<br>
<br>
So how can CMYK images be handled?<br>
<br>
My PIL is of version 1.1.6.<br>
<br>
_______________________________________________<br>
Image-SIG maillist =A0- =A0<a href=3D"mailto:[email protected]">Image-SI=
[email protected]</a><br>
<a href=3D"http://mail.python.org/mailman/listinfo/image-sig" target=3D"_bl=
ank">http://mail.python.org/mailman/listinfo/image-sig</a><br>
</blockquote></div><br></div>

--047d7b873a0aaf400d04e0c40e16--

--===============1638739305==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

_______________________________________________
Image-SIG maillist  -  [email protected]
http://mail.python.org/mailman/listinfo/image-sig

--===============1638739305==--