With my colour wheel image above I got the following minima/maxima for each channel: Lab.min() # L minįrom lor_objects import sRGBColor, LabColorįrom lor_conversions import convert_colorĬolor1_lab = convert_color(color1_rgb, LabColor) I am not 100% sure of the scaling, but I suspect the L channel is a float in range 0.100, and that a and b are also floats in range -128.+128, though I may be wrong! # Open image and make Numpy arrays 'rgb' and 'Lab' So you would expect the L channel to be much brighter where the image is green, and darkest where it is blue.Īlternatively, you can do it with the scikit-image module, maybe even more simply like this: import numpy as np RGBA stands for Red, Green, Blue and Alpha channel. To make the image background transparent, we need to change 'RGB' to 'RGBA' first. We can see that this is a file of data type, and the mode of this file is 'RGB'.
And the b channel should be negative/low where the image is blue and high/positive where it is yellow, so that looks pretty good to me! As regards the L channel, the RGB to greyscale formula is (off the top of my head) something like: L = 0.2*R + 0.7*G + 0.1*B < image modeRGBA size626x417 at 0x179240973C8> RGB.# Split into constituent channels so we can save 3 separate greyscalesīeing non-scientific for a moment, the a channel should be negative/low where the image is green and should be high/positive where the image is magenta so it looks correct. If you carry on and add the following lines to the end of the above code, you can split the Lab image into its constituent channels and save them each as greyscale images for checking. Lab = ImageCms.applyTransform(im, rgb2lab)Īnd Lab is now your image in Lab colourspace. Rgb2lab = ImageCms.buildTransformFromOpenProfiles(srgb_p, lab_p, "RGB", "LAB") Im = Image.open('colorwheel.png').convert('RGB') # Open image and discard alpha channel which makes wheel round rather than square You can do it with PIL/Pillow using the built-in Colour Management System and building a transform like this: #!/usr/local/bin/python3