2

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.

Jason
  • 2,495
  • 4
  • 26
  • 37
  • a and b in L*a*b colorspace define the coordinates of a matrix, the value of which defines the color of that pixel. `imshow` assumes RGB input so when you provide non-zero values in only the one channel, `imshow` displays that as intensity only in the red channel. It doesn't automatically know you are giving it Lab colorspace values. If you want your image to appear grayscale with `imshow` either give it only a 2D matrix or have all three planes (`Lab(:,:,1:3)`) all equal the same 2D matrix. – Staus Dec 02 '14 at 00:27
  • Thanks. Essentially what I'm asking, however, is not this, but the following: if I have a grayscale image, what is its equivalent Lab-space representation? – Jason Dec 02 '14 at 04:27
  • You're doing it right. You want `a* = 0` and `b* = 0` for grayscale. @Staus has explained why `imshow` displays a red image. See [Wikipedia](http://en.wikipedia.org/wiki/Lab_color_space) for more information. – beaker Dec 02 '14 at 18:06

1 Answers1

0

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.

Myndex
  • 3,952
  • 1
  • 9
  • 24