Login  Register

Re: A question about ImageJ's threshold values

Posted by melkor2.0 on Apr 07, 2016; 1:40pm
URL: http://imagej.273.s1.nabble.com/A-question-about-ImageJ-s-threshold-values-tp5013177p5016073.html

Hi,

I'm running through a similar problem here, I wonder how the macro was tweaked to make it run. I work with 12-bit depth images, and I am interested in thresholding and analyzing at a particular % of each image. The script seemed to work, but I noticed that the values are different as if I do it manually. I was wondering whether this might be related to the max value of the histogram (in the images with the greatest deviation the max value is around 2500 [saturated pixels are 4095], so when I manually do the 95% for that particular image the threshold value is around 1200 but the macro prints a value of 1800...

What am I missing?

origen = getDirectory("Images to process");
lista = getFileList(origen);
setBatchMode(true);
for (j=0; j<lista.length; j++) {
       showProgress(j+1, lista.length);
       open(origen+lista[j]);
       nombre = lista[j];
       run("Split Channels");
       id = getImageID();
       selectImage(id);
       run("Duplicate...", " ");
        tissueThreshPerc = 95;
                nBins = 4095;
                getHistogram(values, count, nBins);
                size = count.length;
                cumSum = getWidth() * getHeight();
                tissueValue = cumSum * tissueThreshPerc / 100;
                cumSumValues = count;
                for (i = 1; i<count.length; i++)
                        {
  cumSumValues[i] += cumSumValues[i-1];
                        }
                for (i = 1; i<cumSumValues.length; i++)
  if (cumSumValues[i-1] <= tissueValue && tissueValue <= cumSumValues[i])
                {
  setThreshold(i,4095);
  print(i);
                }
       run("Convert to Mask");
       run("Open");
       run("Close-");
       run("Create Selection");
       run("Copy");
       run("Analyze Particles...", "size=75-Infinity summarize");
       selectImage(id);
       run("Restore Selection");
       run("Measure");
  }

I just tried to change the cumSum loop by the total pixel size as suggested in the other thread:
http://imagej.1557.x6.nabble.com/Threshold-as-a-percentage-of-image-histogram-td3695671.html

But if I try to reset min and max right after i give the value of nBins, it doesn't work :(

Thanks for your patience and help!!

Ramon