Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert L*a*b* to grayscale in matlab

I have already converted an RGB image into La*b* colorspace, but I want to convert it into gray scale. I'm not sure whether I can use rgb2gray or not.

Any idea?

like image 818
Bow House Avatar asked Jan 15 '23 18:01

Bow House


2 Answers

The L channel of Lab colorspace is the grayscale part. Just use it as is. Using rgb2gray will not work as expected, since it expects that the three channels that you give to it as an input are from RGB colorspace.

like image 190
Andrey Rubshtein Avatar answered Jan 17 '23 08:01

Andrey Rubshtein


If you have an image in the CIELa*b* colorspace representation, you could just convert it back to RGB using Lab2RGB(can be found here) and then use the function rgb2gray to convert your image to grayscale.

Be aware that there is a difference in the grayscale image produced by rgb2gray and the Lchannel produced by RGB2Lab.

In Matlab, grayscale is simply achieved by

0.2989 * R + 0.5870 * G + 0.1140 * B 

where the Lis achieved via a way more complex manner (see source code), hence gives a different result.

So choose wisely according to your needs or requirements!

like image 24
e0571302 Avatar answered Jan 17 '23 07:01

e0571302