Mathematically right values in decomposing to LAB ?

Hi all,

I am a French PhD student currently struggling with colorimetry, and especially converting from RGB to Lab.

I need:
1°) to take a sRGB photo as close as possible to the real colors
2°) to decompose my sRGB photo in mathematically right values of L*, a* and b*
3°) to get the values of L*, a* and b* for every pixel (2 columns of data: the value of L* and the number of pixel corresponding to this value - the same for a* and b*)
With this values, I will then be able to make a statistical study of the distribution of the colors.

My current method is the following:

  • My lab owns a box with constant lighting in which I can put at once my product. A SLR Canon camera is placed on top of the box and takes a photograph through a hole. I take photos in sRGB color space, but could you please tell me if you think I should use Adobe RGB instead ?

  • Then, I upload the photos of my computer, and convert them from CR2 (RAW format of Canon) to Tiff with the software XnConvert. I am not sure that the ICC profile given to the photo by XnConvert is sRGB and that the gamma correction is applied. Could you please advise me another free software that does well the conversion ?

  • Then, I use the plugin of ImageJ 2.0 “Conversions between RGB color space and Lab color space” (Plugins / Image / Color / Convert RGB image to Lab Stack v1.00)

  • Finally, Analyze / Histogram / Copy and then I paste the values in a spreadsheet which allows me to compute the mean, the standard deviation, etc…

I read on the website http://www.ericbrasseur.org/gamma.html that many softwares (including ImageJ 1.40) produce gamma error in picture scaling.

I am using ImageJ 2.0, do you know if in this version of ImageJ the gamma correction is applied ?

ImageJ 2.0 uses 16-bits and 32-bits, so no problem of posterization if I understand well.

I have a few more questions:

  • The LAB given by GIMP 2.10 is supposed to be Hunter Lab color space or CIE Lab* (1979) color space ?

  • I would like to use GIMP 2.10 to compare to the results I got with ImageJ 2.0. When I open a photo in GIMP 2.0, I am asked to convert the image to built-in sRGB or keep the current ICC. I guess I should convert to built-in sRGB, but what should I choose for the rendering intent (perceptual, relative colorimetric, saturation, or absolute colorimetric ?), and should I check or uncheck the black point compensation ? The informations I found on the web concerning the black point compensation only referred to printing and I don’t need to print.

  • Is it possible to obtain the different values of L a b of the pixels and / or the histograms with GIMP 2.10 ? Or should I do the conversion to LAB with GIMP 2.10, save the 3 images and then obtain the values with ImageJ (but what if ImageJ doesn’t apply the gamma correction)?

Thank you very much for reading up until this point,

And thanks to @Elle for bringing me to this forum,

Best regards,

Marion Gaff

1 Like

Salut, @MarionGaff and welcome :slight_smile:

Which operating system are you on (or rather your computer)?
Some Linux variety, Windows, or Mac?

Cordialement,
Claes en Lund, La Suède

Hi @Claes,

I have a MacBook Air OS X Yosemite (10.10.5)

In my lab I can also have access to Ubuntu or Windows, if needed, but I am less familiar.

Thank you very much,

Cordialement :wink:

Marion from Paris

“As close as possible to the real colors” means you want colorimetrically accurate raw rendering. So you are shooting raw files, in which case the color space of any jpegs that your camera might save is irrelevant.

This rather wordy and outdated article talks about settings for getting scene-referred colors from your camera: Raw Processor Review, Part 1

But rather than wade through the above article I’d suggest picking either darktable or PhotoFlow or RawTherapee (because these all can be plug-ins for GIMP-2.10) and asking people on this forum (the devs for all three programs are here, plus a lot of very experienced users) “how to get scene-referred as colorimetrically accurate as possible colors” during raw rendering.

I’ve never had to produce ultra-correct colors, so hopefully others will weigh in with practical considerations. You’ll probably want to shoot a middle gray target to set the white point to be the same for all your shots.

Regarding your set-up, I’d be curious about things like the color temperature of the light source and the light source color rendering index, if colorimetrically accurate colors is important, which of course it is. You might want to consider getting a target chart and making a custom camera profile just for your study.

Three free/libre raw processors are set up to work with GIMP as plug-ins: darktable, PhotoFlow, and RawTherapee. All three of these are capable of outputting “scene-referred” colorimetrically accurate renditions of your raw file, within the limits of the accuracy of the provided camera input profile, which is why shooting a custom target might be worth doing - opinions vary on this point and convincing arguments have been made pro and con. Hopefully someone can weigh in with thoughts on this matter.

