Snippets

Dave Mason Get profiles along Feret lengths (https://forum.image.sc/t/drawing-feret-and-feretmin-as-selection/22131)

Created by Dave Mason
//-- CLose existing images
close("*");
//-- open a sample image
run("Blobs (25K)");
//-- Threshold and create particles
setThreshold(125, 248);
run("Analyze Particles...", "show=Nothing exclude clear record");

//-- For each object, calculate the Feret parameters and draw the line
for (i=0; i<nResults; i++) {
	x = getResult('XStart', i);
	y = getResult('YStart', i);
	doWand(x,y);
	drawFeretsDiameter();
    if (i%5==0) {showProgress(i/nResults);}
    run("Select None");
    resetThreshold;
}




function drawFeretsDiameter() {
//-- FeretDiameter macro example
requires("1.29n");
run("Line Width...", "line=1");
diameter = 0.0;
getSelectionCoordinates(xCoordinates, yCoordinates);
n = xCoordinates.length;
for (i=0; i<n; i++) {
	for (j=i; j<n; j++) {
    	dx = xCoordinates[i] - xCoordinates[j];
        dy = yCoordinates[i] - yCoordinates[j];
        d = sqrt(dx*dx + dy*dy);
        if (d>diameter) {
        	diameter = d;
            i1 = i;
            i2 = j;
            }
        }
    }
//-- Create a line selection
makeLine(xCoordinates[i1], yCoordinates[i1],xCoordinates[i2],yCoordinates[i2]);
//-- Pull the intensity profile alone the line
profile = getProfile();
//-- Print the profile intensities to the log
Array.print(profile);
//-- Draw the line in a non-destructive overlay
Overlay.addSelection("magenta");
}

Comments (0)

HTTPS SSH

You can clone a snippet to your computer for local editing. Learn more.