Image Analysis: length measurements between Edges

Hi (Fiji is just ) ImageJ experts,
I am new with macro and sripts in ImageJ suite. Here is what I’d like to perform:
I’d like to measure (vertical) length of SEM images. Up to now I managed to create a small macro with all the bunch of filters I need to get only edges of the structures and get a Selection of these edges. Now I wish to measures for a given or several x values the highest and lowest Y values for the maxima (pixel intensities).

(When the code will run it will be used in batch process for hundreds of images)

I hope I am clear enough.

Here is the code I did up to now:

macro "ResolutionBridge_1" {

//setBatchMode(true);
title = getTitle();
Path = getDirectory("image");
//ResultName = replace(title, ".tif", "");

run("Duplicate...", "title=threshold");
getDimensions(width, height, channels, slices, frames);
//print("width:" + width, "height:" + height);
makeRectangle(0.2*width, 0, 0.8*width, 0.8*height);
run("Crop");
run("Gaussian Blur...", "sigma=2");
minthresh = getNumber("Min Threshold Value", 60);
maxthresh = getNumber("Max Threshold Value", 150);
setAutoThreshold("Huang");
setThreshold(minthresh, maxthresh);
//run("Threshold...");
setOption("BlackBackground", true);
run("Duplicate...", "title=Binary_Mask");
run("Convert to Mask");
run("Duplicate...", "title=Edges");
run("Find Edges");
run("Convolve...", "text1=[1 0 -1\n] normalize");
run("Duplicate...", "title=Maxima");
run("Find Maxima...", "noise=100 output=[Point Selection]");
if (selectionType==10) {
	getSelectionCoordinates(x,y);
		} //end of if condition


//run("Image to Results");
} // end of macro

My problem is I do not know how to go on:

  • Should I draw a line and find plugin or code to tell to look for maxima on this line ?
  • Make a function to do it ?

It is noteworthy to say I do not know anything about coding at all. Everything I did is coming from videi by Ellen Arena and chat from http://imagej.1557.x6.nabble.com/moving-boundary-tc5000422.html

Thank you for your kind and wised advise.

Here is a typical image:
20200615-5.1.5_001.tif (3.7 MB)

1 Like

Hi
@ClotR_C.C
It is an interesting work, but you would facilitate our task by depositing a second annotated image.
Indicate with line segments the lengths you want to measure.
Regards

1 Like

First of all Thank you for your reply.

Here is the “schematic” of what I explained. It represents the “1st step” of signal processing (already achieved) and the “2nd step” in drawing lines or taking measurements in order to get the lengths and save them in a table.

Is it clearer with picture ?

Thank you
Regards

This older thread might be a help because it’s quite similar (which also has nested links):

Using the Exact Euclidean Distance Transform.

1 Like

Hi
@ClotR_C.C
Regards

macro "Length measurements between edges"
{
requires("1.53b");
setBackgroundColor(0,0,0);
setOption("BlackBackground",true);
img=getImageID();
setBatchMode("True");
selectImage(img);
run("Duplicate...", "title=1");
close("\\Others");
//setTool("rectangle");
makeRectangle(50, 440, 2048, 1020);
run("Duplicate...", "title=1");
run("Set Scale...", "distance=0 known=0 unit=pixel");
run("Set Measurements...", "area mean display redirect=None decimal=0");
run("Duplicate...", "title=2");
selectImage("2");
run("Gaussian Blur...", "sigma=3");
setAutoThreshold("Mean");
//run("Threshold...");
//setThreshold(0, 145);
run("Convert to Mask");
run("Invert");
run("Fill Holes");
setBatchMode("false");

//------------------------------------
//setTool("line");
h=getHeight();
l=getWidth();
interval=l/50;
for(k=1; k<50; k++)
{
makeLine(k*interval, 0 ,k*interval, h);
roiManager("Add");
//----------------------------------------
  profile = getProfile();
  for (i=0; i<profile.length; i++)
      setResult("Value", i, profile[i]);
  updateResults;
//-------------------------------
/* 
*Thickness measurements
*/
//------------------------------------
n=0;
 for (i=0; i<nResults; i++)
{
if(getResult("Value", i)>0 )
n++;
}
print("for line"+" "+ k+":"+"n=",n);
}

close("results");
roiManager("Show All with labels");
run("Tile");
exit("All is done!");
}


Watch out for lines 8 to 10 and 13 to 14!

Thank you very much @Bio7 for the link, very close to what I need indeed.
And Thank’s a lot to @Mathew for the full code.

I have a lot to read and understand to fill my lack of knowledge.

Thank you again

Best regards
ClotR

1 Like

@ClotR_C.C
Two essential readings
https://imagej.nih.gov/ij/docs/guide/index.html
https://imagej.nih.gov/ij/developer/macro/functions.html

Have a good day

1 Like