Re: Batch Analysis and ROIset saving
Posted by Nathaniel Ryckman on Apr 14, 2011; 6:19pm
URL: http://imagej.273.s1.nabble.com/Batch-Analysis-and-ROIset-saving-tp3684918p3684922.html
<quote author="Arne Seitz">
Hello Everyone,
I am trying to find an easy way to do a batch analysis of 10 sets of images. Each set contains a DNA and Cytoplasmic channel. I would like to load each image, segment on the DNA Image, get the measurements for the nuclear intensity on the DNA and Cytoplasmic images, then save out the ROIset.zip with a custom or new name for the .zip file, and also save out the measurements as a csv, txt, or excel file. I am relatively new to Image J and wanted to know if anyone has any advice on this.
It would also be great if I could save out an image of the ROI mask as well.
Any help or advice would be greatly appreciated.
Sincerely,
Sean Burke
Dear Sean,
please find below a macro which should more or less do what you were asking for.
It is creating a mask/ROI in images which contain the key word "cherry.tif" and then does the measurements in the other channel which name ended with GFP2.tif.
You probably will have to adapt the one or the other parameter.
Feel free to contact me again if you have further questions.
Cheers Arne
setBatchMode(true);
run("Set Measurements...", "area mean standard min integrated area_fraction display redirect=None decimal=3");
dir=getDirectory("Choose a Source Directory ");
savedir=getDirectory("Choose a Storage Directory");
list = getFileList(dir);
print (dir);
print (savedir);
for (i=1; i<list.length; i++) {
if (endsWith(list[i],"cherry.tif")){
ch1=dir+list[i];
ch2=replace(list[i],"cherry.tif","GFP2.tif");
stem=replace(list[i],"cherry.tif","");
nucmask=stem+"NucMask.tif";
open(ch1);
createObjects(savedir,stem);
rename(nucmask);
saveAs(nucmask,savedir+nucmask);
close();
open(ch2);
measureObjects(ch2);
selectWindow("Results");
savename=savedir+stem+"MeasureResults.xls";
saveAs("Text", savename);
if (isOpen("Results")) {
selectWindow("Results");
run("Close" );
}
savename=savedir+stem+"Roi.zip";
roiManager("Save",savename);
}
}
function createObjects(dir,stem){
run("Median...", "radius=2");
run("Convert to Mask");
run("Fill Holes");
rename(stem+"Nuc.tif");
saveAs(stem+"Nuc.tif",dir+stem+"Nuc.tif");
run("Watershed");
run("Analyze Particles...", "size=10-6000 circularity=0.00-1.00 show=Nothing exclude clear add");
}
function measureObjects(object){
open(object);
num=roiManager("count");
for (i=0;i<num;i++){
roiManager("select",i);
setAutoThreshold();
run("Measure");
}
close();
}
</quote>
More or LESS. Do you have any practical examples where this macro will actually work? He could use CellProfiler instead if this is all he wants to do. With CellProfiler, he won't have to bother coding.
The Watershed program is inherently flawed in my opinion.