Posted by
gnelson on
URL: http://imagej.273.s1.nabble.com/Batch-process-images-with-specific-ROis-tp5021442p5021459.html
Hi Franco,
Apologies, I was rushing yesterday and literally just hacked the code from
my own macro, so variables were set wrongly etc. I've adjusted your macro
below. It uses the binary mask to find the objects, then analyses those
objects on the original image then saves the ROI list, the analysis and the
binary image. I have set the measurements at the beginning to include a few
stats and the image label- this means you could potentially keep saving all
the output to one csv (since you can identify which image each measurement
comes from), which I find easier for analysis later. To do this, just
change the csv name to a fixed name rather than the filename, and don't
clear the results after each loop. Obviously you need to change the stats
to the ones you want or don't want too.
You don't say if the images are a single channel or not. If they are
multichannel and there is a specific channel you wish to analyse with the
ROIs you have made, then you need to add a line to switch to that channel.
Since your duplicate command is empty, I assume they are single channel.
I've tried to keep the rest of your code as you had it, so I hope you can
see how it works.
Glyn
#@File(label = "Input directory", style = "directory") input
#@File(label = "Output directory", style = "directory") output
#@String(label = "File suffix", value = ".tif") suffix
processFolder(input);
//specify the measurements you want and the image label (plus ROI
co-ordinates)
run("Set Measurements...", "area mean standard integrated limit display
redirect=None decimal=3");
// function to scan folders/subfolders/files to find files with correct
suffix
function processFolder(input) {
list = getFileList(input);
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) {
setBatchMode(true);
run("Bio-Formats", "open=[" + input + "/" + file +"] autoscale
color_mode=Default rois_import=[ROI manager] view=Hyperstack
stack_order=XYCZT");
id = getImageID(); // get original image id
run("Duplicate...", " ");
run("8-bit");
run("Subtract Background...", "rolling=50");
run("Median...", "radius=1.5");
//save(output + "/Processed_filter_" + file);
setAutoThreshold("Otsu dark");
//run("Threshold...");
run("Create Mask");
run("Fill Holes");
run("Analyze Particles...", "add");
rename("mask");
selectImage(id);
roiManager("Measure");
// save ROIs for current image
roiManager("Deselect");
roiManager("Save", output+ "/" + file + "_Amyloid_ROI.zip"); //
saves Rois zip file
roiManager("Deselect");
roiManager("Delete");
saveAs("Results", output+ "/" + file + "_Amyloid_Results.csv") ;
run("Clear Results");
selectImage("mask");
save(output + "/Processed_filter_" + file);
}
--
Sent from:
http://imagej.1557.x6.nabble.com/--
ImageJ mailing list:
http://imagej.nih.gov/ij/list.html