All three above-listed raw processors can output 32-bit floating point tiffs. This is important especially when converting the interpolated raw file to sRGB - at integer precision channel values will be clipped for colors outside the very small sRGB color gamut. For example brightly colored flowers and fruit - those colors are just completely outside the sRGB color gamut. But for measuring LAB values, as long as the channel values aren’t clipped during raw processing and when exported to disk - at 32f neither GIMP-2.10 nor the three raw processors do any clipping - you still can get accurate LAB readouts even for very bright colors.

Regarding converting from the camera input profile to sRGB, I think all three of the above-listed softwares include the exact same version of sRGB as GIMP, darktable does, PhotoFlow does, and I think the latest version of RawTherapee also does. Many softwares use various slightly or even very different versions of sRGB, so be wary of this issue.

Use relative colorimetric intent to convert to sRGB. But it doesn’t matter as long as you are using the version of sRGB provided by GIMP and the three raw processors listed above, as sRGB is a matrix profile. Search on the pixls forum and you’ll find long discussions of this point :slight_smile: .

Answering a bunch of your questions about GIMP in a sort of scatter-shot way:

  • GIMP-2.10 does allow to color pick using any preset sample size (well, there’s an upper limit I think of 256 pixels per side), and does allow to read off LAB values.
  • GIMP-2.10 also does scale in a way that accounts for gamma artifacts.
  • GIMP conversions to LAB use Bruce Lindbloom’s XYZ to LAB equations (Welcome to Bruce Lindbloom's Web Site), which are for the 1976 CIELAB color space. GIMP conversions use LAB with the D50 white point because GIMP is an ICC profile color-managed editing application. So if you use GIMP and you need LAB values using some other white point, you’d need to do a chromatic adaptation.
  • GIMP-2.10 still has hard-coded sRGB values that mean that the color pickers only provide accurate LAB readouts for images in the sRGB color space. GIMP-2.99 can produce accurate readouts in any RGB working space, but GIMP-2.99 is not ready for “production” use.
  • Decomposing images to LAB using GIMP-2.10 produces slightly wrong results because of a TRC problem, unless you take care to assign a proper grayscale ICC profile to the decomposed image. There are a couple of outstanding bug reports on this issue.
  • The only way to see a LAB histogram with GIMP-2.10 is to decompose to LAB and figure out how to deal with the TRC problem.

You’ve probably already done a literature search, but Section C of this article has links to a small set of nice studies of LAB/LCH values for various natural colors (skin, grapes, flowers, etc), with occasional mention of how the colors were photographed and measured: LCh color palettes

@MarionGaff
Actually, the thread so far reminds me of a very old Swedish army joke, when the old staff sergeant told the recruits: You think this is easy, lads? Just you wait until I have explained it all.

Cordialement,
Claes in Lund, La Suède

PS: Yes, I do think that this is the right forum for you!

Without knowing your specific experiment, I can only say that it’s important to control your measurments to insure only the attributes in question are variable. To that end:

  1. Using the same camera for all your measurements is important. It has a specific spectral response, you don’t want to have to account for that.

  2. Using the raw image with as few transforms as possible may be a consideration. White balance, demosaic, any tone response curve, and even the conversion from the camera profile to sRGB or AdobeRGB, all change the original measurements of R, G, and B intensities and need to be identified. It also may be that you want some or all of these transforms, if so, it’s probably important to do the exact same ones to all your images.

  3. Converting from the camera profile to any working profile such as sRGB or AdobeRGB will change your statistical characterization of color. These conversions chop/compress/fiddle with the range of captured colors, depending on the selected rendering intent. If “accurate” color is important, it may be that you run your statistics on the raw data, maybe with just a white balance transform to mitigate the green bias. The working images won’t look good to you, but they’ll be as close to the spectral measurements made by the camera as practical.

As always, For What It’s Worth…

1 Like

@MarionGaff
Hello,

as far as I know, imageJ knows nothing about colour management. You have to apply the gamma-correction via the tab “process – math – macro”. Depending on the normalization desired, you might also want to use the gamma-correction under “process – math – gamma…”

For colour space transformation, have you looked into “color transformer 2”?

Hermann-Josef

@MarionGaff I just hit me: why do you convert-convert-convert-convert-convert-… to finally obtain Lab?

Why not simply stay with the RAW cr2 file your Canon delivers and make the graphs/calculations/statistics from that?

Cordialement,
Claes en Lund, La Suède

Hi,
Many thanks to you all for your answers ! :smiley:

Yes, I agree with you both. The ideal situation would be to avoid the conversion from CR2 to Tiff (it is the only conversion of format I do, the next step being the transformation from RGB to Lab*) , but can GIMP or ImageJ open CR2 files ? I am not familiar with those softwares, so sorry if I appear to be a newbie with that kind of questions. I am doing a PhD in food chemistry, I digged into the colorimetry issue only 3 weeks ago…! :woozy_face:

My objective is to obtain L* a* b* values for each pixel. From now on, ImageJ 2.0 is the only software with which I managed to obtain a spreadsheet giving the values and the number of pixel corresponding to those values. As I was not sure that ImageJ 2.0 could handle the gamma correction I also got interest in GIMP. If you could recommend any software that gives the total L* a* b* values using the RAW (CR2) file, that would be the best for sure! :grin:

So the question is, what’s the shortest route from camera RGB → characterization → XYZ → perceptual values? I’d also like to know that!

What I do know about is spreadsheets… pure evil! Be careful with that :slight_smile:

The best way to get solid advice is to provide an example (files, data, instruments, etc.), the steps you have taken and the software you have used so far. The more details you share, the easier it is for us to help you.

I also recommend asking your University tech support or a department that could introduce you to useful software and techniques. After all, you are at a place of inquiry with lots of smart and experienced people. :slight_smile:

The reason why I asked what OS you (i.e. your computer) are/is on is that
different OSs offer you quite different ranges of tools.

Just to give you an example, take a look here:
https://duckduckgo.com/?q=imagemagick+read+pixelvalues&ia=qa
And here:
https://www.imagemagick.org/discourse-server/viewtopic.php?t=25830
And here:
https://duckduckgo.com/?q=imagemagick+read+pixelvalues+Lab&ia=web

And… and … and… Life (=Linux) is full of possibilities. (You don’t even have to cut/paste the data into a spreadsheet, you let Linux generate a CSV file for you :slight_smile: )

No, The Gimp cannot open a CR2 file by itself.
However, from what I understand of what you want to do, I would skip The Gimp and instead I would study Imagemagick more closely.

Our own @snibgo wrote a few suggestions here:
https://www.imagemagick.org/discourse-server/viewtopic.php?t=6936

Have fun!
Claes en Lund, La Suède

PS: Can you stand another link?
I just discovered this wealth of ImageMagick information,
written by @snibgo Snibgo's ImageMagick pages

/Claes

Yes, I only use one camera.

Yes, I use 20% gray of SpyderCheckr 24 to set a personalized white balance.

Doesn’t this look very close to what you are after?
http://im.snibgo.com/jumpmeth.htm

/Claes

There is no way to avoid interpolation of the raw file to produce an image file. Doing this absolutely requires a camera input profile.

Converting the interpolated raw file from the camera input profile to a suitable RGB working space will not “harm” the LAB values unless channel clipping is involved.

Exporting the “interpolated from raw” image file to disk as a floating point tiff also will not harm or in any way compromise the LAB values.

No LAB data is even possible without first interpolating the raw file and assigning a suitable camera input profile. The input profile tells you how to get from the interpolated RGB values to XYZ. You have to get to XYZ before you can get to LAB.

1 Like

The thing is that I am in a food technology University, so my issues are far away from the scope of most our Professors. And the one that created the box I am using with the constant light with a hole on top of it to put the lens of the camera, and began the setting of this color analyzing system, suddenly passed away. So I am trying to solve this out by myself thanks to your precious help :slight_smile:

1 Like

Might help for us to know: what’s the significance of LAB to your endeavor?

Ouch. One of my committee members suffered a similar situation in her doctoral work, took a creative approach for her to recover.

You’re probably getting a whole lot more help here than you bargained for, but I think you’re in the right place to figure out a proper method of chromatic characterization, whatever the purpose.

Ok, thank you very much!
Could you recommend any link to create step by step such a camera input profile ?
Actually, today I talked with a PhD student who told me that some industrials got the same issues in creating a colorimeter based on photographs, and they had to create a camera input profile

Haha! Yes! It is amazing! I should thank @Elle for encouraging me to ask my numerous questions on this forum!