Error message when attempting to run CLAHE

clahe
macro
Tags: #<Tag:0x00007fd5408a4798> #<Tag:0x00007fd5408a4630>

#1

Hello,

I am trying to use CLAHE through Fiji to enhance a stack of CT images. Every time I attempt to run the script, however, I get an error saying:

Stack required in line 24. 
Stack.<setFrame>(f);

Does anyone who is familiar with using CLAHE know what the issue could be? I haven’t been able to find any similar issues when searching the forum for discussions about CLAHE.

Thanks,
Greg


#2

Hi Greg and welcome to the forum :slight_smile:

Is the script you are referring to taken from the CLAHE wiki site? Did you modify it at all? If so can you please share with us your version.

Just copy-pasting the script and selecting a random stack it runs without errors on my W10 system with a fresh install of Fiji.

The macro from the wiki:

blocksize = 127;
histogram_bins = 256;
maximum_slope = 3;
mask = "*None*";
fast = true;
process_as_composite = true;
 
getDimensions( width, height, channels, slices, frames );
isComposite = channels > 1;
parameters =
  "blocksize=" + blocksize +
  " histogram=" + histogram_bins +
  " maximum=" + maximum_slope +
  " mask=" + mask;
if ( fast )
  parameters += " fast_(less_accurate)";
if ( isComposite && process_as_composite ) {
  parameters += " process_as_composite";
  channels = 1;
}
   
for ( f=1; f<=frames; f++ ) {
  Stack.setFrame( f );
  for ( s=1; s<=slices; s++ ) {
    Stack.setSlice( s );
    for ( c=1; c<=channels; c++ ) {
      Stack.setChannel( c );
      run( "Enhance Local Contrast (CLAHE)", parameters );
    }
  }
}

#3

Hello @Sverre and @gpandeli,

Here you are the equivalent Beanshell script in case you prefer to use it instead of a macro:

// @ImagePlus image
// @int(label="Block size", description="Size of the local region around a pixel for which the histogram is equalized", value=127) blocksize
// @int(label="Histogram bins", description="Number of histogram bins used for histogram equalization",value=256) histogram_bins
// @float(label="Maximum_slope", description="Limits the contrast stretch in the intensity transfer function", value=3f) maximum_slope
// @String(label="Mask", value="*None*", description="Mask for the filter application", required=false) mask
// @boolean(label="Fast", description="Fast but less accurate version of the filter", value=true) fast
// @boolean(label="Process as composite", description="If unchecked, the selected channel is processed individually", value=true) process_as_composite

import ij.IJ;
import ij.ImagePlus;

// read image dimensions
dim = image.getDimensions();
width = dim[ 0 ];
height = dim[ 1 ];
channels = dim[ 2 ];
slices = dim[ 3 ];
frames = dim[ 4 ];

isComposite = channels > 1;
parameters =
  "blocksize=" + blocksize +
  " histogram=" + histogram_bins +
  " maximum=" + maximum_slope +
  " mask=" + mask;
if ( fast )
  parameters += " fast_(less_accurate)";
if ( isComposite && process_as_composite ) {
  parameters += " process_as_composite";
  channels = 1;
}

// apply CLAHE to each component of the stack
for ( f=1; f<=frames; f++ ) {
  for ( s=1; s<=slices; s++ ) {
    for ( c=1; c<=channels; c++ ) {
      image.setPosition( c, s, f );
      IJ.run( image, "Enhance Local Contrast (CLAHE)", parameters );
    }
  }
}

#4

Thanks Sverre and iarganda,

I did not modify the script at all, I was copy and pasting it directly from the wiki site.

Any ideas as to what the issue could be? One thing to note is that for some reason I have not been able to use import>image sequence through fiji to select an image stack, for some reason it will only allow me to select one image. Instead, I have been selecting the entire stack and just dragging and dropping it into fiji. I wouldn’t think this would make any difference but I though it worth mentioning. Other than that, I cannot think of anything out of the ordinary that might have caused the error.

Thanks,
Greg


#5

When I copy and paste the script from the wiki as linked by @Sverre, I get Stack.setFrame( f ); in line 23, not 24. (But I don’t think this causes the issue here.)

The error message suggests that you simply don’t have a stack as the currently active image, but just a single slice. Possible?


This is how it is supposed to work: you select a single image from the folder, and in the subsequent dialog, you can choose more options, e.g. the file name pattern and a limit of files.

You mean you dragged the whole list of files onto Fiji? In this case, they opened in a single window per slice, which would explain your error. Try instead dragging the (single) folder containing your images.


#6

Thank you so much Jan! That must be the problem as they did open in a single window per slice. I had a feeling it would be something silly as this is my first time working with fiji! I appreciate all the input.