Skip to content

Instantly share code, notes, and snippets.

@romainGuiet
Created September 3, 2019 09:24
Show Gist options
  • Save romainGuiet/42395587d1193536b7a0858f72db4aca to your computer and use it in GitHub Desktop.
Save romainGuiet/42395587d1193536b7a0858f72db4aca to your computer and use it in GitHub Desktop.
a script for ImageJ (in macro language) to measure Full Width at Half Maximum.
doAxialMeasure = true;
//get some informations about the image
image_Name = getTitle();
getDimensions(image_width, image_height, image_channels, image_slices, image_frames);
getVoxelSize(voxel_width, voxel_height, voxel_depth, voxel_unit);
doFWHM();
if (doAxialMeasure){
// define the length of the line
lineLength = 40;
// to find bright spot , https://imagej.nih.gov/ij/docs/guide/146-29.html
prominence = 100 ;
selectImage(image_Name);
run("Reslice [/]...", "output=["+voxel_depth+"]");
run("Find Maxima...", "prominence="+prominence+" output=[Point Selection]");
// get coordinates of the Maxima(s)
getSelectionCoordinates(xpoints, ypoints);
// make a Line using the Coordinates of the First Maxima (the brightest)
// and the line length defined
makeLine(xpoints[0], ypoints[0] - lineLength/2,xpoints[0], ypoints[0] + lineLength/2 );
// do the measure
doFWHM();
}
// companion function to make the math for FWHM
function doFWHM(){
image_Name = getTitle();
getVoxelSize(voxel_width, voxel_height, voxel_depth, voxel_unit);
y = getProfile();
x = Array.getSequence(lengthOf(y));
Fit.doFit("Gaussian", x, y) ;
Fit.plot;
// parameter d of gaussian
sortedParameter = Fit.p(3);
rSquared = Fit.rSquared ;
// http://fr.wikipedia.org/wiki/Largeur_%C3%A0_mi-hauteur
FWHM = (2 * sqrt( 2 * log(2) ) ) * sortedParameter ;
setResult("FWHM ("+voxel_unit+")", nResults, FWHM * voxel_height);
setResult("Label",nResults-1,image_Name);
setResult("rSquared",nResults-1,rSquared);
updateResults();
selectWindow("Results");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment