I have a bunch of images, the vast majority of which are color (rgb) images. I need to apply some spatial features in the three different channels of their Lab color space. The conversion from RGB Color space to Lab color space is straightforward through rgb2gray
. However, this naturally fails when the image is grayscale (consists of one channel only, with the numerical representation being a double
, uint8
, anything really).
I am familiar with the fact that the "luminance" (L) channel of the Lab color space is essentially the grayscaled original RGB image. This question, however, is of a different nature; what I'm asking is: Given an image that is already grayscale, I trivially get the L channel in Lab color space. What should the a and b channels be? Should they be zero? The following example, using the pre-build "peppers" image, shows the visual effect of doing so:
I = imread('peppers.png');
figure; imshow(I, []);
Lab = rgb2gray(I);
Lab(:, :, 2) = 0;
Lab(:, :, 3) = 0;
figure; imshow(Lab, []);
If you run this code, you will note that the second imshow
outputs a reddish version of the first image, resembling an old dark room. I admit to not being knowledgeable about what the a and b color channels represent in order to understand how I should deal with them in grayscale images, and was looking for some assistance.
An XY Type of Question.
IN CIELAB, a* and b* at 0 means no chroma: i.e. it's greyscale.
BUT WAIT THERE'S MORE! If you're having problems it's because that's not the actual question you need answered:
Incorrect Assumptions
First off, no, The L* of
L*a*b*
is NOT Luminance, and it is not the same as luminance.Luminance (L or Y) is a linear measure of light.
L* (*Lstar) is perceptual lightness, it follows human perception (more or less, depending on a bazillion contextual things).
rgb2grey
rgb2grey does not convert to
L*a*b*
Also, unfortunately some of the MATLAB functions for colorspaces have errors in implementation.
If you want to convert an sRGB color/image/pixel to LAB, then you need to follow this flowchart:
sRGB -> linear RGB -> CIEXYZ -> CIELAB
If you only want the greyscale or lightness information, with no color you can:
sRGB -> linear RGB -> CIE Y (spectral weighting) -> L* (perceptual lightness)
I discuss this simple method of sRGB to L* in this post
And if you want to see more in depth details, I suggest Bruce Lindbloom.