[PYTHON] Convert color space from RGB to CIELAB with PIL (Pillow)

Mutual conversion between RGB and CIELAB is done using PIL.ImageCms instead of PIL.Image.convert.

from PIL import Image, ImageCms

im = Image.open(image_path)
if im.mode != "RGB":
  im = im.convert("RGB")

srgb_profile = ImageCms.createProfile("sRGB")
lab_profile  = ImageCms.createProfile("LAB")

rgb2lab_transform = ImageCms.buildTransformFromOpenProfiles(srgb_profile, lab_profile, "RGB", "LAB")
lab_im = ImageCms.applyTransform(im, rgb2lab_transform)

Recommended Posts

Convert color space from RGB to CIELAB with PIL (Pillow)
Convert PIL format images read from form with Django to base64 format
Convert from PDF to CSV with pdfplumber
Convert 202003 to 2020-03 with pandas
Convert Select query obtained from Postgre with Go to JSON
Convert images to sepia toning with PIL (Python Imaging Library)
Convert garbled scanned images to PDF with Pillow and PyPDF
Made it possible to convert PNG to JPG with Pillow of Python
Convert .ipynb to .html (with BatchFile)
Create folders from '01' to '12' with python
Convert list to DataFrame with python
Convert sentences to vectors with gensim
Convert from pdf to txt 2 [pyocr]
How to convert from .mgz to .nii.gz
Convert PDF to image with ImageMagick
Try to reproduce color film with Python
Convert memo at once with Python 2to3
How to easily convert format from Markdown
Output color characters to pretty with python
Convert character strings to features with RoBERTa
Convert Excel data to JSON with python
Convert Hiragana to Romaji with Python (Beta)
Convert from katakana to vowel kana [python]
Use PIL and Pillow with Cygwin Python
Script example to display BoundingBox with PIL
Convert FX 1-minute data to 5-minute data with Python
Convert PDF files to PNG files with GIMP
Convert array (struct) to json with golang
Convert HEIC files to PNG files with Python
Convert Chinese numerals to Arabic numerals with Python
Convert from Markdown to HTML in Python
Fastly replace image colors with PIL / Pillow
Sample to convert image to Wavelet with Python
Use PIL and Pillow with Cygwin Python
Fastly replace image colors with PIL / Pillow
PIL / Pillow cheat sheet
Center images with python-pptx
Image Processing with PIL
Convert color space from RGB to CIELAB with PIL (Pillow)
Convert images to sepia toning with PIL (Python Imaging Library)
Convert garbled scanned images to PDF with Pillow and PyPDF
The story of displaying images with OpenCV or PIL (only)