Login  Register

Re: Method of creating a stack zprojection image using the mode / modal value

Posted by jeremydouglass on Jan 01, 2009; 8:06am
URL: http://imagej.273.s1.nabble.com/Method-of-creating-a-stack-zprojection-image-using-the-mode-modal-value-tp3694140p3694144.html

Thank you so much G. This was extremely helpful.

After working for a while in this direction, I've written a macro to compute the modal zprojection that does exactly as you suggest -- first performing a reslice, then computing the mode(s) of each pixel column in each slice, and the reslices back to assemble the modal z projection image.  It appears to be working correctly although it is quite inefficient.  For anyone interested, I'm including my source below, with the caveat that this was my first ImageJ plugin and it might have problems. Note that here the modal value used for each pixel is always the *last* value returned to the results list if more than one mode is returned.


if (nSlices<2) exit("This macro requires a stack.");
makeModalZProject();
function makeModalZProject() {
   setBatchMode(true);
   run("Set Measurements...", "  modal redirect=None decimal=3");
   run("Reslice [/]...", "input=1.000 output=1.000 start=Top");
   depth = nSlices;
   width=getWidth();
   for (z=0; z<depth; z++) { // loop through slices
      setSlice(z+1);
      for (x=0; x<width; x++) { // loop through rows in a slice
         makeRectangle(x, 0, 1, depth); // select each column
run("Measure");
zmodal = getResult("Mode",nResults-1);
// be careful if multiple modes are returned this will take the last one.
         setPixel(x, 0, zmodal);
      }
   }
   run("Select None");
   run("Reslice [/]...", "input=1.000 output=1.000 start=Top");
   setBatchMode(false); // display
}