Testing different CLAHE parameters on a single image

In order to avoid tediously manually testing different possible combinations of input parameters for the CLAHE filter, the following Fiji macro can be used to get a fast overview.

// Macros for applying the CLAHE plugin at http://rsb.info.nih.gov/ij/plugins/clahe/index.html
// by Michael Cammer March 2012

// This macro operates applies a few different CLAHE paramenters to the same image and pops the
// results into a stack. The paramenters are printed in the upper left of the image. To turn this off, comment out the
// "drawString" line at the end of the loop. On large images, beast run on a subset of the stack. Then pick the
// favorite result and run on the full image.
macro "iterate through CLAHE options" {
original = getImageID;
blocksize = newArray(7, 15, 31, 63, 127, 512);
contrast = newArray(3, 7, 11, 16);
for (k=0; k<contrast.length; k++)
for (i=0; i<blocksize.length; i++) {
if (nSlices>1) setSlice(1);
run("Select All");
run("Add Slice");
run("Select None");
run("Enhance Local Contrast (CLAHE)", "blocksize="+blocksize[i]+" histogram=256 maximum="+contrast[k]+"");
drawString("blocksize "+blocksize[i]+", contrast "+contrast[k], 1, 30);
} // test CLAHE parameters

Input image:


notice the input values shown in the upper left

3 Replies to “Testing different CLAHE parameters on a single image”

  1. thanks for the post about CLAHE parameters, the image result is run. great. thank you

  2. What method is used to test the CLAHE parameter?

    1. The script is basically just running the filter with several input values (which can be extended in the script if whished), see below:

      blocksize = newArray(7, 15, 31, 63, 127, 512);
      contrast = newArray(3, 7, 11, 16);

      Thus there is no other method used to test these values than just the visual inspection of the user.
      The script is intended to get a fast overview which of the input values give the best intended result. Afterwards further fine tuning of the values is possible.

Leave a Reply