HyperStack Histogram Macro

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

HyperStack Histogram Macro

Francis
Hello,

I need help to automatically extract the histogram and statistics from a 20
channel hyperstack 32bit tiffs and save the data to csv text file or
ideally an excel spreadsheet. I am not sure if I need to use the 256 bin
range or the pixel use range to make this work.

Does anyone have a macro to achieve this goal or can suggestion any ideas
to tackle this problem? I am including a file of what I trying to do.

--
Best Regards,

Francis

Research graduate,
New York School of Medicine
New York

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

ImageJHyperStack.tif (1M) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: HyperStack Histogram Macro

Cammer, Michael
I think this is what you want (except it dumps the results into the Log window tab delimited), but there is one pixel of value 169256250 that throws the whole thing off.  Also, the dynamic range is so wide in channels 5 & 6 compared to the others that 256 bins may not give significant results.  Even after 1 X 1 median filtering.

//  Prints to Log window.  Could print to a text file instead.  Just need to add file commands.
//  For now, Select all, copy, paste into Excel.
var tab = " \t ";           // Could be changed to comma if csv really preferred.
var hmax = 65535 ;  // max for 16 bit images.
var hmin = 0;             //  assumes unsigned image.
var bins = 256;         //  set whatever you need
macro "Histogram of each slice in stack [F4]" {
  run("Select None");
  s = nSlices();
  // This first pass finds the min and max of the entire volume.
  for (i=1; i<=s; i++) {
    setSlice(i);
    getStatistics(area, mean, min, max, std, histogram);
    if (max > hmax) hmax = max;
    if (min < hmin) hmin = min;
  }
  //  This is where the dialog for user input would go.  It would display the min & max values found in the first pass
  //  and ask for user changes including # of bins.
  outputstring = newArray(bins);
  for (out=0; out<bins; out++)
    outputstring[out] = "";
  //Array.fill(outputstring, "");
  for (i=1; i<=s; i++) {
    setSlice(i);
    getHistogram(values, counts, bins, hmin, hmax);
    if (i==1)
      for (out=0; out<bins; out++)
         outputstring[out] = outputstring[out] + values[out] + tab;
    for (out=0; out<bins; out++)
      outputstring[out] = outputstring[out] + counts[out] + tab;
  }  // end for each slice
  for (out=0; out<bins; out++)
    print(outputstring[out]);
} // end macro


_________________________________________
Michael Cammer, Optical Microscopy Specialist
http://ocs.med.nyu.edu/microscopy
http://microscopynotes.com/
Cell: (914) 309-3270

________________________________________
From: ImageJ Interest Group [[hidden email]] on behalf of Francis OBrien [[hidden email]]
Sent: Tuesday, April 07, 2015 7:24 PM
To: [hidden email]
Subject: HyperStack Histogram Macro

Hello,

I need help to automatically extract the histogram and statistics from a 20
channel hyperstack 32bit tiffs and save the data to csv text file or
ideally an excel spreadsheet. I am not sure if I need to use the 256 bin
range or the pixel use range to make this work.

Does anyone have a macro to achieve this goal or can suggestion any ideas
to tackle this problem? I am including a file of what I trying to do.

--
Best Regards,

Francis

Research graduate,
New York School of Medicine
New York

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: HyperStack Histogram Macro

Francis
Michael,

Thank you so much for your help. The image hyperstack represents 20
separate channels of mass spectrometer data so I need each channel
to have its own bin range.

The outliers are detector "blips" that create random noise and I need to
separately determine their frequency, location and tag for removal by
setting to the (average/median,) of the pixels before and after this single
pixel "blip". The data is acquired line by line, with each line taking 1-2
minutes to complete. The 100's of lines of data are then stacked together
to form a matrix of numbers which represents a chemical map.

I am using some basic stats (see below) to try to separate the outliers
from the dataset and then create histograms to capture the behavior of the
normal image by separating out the detector blips.
It would be nice to see if I can create a separate histogram for the noise
in the image as this information may help me understand the source of the
noise and how to eliminate or minimize its effects.

Best,

Francis

AverageMinimumMaxmiumMedianStandard DeviationAverage deviation from meanLower
quartileUpper quartile

Interquartile range

Anything outside of 3 standard deviations (99.7%) seems to capture those
outliers.






On Tue, Apr 7, 2015 at 10:59 PM, Cammer, Michael <[hidden email]
> wrote:

> I think this is what you want (except it dumps the results into the Log
> window tab delimited), but there is one pixel of value 169256250 that
> throws the whole thing off.  Also, the dynamic range is so wide in channels
> 5 & 6 compared to the others that 256 bins may not give significant
> results.  Even after 1 X 1 median filtering.
>
> //  Prints to Log window.  Could print to a text file instead.  Just need
> to add file commands.
> //  For now, Select all, copy, paste into Excel.
> var tab = " \t ";           // Could be changed to comma if csv really
> preferred.
> var hmax = 65535 ;  // max for 16 bit images.
> var hmin = 0;             //  assumes unsigned image.
> var bins = 256;         //  set whatever you need
> macro "Histogram of each slice in stack [F4]" {
>   run("Select None");
>   s = nSlices();
>   // This first pass finds the min and max of the entire volume.
>   for (i=1; i<=s; i++) {
>     setSlice(i);
>     getStatistics(area, mean, min, max, std, histogram);
>     if (max > hmax) hmax = max;
>     if (min < hmin) hmin = min;
>   }
>   //  This is where the dialog for user input would go.  It would display
> the min & max values found in the first pass
>   //  and ask for user changes including # of bins.
>   outputstring = newArray(bins);
>   for (out=0; out<bins; out++)
>     outputstring[out] = "";
>   //Array.fill(outputstring, "");
>   for (i=1; i<=s; i++) {
>     setSlice(i);
>     getHistogram(values, counts, bins, hmin, hmax);
>     if (i==1)
>       for (out=0; out<bins; out++)
>          outputstring[out] = outputstring[out] + values[out] + tab;
>     for (out=0; out<bins; out++)
>       outputstring[out] = outputstring[out] + counts[out] + tab;
>   }  // end for each slice
>   for (out=0; out<bins; out++)
>     print(outputstring[out]);
> } // end macro
>
>
> _________________________________________
> Michael Cammer, Optical Microscopy Specialist
> http://ocs.med.nyu.edu/microscopy
> http://microscopynotes.com/
> Cell: (914) 309-3270
>
> ________________________________________
> From: ImageJ Interest Group [[hidden email]] on behalf of Francis
> OBrien [[hidden email]]
> Sent: Tuesday, April 07, 2015 7:24 PM
> To: [hidden email]
> Subject: HyperStack Histogram Macro
>
> Hello,
>
> I need help to automatically extract the histogram and statistics from a 20
> channel hyperstack 32bit tiffs and save the data to csv text file or
> ideally an excel spreadsheet. I am not sure if I need to use the 256 bin
> range or the pixel use range to make this work.
>
> Does anyone have a macro to achieve this goal or can suggestion any ideas
> to tackle this problem? I am including a file of what I trying to do.
>
> --
> Best Regards,
>
> Francis
>
> Research graduate,
> New York School of Medicine
> New York
>
> --
> ImageJ mailing list: http://imagej.nih.gov/ij/list.html
> --
> ImageJ mailing list: http://imagej.nih.gov/ij/list.html
>



--
Regards,

Francis

Research graduate,
New York School of Medicine
New York

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