Login  Register

Re: Loop for ROIs

Posted by Brandon Hurr on Jan 08, 2017; 3:55am
URL: http://imagej.273.s1.nabble.com/Loop-for-ROIs-tp5017852p5017853.html

Could you provide an image? I don't get the same names as you for the
channels so I can't replicate your process very easily.

More generally, it looks like you are splitting the image into 3 channels
(C1,C2,C3; I get (red), (green), (blue)), implementing a threshold in a
single channel to find your ROIs, copying those ROIs from each channel and
then merging those.

My suggestion would be something like this:

input="C:\\Users\\"
output=input+"zoutput\\" // your output folder needs to exist
list=getFileList(input);

setBatchMode(false); // set this once outside of the loop

for (i=0;i<list.length;i++) {

// open file

open(input+list[i]);

// get window name

name = getTitle();

selectWindow(name);

// duplicate window for segmentation and finding ROIs

run("Duplicate...", "segment");

run("Split Channels");
setAutoThreshold("Percentile dark");
run("Convert to Mask");

// get ROIs (cells?)

run("Analyze Particles...", "size=100-Infinity show=Outlines display
exclude clear include add");

// close split channels

[ insert code here for that]

// select the original window again

selectWindow(name);

// loop through ROIs and save
for (m = 0; m < roiManager("count"); m++){

selectWindow(name);
roiManager("Select", m);

// duplicate ROI for saving
run("Duplicate...", "saveout");
run("Clear Outside");

// save out individual cell

saveAs("tiff", output + name + m);

run("Close"); // close saved window


} // end ROI loop

selectWindow(name);

run("Close"); // close original window

} // end image loop

// end macro

This way you only duplicate once from the original image for every ROI.
Less splitting and whatnot is always a good thing, because it's hard to
keep track of those things.

HTH,
B



On Sat, Jan 7, 2017 at 11:00 AM, LP <[hidden email]> wrote:

> Dear ImageJ community,
>
> I'm trying to make a macro that from picture with multiple cells creates
> one
> file per cell based on a threshold.
>
> However I don't know how to make a loop for the ROIs.
> So far I have this:
> ______________________________________________
> input="C:\\Users\\"
> output=input+"zoutput\\"
> list=getFileList(input);
>
> for(i=0;i<list.length;i++){
>     open(input+list[i]);
>     name = File.nameWithoutExtension();
>     setBatchMode(false);
>
> selectWindow(name + ".tif");
> run("Split Channels");
> selectWindow("C2-" + name + ".tif");
> run("Duplicate...", " ");
> setAutoThreshold("Percentile dark");
> run("Convert to Mask");
> run("Analyze Particles...", "size=100-Infinity show=Outlines
> display exclude clear include add");
>
> selectWindow("C1-" + name + ".tif");
> roiManager("Select", <b>0*);
> run("Duplicate...", " ");
> selectWindow("C2-" + name + ".tif");
> roiManager("Select", *0*);
> run("Duplicate...", " ");
> selectWindow("C3-" + name + ".tif");
> roiManager("Select", *0*);
> run("Duplicate...", " ");
>
> run("Merge Channels...", "c1=C1-"+name+"-1.tif c2=C2-"+name+"-2.tif
> c3=C3-"+name+"-1.tif create keep");
> Stack.setDisplayMode("color");
> roiManager("Select", *0*);
> run("Clear Outside", "stack");
> saveAs("tiff", output + name + "*0*");
>
> close();
> selectWindow("C3-" + name + "-1.tif");
> close();
> selectWindow("C2-" + name + "-2.tif");
> close();
> selectWindow("C1-" + name + "-1.tif");
> close();
> selectWindow("Drawing of C2-" + name +"-1.tif");
> close();
> _____________________________________________________________
>
>
> So I'd like to replace all the *0* by a variable.
> I tried to use
> i= roiManager("index");
>
> But with no success.
>
> Any suggestion and help will be very appreciated.
> Thank you very much for your help in advance,
> LP
>
>
>
> --
> View this message in context: http://imagej.1557.x6.nabble.
> com/Loop-for-ROIs-tp5017852.html
> Sent from the ImageJ mailing list archive at Nabble.com.
>
> --
> ImageJ mailing list: http://imagej.nih.gov/ij/list.html
>

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html