Skip to content

Error: "conversion from RGB to LAB not supported" (CMYK image) #8357

@echo-lalia

Description

@echo-lalia

What did you do?

Tried converting a CMYK image to "LAB" mode.

What did you expect to happen?

I expected the conversion to work. (an image with "LAB" color mode returned)

What actually happened?

A ValueError was raised with the text "conversion from RGB to LAB not supported"

What are your OS, Python and Pillow versions?

  • OS: Windows 10
  • Python: 3.12.5
  • Pillow: 10.4.0
--------------------------------------------------------------------
Pillow 10.4.0
Python 3.12.5 (tags/v3.12.5:ff3bc82, Aug  6 2024, 20:45:27) [MSC v.1940 64 bit (AMD64)]
--------------------------------------------------------------------
Python executable is C:\...\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\python.exe
System Python files loaded from C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.12_3.12.1520.0_x64__qbz5n2kfra8p0
--------------------------------------------------------------------
Python Pillow modules loaded from C:\...\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\PIL
Binary Pillow modules loaded from C:\...\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\PIL
--------------------------------------------------------------------
--- PIL CORE support ok, compiled for 10.4.0
--- TKINTER support ok, loaded 8.6
--- FREETYPE2 support ok, loaded 2.13.2
--- LITTLECMS2 support ok, loaded 2.16
--- WEBP support ok, loaded 1.4.0
--- WEBP Transparency support ok
--- WEBPMUX support ok
--- WEBP Animation support ok
--- JPEG support ok, compiled for libjpeg-turbo 3.0.3
--- OPENJPEG (JPEG2000) support ok, loaded 2.5.2
--- ZLIB (PNG/ZIP) support ok, loaded 1.3.1
--- LIBTIFF support ok, loaded 4.6.0
*** RAQM (Bidirectional Text) support not installed
*** LIBIMAGEQUANT (Quantization method) support not installed
*** XCB (X protocol) support not installed
--------------------------------------------------------------------

Example:

from PIL import Image

img = Image.open("1.jpg")
print(f"{img.mode=}")
img.convert(mode='LAB')

Output:

img.mode='CMYK'
---------------------------------------------------------------------------
   [1145] try:
-> [1146]     im = self.im.convert(mode, dither)
   [1147] except ValueError:

ValueError: conversion from CMYK to LAB not supported

During handling of the above exception, another exception occurred:

ValueError                                Traceback (most recent call last)
Cell In[19], [line 5]
      [3] img = Image.open("f:\\Ethan\\Documents\\GitHub\\bigimagedata\\dummytiles\\1 - Copy.jpg")
      [4] print(f"{img.mode=}")
----> [5] img.convert(mode='LAB')

File ~\AppData\...\Python312\site-packages\PIL\Image.py:1154, in Image.convert(self, mode, matrix, dither, palette, colors)
   [1152]         raise
   [1153]     im = self.im.convert(modebase)
-> [1154]     im = im.convert(mode, dither)
   [1155] except KeyError as e:
   [1156]     msg = "illegal conversion"

ValueError: conversion from RGB to LAB not supported

It's worth noting that this code works without issue:

img.convert(mode="RGB").convert(mode='LAB')

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions