Tracking the same fiber-type object motion between multiple frames

Hi everyone,
I’m newbie here, and I’m being struggled with my study, seeking for some help.
At the moment, I’m doing some image processing related to tracking fiber-type object motion in video.
In my case, the output data requires object’s position, angle and length.
By using tools of ImageJ, I can only get these data manually. It takes me very long time to get work done.
Could anyone help me how to track the same fiber-type object motion between multiple frames and export object data (position, angle and length) automatically (Roughly trace the fiber in frame 1 and then let the program track it through the frames).
I enclosed my sample images and video link.
Thank you for your help. I greatly appreciate it.


00.tif (2.5 MB) 02.tif (2.5 MB) 04.tif (2.5 MB) 06.tif (2.5 MB)
1 Like

Hi
@Khoa

Very nice pictures. Below is a part of the macro that you can adapt to your problematic.



// Set scale
setOption("ScaleConversions", true);
run("Set Scale...", "distance=0 known=0 unit=pixel");


//Crop the image for the area of interest
run("Duplicate...", "title=1");
run("8-bit");
close("\\Others");
//setTool("rectangle");
makeRectangle(300, 0, 724, 1280);
run("Crop");
run("Duplicate...", "title=2");
run("Duplicate...", "title=3");

//Image processing
run("Subtract Background...", "rolling=50 light");
run("Gaussian Blur...", "sigma=3");
run("Ridge Detection", "line_width=3.5 high_contrast=230 low_contrast=87 darkline add_to_manager method_for_overlap_resolution=NONE sigma=1.51 lower_threshold=0.85 upper_threshold=5.78 minimum_line_length=0 maximum=0");
run("Create Mask");
run("Analyze Particles...", "display exclude include");

// Create an array
arrayX=newArray(nResults);
arrayY=newArray(nResults);

// Save the values in an array
for(i=0;i<nResults;i++)
{
arrayX[i]=getResult("X",i);
arrayY[i]=getResult("Y",i);
}
// Show all array
Array.show(arrayX);
Array.show(arrayY);
close("Mask");
selectImage("2");

// Superimpose points
//setTool("point");
makeSelection("point", arrayX, arrayY);
run("Point Tool...", "type=Circle color=Red size=Large add_to label show");
run("Flatten");

Greetings

1 Like

Hi
@Khoa
Can you tell me about your results, if you don’t mind.
Regards

macro "Tracking the same fiber-type object "
{

requires("1.52u");
setBackgroundColor(0,0,0);
setOption("BlackBackground",true);
// Start batch mode
setBatchMode(true);
run("Set Measurements...", "centroid display add redirect=None decimal=2");


// Step 1
dir1=getDirectory("Select folder containning files to process");
dir2=getDirectory("Select the folder which should save the processed files.");
print("The name of the folder1 is:"+dir1);
print("The name of the folder2 is:"+dir2);
list=getFileList(dir1);
n=lengthOf(list);
print("The number of images is: ="+n);
for(j=0;j<n;j++)
{

if(endsWith(list[j],".tif"))
open(dir1+list[j]);
wait(100);
img=getImageID();
print(img);
selectImage(img);

//-------------------------------------------------
// Step 2
//Crop the image for the area of interest
run("Duplicate...", "title=1");
run("8-bit");
setOption("ScaleConversions", true);
run("Set Scale...", "distance=0 known=0 unit=pixel");
close("\\Others");
//setTool("rectangle");
makeRectangle(300, 0, 724, 1280);
run("Crop");
run("Duplicate...", "title=2");
run("Duplicate...", "title=3");

//Image processing
run("Subtract Background...", "rolling=50 light");
run("Gaussian Blur...", "sigma=3");
run("Ridge Detection", "line_width=3.5 high_contrast=230 low_contrast=87 darkline add_to_manager method_for_overlap_resolution=NONE sigma=1.51 lower_threshold=0.85 upper_threshold=5.78 minimum_line_length=0 maximum=0");
run("Create Mask");
run("Analyze Particles...", "display exclude include");

// Create an array
arrayX=newArray(nResults);
arrayY=newArray(nResults);

// Save the values in an array
for(i=0;i<nResults;i++)
{
arrayX[i]=getResult("X",i);
arrayY[i]=getResult("Y",i);
}
// Show all array
Array.show(arrayX);
Array.show(arrayY);
close("Mask");
selectImage("2");

// Superimpose points
//setTool("point");
makeSelection("point", arrayX, arrayY);
run("Point Tool...", "type=Circle color=Red size=[Extra Large] add_to label show");
run("Flatten");
saveAs("Jpeg", dir2+"Y"+j+".jpg");
//-----------------------------------------------------------
// Step3
 Array.show(arrayX);
Table.rename("arrayX", "arrayX"+j);
saveAs("Results",dir2+"X"+j+".csv");
close("X"+j+".csv");
close("arrayx");

//Array.show(arrayY);
Table.rename("arrayY", "arrayY"+j);
saveAs("Results",dir2+"Y"+j+".csv");
close("Y"+j+".csv");
close("arrayY");
roiManager("reset");
close("Results");
}
run("Close All"); close("Log"); close("ROI Manager");

//------------------------------------------
// End of processing
// End of batch mode
setBatchMode(false);
exit("All is done !\nCheck your destination folder.");
}
1 Like