Initial Color Calibration Results

Thanks to Peter Haub’s comment on my previous post, I’ve begun to get color calibration of our RGB images working. As he suggested, I’ve been using ArgyllCMS, which does most of what I need using a command line interface. I acquire my images using illumination with red, green, and blue LEDs, using a monochrome camera. These are then flat-fielded using images acquired with no slide; this is done without normalizing the images so as to white balance at the same time (details in this previous post). As an aside, I’m not totally happy with this correction procedure and I hope to improve it soon.

As our camera is 16-bit, the first task is to convert our Micro-manager image stacks into 16-bit per channel RGB TIFFs (also known as 48-bit TIFFs) so that ArgyllCMS can read them. It turns out that ImageJ will save 48-bit RGB tiffs, but only if the first channel is named “Red”. This ImageJ macro will fix the naming (thanks to Wayne Rasband for telling me how to do this):

labels = newArray("Red", "Green", "Blue");
for (i=0; i<3; i++) {
   setSlice(i+1);
   setMetadata("label", labels[i]);
}
saveAs("tif", "");

The first step in color calibrating an image is extracting the pixel values from the calibration slide I showed previously and comparing them to the expected values of the slide in a reference color space (CIEXYZ or CIELAB). These values are provided by the manufacturer of the slide. In ArgyllCMS, this is done with the scanin command:

scanin -v -dipn CalibrationSlide.tif C:\Argyll_V1.6.3\ref\It8.cht ..\N140131.txt

It8.cht is the file that defines the chart layout, and N140131.txt is the file documenting the XYZ values of the chart provided by the manufacturer.

This produces CalibrationSlide.ti3, which is just a text file listing all of the color patches in the chart with their XYZ values (from the manufacturer) and the RGB values (measured from our image). The RGB values are expressed in percent of full scale. Next, we need to turn these values into an ICC device profile to transform our measured data (from the .ti3 file) into one of the reference (or device independent) color spaces. The ArgyllCMS command colprof does this:

colprof -v -D"HSS" -qm -am CalibrationSlide

This produces an ICC profile in the file CalibrationSlide.icm. The -D flag lets you provide a name for your profile, and the -am flag tells it to calculate a single matrix that transforms from RGB to the reference color space. There are many ways of doing this transformation, but the single matrix is in some sense the most conservative, and is appropriate if your camera has a linear response, which it probably does. For my system, this results in the matrix:

 0.589552 0.502653 0.138266
 0.282719 1.007607 0.031246
-0.005334 -0.068406 1.045615

I believe that this matrix transforms RGB to XYZ, i.e. XYZ = matrix * RGB, but I haven’t confirmed this.

With this ICC profile in hand you are essentially done. You can load this profile into a program that knows about color management (like Photoshop) and then assign this profile to your microscope images when you load them, and Photoshop will handle the rest. You can then save your images into a standard color space (like sRGB), and in principle, other people will know how to interpret the RGB values. If you want to simplify your workflow and avoid going through Photoshop, you can link the device profile created above to a profile defining a standard color space (e.g. sRGB) and convert from the device color space to sRGB in a single step. The command collink does this:

collink CalibrationSlide.icm c:\Argyll_V1.6.3\ref\sRGB.icm HSS2sRGB.icm

I can then use the command cctiff to convert a TIFF measured on our microscope to the sRGB color space in a single step:

cctiff -ip HSS2sRGB.icm HE9.tif HE9sRGB.tif

Finally, here are some results. These are single images of various H&E stained tissues from Carolina Biological Supply. The top row (if your browser window is wide enough) is the raw images from the microscope; the bottom row is the same images converted to the sRGB color space; you can click on the images to see the full resolution 4 megapixel images.

HE4HE7HE9
HE4sRGBHE7sRGBHE9sRGB

The single biggest difference you can see is that the sRGB images are much brighter. I believe that’s because of the gamma correction of roughly 2.2 that sRGB provides. I’m still not sure if this is a good thing, if we should be working in a linear color space, or if I’ve done something wrong in this process. The colors are definitely brighter and better looking in the corrected images, but they look washed out to me. Applying a gamma correction of about 2 makes these images look better, but I don’t think I should have to do that.  Expect more posts as I learn more about how to do this correctly.

Forays into color correction

I posted a while back about using RGB LEDs and a monochrome camera to acquire color images, and while this works pretty well, one thing that has bothered me about it is getting the right color balance of the images. That is, does the color image captured by this process correspond to the same image you would see under white light illumination?

Datacolor has released a calibration slide and software tool for doing this color calibration, but I want to see if we can do it cheaply and build a tool for color correction into Micro-manager. To that end, I got a 35 mm slide designed for calibrating flatbed scanners and imaged it on our microscope, with RGB LED illumination, and white balanced by dividing by flatfield images taken with no sample present..

Coloraid.de calibration slide imaged with RGB LED illumination and stitched together from 77 images with a 4x / 0.2 objective. Click to open the full size image at Gigapan.

Coloraid.de calibration slide imaged with RGB LED illumination and stitched together from 77 images with a 4x / 0.2 objective. Click to see full resolution image at Gigapan.org.

Continue reading