Login  Register

Re: reading channel display color

Posted by Gabriel Landini on Oct 28, 2020; 11:18am
URL: http://imagej.273.s1.nabble.com/reading-channel-display-color-tp5024126p5024133.html

Hi Kees,
Nice script. Can I contribute a suggestion?
You could test if the LUT is incrementally linear for the R G B components of
the LUT through the 256 levels, in case some other LUT has been applied or
inverted.
For example when using a different lut the modification below would detect it
(just uncomment line 2 to test).
There might be more elegant ways to test if the LUT linearly increases to 255.
The suggestion below checks that increments are all 1 between levels and that
the highest LUT value is 255.

run("Neuron (5 channels)");
//run("Ice"); //uncomment to test a different LUT
Stack.getDimensions(width, height, channels, slices, frames);
color=newArray(channels+1);
for (i=1; i<=channels; i++){
  if (channels>1) Stack.setChannel(i);
  getLut(reds, greens, blues);
  chr= chg= chb=-1;
  for (j=0;j<255;j++) {
   if (reds[j+1]-reds[j]!=1) chr=0;
   if (greens[j+1]-greens[j]!=1) chg=0;
   if (blues[j+1]-blues[j]!=1) chb=0;
  }
  if (reds[255]!=255) chr=0;
  if (greens[255]!=255) chg=0;
  if (blues[255]!=255) chb=0;
  //print (chr, chg, chb);

 color[i]="unrecognised LUT";
  if (chr==-1 && chg ==0 && chb==0) color[i] = "red";
  if (chr==0 && chg ==-1 && chb==0)  color[i] = "green";
  if  (chr==0 && chg ==0 && chb==-1) color[i] = "blue";
  if  (chr==0 && chg ==-1 && chb==-1) color[i] = "cyan";
  if  (chr==-1 && chg ==0 && chb==-1)  color[i] = "magenta";
  if  (chr==-1 && chg ==-1 && chb==0) color[i] = "yellow";
  if  (chr==-1 && chg ==-1 && chb==-1) color[i] = "gray";
  print (color[i]);
}

Cheers

Gabriel

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html