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