I am trying to sample colors in MATLAB using the Color Thresholder App and then use the L * a * b output in OpenCV. But there seems to be a scale mismatch. The following are the L * a * b scales in MATLAB and OpenCV:
according to these two sources : Source 1; and Source 2
It seems like we need the following L * a * b ranges for 8 bit images in OpenCV :
0 <= L <= 255; 0 <= a <= 255; and 0 <= b <= 255
How do we convert from MATLAB to OpenCV L * a * b color scale for 8 - bit images ?
Matlab uses the International Color Consortium's specifications for color representation in their image processing toolbox. The specification for ICC profiles are nearly universally used for color specification and conversions.
ICC Lab specified that LAB is used for the profile conversion space in various resolutions. For 8 bits, unsigned 8 bit values are used. L* is mapped 0->0 and 100->255. For a* and b* the values are limited to between -128 and +127. Thus the actual encoding adds 128 to a* and b* to produce an unsigned values between 0 and 255.
Representation for these and other, larger bit sizes can be found on tables 12 and 13 in section 6.3.4.2 in the specification here:
http://color.org/specification/ICC1v43_2010-12.pdf
Most programs such as Photoshop, Tiff files, and such use the ICC formats. Additionally, Matlab's functions include various conversion functions such as lab2uint8(lab)
which can be used to convert flating point Lab values to their proper representation in fixed sizes such as unsigned 8 bit ints.