Help combining 2 macros to obtain FWHM from the plot profile of a stack

Hi folks,

I need your assistance. I would like to combine 2 macros (that I did not create) and don’t understand how to go about integrating them.

One of the macros gives me the plot profile of a stack. This macro is extremely useful for me but contains too many data points for analysis.

The other macro gives me the essential piece of information that is FWHM, but only for 1 slice of the stack.

In essence, I would like the new macro to tell me the FWHM for each slice of the entire stack. For what it’s worth, I want to obtain the distance between two boundaries across time using the line scan function.

Please advise. Thank you.

Apologies if this is an inefficient way way of attaching the macros.

**// StackProfileData**
// This ImageJ macro gets the profile of all slices in a stack
// and writes the data to the Results table, one column per slice.
//
// Version 1.0, 24-Sep-2010 Michael Schmid

macro "Stack profile Data" {
     if (!(selectionType()==0 || selectionType==5 || selectionType==6))
       exit("Line or Rectangle Selection Required");
     setBatchMode(true);

     run("Plot Profile");
     Plot.getValues(x, y);
     run("Clear Results");
     for (i=0; i<x.length; i++)
         setResult("x", i, x[i]);
     close();

     n = nSlices;
     for (slice=1; slice<=n; slice++) {
         showProgress(slice, n);
         setSlice(slice);
         profile = getProfile();
         sliceLabel = toString(slice);
         sliceData = split(getMetadata("Label"),"\n");
         if (sliceData.length>0) {
             line0 = sliceData[0];
             if (lengthOf(sliceLabel) > 0)
                 sliceLabel = sliceLabel+ " ("+ line0 + ")";
         }
         for (i=0; i<profile.length; i++)
             setResult(sliceLabel, i, profile[i]);
     }
     setBatchMode(false);
     updateResults;
}
 * Example finding length of line-like structures using supergaussian fitting and FWHM
 * 
 * Olivier Burri, Romain Guiet, EPFL-SV-BIOP
 * June 2018 
 * 
 * REQUIRES 
 * 	An open image
 * 	A line ROI drawn across a structure of interest
 * 	A bright structure on a dark background
 * 	
 * OUTPUTS
 * 	Plot of original data + fit
 * 	FWHM value in ImageJ Log in PIXELS
 */
 
//Get Line Profile
y = getProfile();

// Create x axis
x = Array.getSequence(y.length);

// Get some stats to initialize the fit
Array.getStatistics(y, ymin, ymax, ymean, ystdDev);

guesses = newArray(ymin, ymax, ymean, ystdDev, 1.0);

// The formula for a supergaussian
superGaussian = "y = a + b * exp(-1*(pow ((x-c)*(x-c), e ) / pow( 2*d*d , e ) ) )"

// Do fitting

Fit.doFit(superGaussian, x,y, guesses);
Fit.plot();

// Compute and display FWHM in the log window
par_d = Fit.p(3);
par_e = Fit.p(4);
FWHM = 2*sqrt(2)*par_d*pow(log(2),1/(2*par_e));

print("FWHM: "+FWHM);

Hi @Michael_Alvarado,

something like that should be ok:

for (slice=1; slice<=nSlices(); slice++)
{
   setSlice(slice);
   //Get Line Profile
   y = getProfile();

   // Create x axis
   x = Array.getSequence(y.length);

   // Get some stats to initialize the fit
   Array.getStatistics(y, ymin, ymax, ymean, ystdDev);

   guesses = newArray(ymin, ymax, ymean, ystdDev, 1.0);

   // The formula for a supergaussian
   superGaussian = "y = a + b * exp(-1*(pow((x-c)*(x-c), e) / pow(2*d*d, e) ) )";

   // Do fitting
   Fit.doFit(superGaussian, x,y, guesses);

   // Compute and display FWHM in the log window
   par_d = Fit.p(3);
   par_e = Fit.p(4);
   FWHM = 2*sqrt(2)*par_d*pow(log(2),1/(2*par_e));

   print("slice " + slice + " FWHM: " + FWHM);
}

Nico

@VirtualSlide

Thank you so much for the assistance! I have made 2 minor adjustments that output absolute values as well as show the progress of the stack as the values are being calculated. I really appreciate your help.

Cheers,
Michael