Hello, I made a script that is outlining my embryos and scanning mean intensity of the flow inside several ROIs. It supposes to pick up “.tif” files from folders and save them to a subfolder with the same name automatically, but the window “Apply changes to N selections?” keeps poping up from ROI manager each second file. Can someone help me out with that please?
/*
* Macro template to process multiple images in a folder
*/
#@ File (label = "Input directory", style = "directory") input
#@ File (label = "Output directory", style = "directory") output
#@ String (label = "File suffix", value = ".tif") suffix
// See also Process_Folder.py for a version of this code
// in the Python scripting language.
processFolder(input);
// function to scan folders/subfolders/files to find files with correct suffix
function processFolder(input) {
list = getFileList(input);
list = Array.sort(list);
for (i = 0; i < list.length; i++) {
if(File.isDirectory(input + File.separator + list[i]))
processFolder(input + File.separator + list[i]);
if(endsWith(list[i], suffix))
processFile(input, output, list[i]);
}
}
function processFile(input, output, file) {
// Do the processing here by adding your own code.
// Leave the print statements until things work, then remove them.
//Angle measurement
setBatchMode(true);
open(input);
selectImage(1);
imagename=File.nameWithoutExtension;
File.makeDirectory(output +File.separator+imagename);
run("Deinterleave", "how=3 keep");
close();
selectImage(2);
rename("#1");
selectImage(3);
rename("#2");
run("Merge Channels...", "c1=#1 c2=#2 create");
run("Re-order Hyperstack ...", "channels=[Frames (t)] slices=[Channels (c)] frames=[Slices (z)]");
rename("Hyperstack");
run("Z Project...", "projection=[Max Intensity] all");
run("8-bit");
rename("Zstack");
run("Z Project...", "projection=[Max Intensity]");
rename("Zstack_1");
run("Duplicate...", " ");
run("Gaussian Blur...", "sigma=2");
run("Auto Threshold", "method=Triangle white");
//cycle for finding ROI
checker = 0;
doWand(checker, checker);
run("Measure");
n =0;
a1 = getResult("Area", n);
b=pow(0.1, 7);
areaMEASURE = 5.0195308 * b;
while(abs(areaMEASURE - a1) / areaMEASURE > 0.2)
{
doWand(checker/2 + checker, checker);
checker = checker +50;
n=n+1;
run("Measure");
a1 = getResult("Area", n);
}
run("ROI Manager...");
roiManager("Add");
roiManager("Select", 0);
run("Fit Ellipse");
roiManager("Add");
roiManager("Select", 1);
roiManager("Measure");
roiManager("Deselect");
roiManager("Set Color", "yellow");
roiManager("Set Line Width", 20);
selectImage("Zstack_1");
roiManager("Select", 0);
roiManager("Draw");
//Second half
run("Clear Results");
selectImage("Zstack");
frames1=nSlices;
meanint = 0;
roiManager("Select", 1);
getSelectionCoordinates(xpoints, ypoints);
coordrrX=xpoints;
coordrrY=ypoints;
if(coordrrX[0]<coordrrX[coordrrX.length/2])
{
Array.rotate(coordrrX, round(coordrrX.length/2));
Array.rotate(coordrrY, round(coordrrX.length/2));
}
Array.print(coordrrX);
Array.print(coordrrY);
makeSelection(1, coordrrX, coordrrY);
run("Scale... ", "x=0.1 y=0.1");
run("Rotate...", " angle=90");
setSelectionLocation(coordrrX[round(coordrrX.length/4)], coordrrY[0]);
run("Measure Stack...");
for(i=0;i<frames1;i++)
{
meanint = meanint + getResult("Mean", i);
}
meanint=meanint/frames1;
print("meannt= " + meanint);
// second half
run("Clear Results");
makeSelection(1, coordrrX, coordrrY);
run("Scale... ", "x=0.1 y=0.1");
run("Rotate...", " angle=90");
setSelectionLocation(coordrrX[10], coordrrY[0]);
run("Measure Stack...");
counter = 0;
for(i=0;i<frames1;i++)
{
counter = counter + getResult("Mean", i);
}
counter=counter/frames1;
print("counter= " + counter);
if ( counter > meanint)
{
print("Anterior");
for(i=0; i<=3;i++)
{
if (i==3)
{
selectImage("Zstack");
fitx= Array.getSequence(nSlices);
fity= newArray(nSlices);
makeSelection(1, coordrrX, coordrrY);
run("Scale... ", "x=0.40 y=0.50");
run("Rotate...", " angle=90");
setSelectionLocation(coordrrX[round(coordrrX.length*0.45)], coordrrY[round(0.65*coordrrY.length)]);
run("Clear Results");
run("Measure Stack...");
fity= Table.getColumn("Mean", "Results");
Fit.doFit("8th Degree Polynomial", fitx, fity);
Plot.create("Starting point "+ i, "x", "Mean");
Plot.add("Line ", Table.getColumn("Mean", "Results"));
Plot.setStyle(0, "blue,#a0a0ff,1.0,Line");
Plot.show();
save(output +File.separator+imagename+ File.separator + "Start point"+ i+"_.tif");
Fit.plot;
save(output +File.separator+imagename+ File.separator + i + "_fit.tif");
}
else{
selectImage("Zstack");
fitx= Array.getSequence(nSlices);
fity= newArray(nSlices);
makeSelection(1, coordrrX, coordrrY);
getSelectionBounds(xRECT, yRECT, widthRECT, heightRECT);
makeRotatedRectangle(xRECT, yRECT, xRECT+widthRECT, yRECT, heightRECT);
run("Scale... ", "x=0.40 y=0.25");
run("Rotate...", " angle=90");
setSelectionLocation(coordrrX[round(coordrrX.length/4)+i]-heightRECT*0.25, coordrrY[round(0.60*coordrrY.length)]);
run("Clear Results");
run("Measure Stack...");
roiManager("Add", "ffff00", 0);
fity= Table.getColumn("Mean", "Results");
Fit.doFit("8th Degree Polynomial", fitx, fity);
Plot.create("End point "+ i, "x", "Mean");
Plot.add("Line ", Table.getColumn("Mean", "Results"));
Plot.setStyle(0, "blue,#a0a0ff,1.0,Line");
Plot.show();
save(output +File.separator+imagename+ File.separator + "End points "+ i+"_.tif");
Fit.plot;
save(output +File.separator+imagename+ File.separator + i + "_fit.tif");
}
}
}
else
{
for(i=0; i<=3;i++)
{
if (i==3)
{
selectImage("Zstack");
fitx= Array.getSequence(nSlices);
fity= newArray(nSlices);
makeSelection(1, coordrrX, coordrrY);
run("Scale... ", "x=0.40 y=0.50");
run("Rotate...", " angle=90");
setSelectionLocation(coordrrX[round(coordrrX.length*0.2)], coordrrY[round(0.83*coordrrY.length)]);
run("Clear Results");
run("Measure Stack...");
fity= Table.getColumn("Mean", "Results");
roiManager("Add", "ffff00", 0);
Fit.doFit("8th Degree Polynomial", fitx, fity);
Plot.create("Starting point "+ i, "x", "Mean");
Plot.add("Line ", Table.getColumn("Mean", "Results"));
Plot.setStyle(0, "blue,#a0a0ff,1.0,Line");
Plot.show();
save(output +File.separator+imagename+ File.separator + "Start point "+ i+"_.tif");
Fit.plot;
save(output +File.separator+imagename+ File.separator + i + "_fit.tif");
}
else{
selectImage("Zstack");
fitx= Array.getSequence(nSlices);
fity= newArray(nSlices);
makeSelection(1, coordrrX, coordrrY);
getSelectionBounds(xRECT, yRECT, widthRECT, heightRECT);
makeRotatedRectangle(xRECT, yRECT, xRECT+widthRECT, yRECT, heightRECT);
run("Scale... ", "x=0.40 y=0.25");
run("Rotate...", " angle=90");
setSelectionLocation(coordrrX[round(coordrrX.length/4)-i], coordrrY[round(0.6*coordrrY.length)]);
run("Clear Results");
run("Measure Stack...");
fity= Table.getColumn("Mean", "Results");
roiManager("Add", "ffff00", 0);
Fit.doFit("8th Degree Polynomial", fitx, fity);
Plot.create("End points "+ i, "x", "Mean");
Plot.add("Line ", Table.getColumn("Mean", "Results"));
Plot.setStyle(0, "blue,#a0a0ff,1.0,Line");
Plot.show();
save(output +File.separator+imagename+ File.separator + "End points "+ i+"_.tif");
Fit.plot;
save(output +File.separator+imagename+ File.separator + i + "_fit.tif");
}
}
}
selectImage("Zstack_1");
rename(File.nameWithoutExtension + "___1");
save(output +File.separator+imagename+ File.separator + File.nameWithoutExtension + "___1.tif");
selectImage("Zstack");
rename(File.nameWithoutExtension + "___2");
save(output +File.separator+imagename+ File.separator + File.nameWithoutExtension + "___2.tif");
//selectImage("PLOT");
//save(output);
run("Clear Results");
run("Close All");
roiManager("deselect");
roiManager("delete");
close("ROI manager");
print("Processing: " + input + File.separator + file);
print("Saving to: " + output);
}