Reset variables ?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
LP
Reply | Threaded
Open this post in threaded view
|

Reset variables ?

LP
Dear ImageJ community,

I'm writing a macro where I create multiple ROIs based on a threshold and then I want to select them all and combine them. And repeat this on multiple frames.

But unfortunately my macro only works for the first frame and then it says " Invalid index: 0 in line 12. roiManager("select" ,array <)>; "

Maybe I should reset the array variable ? But I didn't manage to do it...

So far I have the following:
___________________________________________
Stack.getDimensions(width,height,channels,slices,frames);
for (t=1; t<=frames; t++) {
                setAutoThreshold("Yen dark");
                run("Analyze Particles...", "size=4-Infinity exclude add slice"); //Creates multiple ROIS

                                array=newArray("0"); //in order to be able to select all the ROIS
                                for (i=1;i<roiManager("count");i++){
                                                array=Array.concat(array,i);
                                                }
                                               
                roiManager("select",array); // selects all the ROIS
                roiManager("Combine"); // Combines all the ROIS
                roiManager("Add");
               
                m = roiManager("count");
                roiManager("Select", m-1 ); // selects the last ROI
               
                roiManager("Measure"); // measures the newly created ROI
                roiManager("Deselect");
                roiManager("Delete");
               
                run("Next Slice [>]");
                }
__________________________________________

Any suggestion and help will be very appreciated.
Thank you very much for your help in advance,
LP
Reply | Threaded
Open this post in threaded view
|

Re: Reset variables ?

Krs5
Dear LP,

Not sure what the problem is but if I replace &quot; with " the macro runs fine.

Kees

-----Original Message-----
From: LP [mailto:[hidden email]]
Sent: 21 April 2017 20:27
To: [hidden email]
Subject: Reset variables ?

Dear ImageJ community,

I'm writing a macro where I create multiple ROIs based on a threshold and then I want to select them all and combine them. And repeat this on multiple frames.

But unfortunately my macro only works for the first frame and then it says "
Invalid index: 0 in line 12. roiManager("select" ,array <)>; "

Maybe I should reset the array variable ? But I didn't manage to do it...

So far I have the following:
___________________________________________
Stack.getDimensions(width,height,channels,slices,frames);
for (t=1; t<=frames; t++) {
                setAutoThreshold("Yen dark");
                run("Analyze Particles...", "size=4-Infinity exclude add slice"); //Creates multiple ROIS

                                array=newArray("0"); //in order to be able to select all the ROIS
                                for (i=1;i<roiManager(&quot;count&quot;);i++){
                                                array=Array.concat(array,i);
                                                }
                                               
                roiManager(&quot;select&quot;,array); // selects all the ROIS
                roiManager(&quot;Combine&quot;); // Combines all the ROIS
                roiManager(&quot;Add&quot;);
               
                m = roiManager(&quot;count&quot;);
                roiManager(&quot;Select&quot;, m-1 ); // selects the last ROI
               
                roiManager(&quot;Measure&quot;); // measures the newly created ROI
                roiManager(&quot;Deselect&quot;);
                roiManager(&quot;Delete&quot;);
               
                run(&quot;Next Slice [>]");
                }
__________________________________________

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/Reset-variables-tp5018587.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
LP
Reply | Threaded
Open this post in threaded view
|

Re: Reset variables ?

LP
Thank you.
I actually found my problem. I had to add "run("Select None");" because every time it kept thresholding in the ROI of the previous loop until there was nothing left to threshold.