|
/**
|
|
* Velocity Measurement Tool
|
|
*
|
|
* Measure the velocity of particles in the kymogram of the time series. The tool allows to create
|
|
* the kymogram. The user can make a segmented line selection and the mean speed for each
|
|
* segment will be measured
|
|
*
|
|
* written 2013 by Volker Baecker (INSERM) at Montpellier RIO Imaging (www.mri.cnrs.fr)
|
|
* uses modified code from www.embl.de/emnet/html/kymograph.html (tsp050706.txt TimeSpacePlot (Kymograph))
|
|
* by J. Rietdorf FMI Basel + A. Seitz EMBL Heidelberg
|
|
*/
|
|
|
|
var helpURL = "http://dev.mri.cnrs.fr/projects/imagej-macros/wiki/Velocity_Measurement_Tool";
|
|
var Z_PROJECT = true;
|
|
|
|
macro "Velocity Measurement Help (f1) Action Tool - C037T4d14?"{
|
|
showHelp();
|
|
}
|
|
|
|
macro "Velocity Measurement Help [f1]" {
|
|
showHelp();
|
|
}
|
|
|
|
macro "Kymograph (f2) Action Tool - C037T4d14k" {
|
|
createKymogram();
|
|
}
|
|
|
|
macro "Kymograph create kymogram [f2]" {
|
|
createKymogram();
|
|
}
|
|
|
|
|
|
macro "Velocity (f3) Action Tool - C037T4d14v" {
|
|
measureVelocities();
|
|
}
|
|
|
|
macro "Velocity [f3]" {
|
|
measureVelocities();
|
|
}
|
|
|
|
function check4ROItype(mintype,maxtype,notype) {
|
|
|
|
if ((selectionType()<mintype)||(selectionType()>maxtype)||(selectionType()==notype)||(selectionType()==-1)){
|
|
if ((mintype==3)&&(maxtype==7)) exit("select a line ROI");
|
|
if ((mintype==0)&&(maxtype==3)) exit("select an area ROI");
|
|
else exit("select a suitable ROI");
|
|
}
|
|
}
|
|
|
|
function showHelp() {
|
|
run('URL...', 'url='+helpURL);
|
|
}
|
|
|
|
function createKymogram() {
|
|
setBatchMode(true);
|
|
title = getTitle();
|
|
hasSelection = false;
|
|
if (selectionType() != -1) hasSelection=true;
|
|
isHyperstack = Stack.isHyperstack;
|
|
if (isHyperstack) {
|
|
run("Reduce Dimensionality...", " frames keep");
|
|
if (hasSelection)
|
|
run("Restore Selection");
|
|
tmp = getTitle();
|
|
}
|
|
run("Reslice [/]...", "output=0.000 start=Top avoid");
|
|
slices = nSlices;
|
|
rename("kymogram of " + title);
|
|
if (isHyperstack) {
|
|
selectWindow(tmp);
|
|
close();
|
|
}
|
|
selectWindow("kymogram of " + title);
|
|
if (slices>1 && Z_PROJECT) {
|
|
run("Z Project...", "start=1 stop="+slices+" projection=[Max Intensity]");
|
|
selectWindow("kymogram of " + title);
|
|
close();
|
|
selectWindow("MAX_kymogram of " + title);
|
|
rename("kymogram of " + title);
|
|
}
|
|
setBatchMode("exit and display");
|
|
}
|
|
|
|
function measureVelocities() {
|
|
// modified from www.embl.de/eamnet/html/kymograph.html (tsp050706.txt TimeSpacePlot (Kymograph))
|
|
|
|
check4ROItype(3,7,-1);
|
|
run("Clear Results");
|
|
getSelectionCoordinates(x, y);
|
|
sum_dx=0;
|
|
sum_dy=0;
|
|
|
|
for (i=0; i<x.length-1; i++){
|
|
dx_now=abs(x[i+1]-x[i]);
|
|
sum_dx=sum_dx+dx_now;
|
|
|
|
dy_now=abs(y[i+1]-y[i]);
|
|
if (dy_now==0)dy_now=1;
|
|
sum_dy=sum_dy+dy_now;
|
|
|
|
setResult("dy sum", i, sum_dy);
|
|
setResult("dx sum", i, sum_dx);
|
|
setResult("dy now", i, dy_now);
|
|
setResult("dx now", i, dx_now);
|
|
setResult("actual speed", i, (dx_now/dy_now));
|
|
setResult("average speed", i, (sum_dx/sum_dy));
|
|
}
|
|
updateResults();
|
|
}
|