First time macro: combine Do loop with recorded macro

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

First time macro: combine Do loop with recorded macro

Alex Valm
Hello,
I am trying to combine a do ... while loop with a macro that I have  
recorded and am having trouble.
What I would like to do is take an image, say 1000 x 1000 pixels, and  
chop it up into smaller square ROIs, each 100 x 100 pixels, starting  
from the top left of the image and moving down to the bottom right.  I  
then want to threshold each ROI, then put all the ROIs together in a  
stack.

I started by opening my image, then recording the following macro for  
the first ROI, using Edit>Selection>Specify...

run("Specify...", "width=100 height=100 x=0 y=0");
run("Duplicate...", "title=testlargeareasquare-1.tif");
setAutoThreshold("IsoData");
//run("Threshold...");
setAutoThreshold("IsoData");
run("Convert to Mask");

This gives me a 100x100 pixel ROI from the top left corner, then  
duplicates and segments it.  Great.   Now I tried editing the recorded  
macro so that I could have it sequentially perform this on 100x100  
ROIs across the whole length and height of the image with the following:

x=0;
y=0;
do {
run("Specify...", "width=100 height=100 x y");
run("Duplicate...", "title=testlargeareasquare-1.tif");
setAutoThreshold("IsoData");
//run("Threshold...");
setAutoThreshold("IsoData");
run("Convert to Mask");
x=x+100;
y=y+100;
}  while (x<=1000);
while (y<=1000);

This did not work at all.  It still only gives me one ROI:  the first  
top left.
Thank you in advance for any help you can give!!!!

Best,
Alex
Reply | Threaded
Open this post in threaded view
|

Re: First time macro: combine Do loop with recorded macro

Mario Faretta
Dear Alex,
a couple of things:
- when you want to specify variables you must put them out of quotes
(i.e.
run("Specify...", "width=100 height=100 x y");  is not correct but
run("Specify...", "width=100 height=100 x="+x+" y="+y);
)
- at each loop remember to reselect the starting image otherwise the
duplicate command will act on the last active one
- if I understand correctly you want to build a sort of square grid: in
this case you need two nested loops
I copied below a corrected version of your macro
Hope it helps
Mario

name="original" /////put in quotes the name of your starting image
y=0;
do {
x=0;
do {
selectWindow(name);
run("Specify...", "width=100 height=100 x="+x+"  y="+y);
run("Duplicate...", "title=testlargeareasquare-1.tif");
setAutoThreshold("IsoData");
//run("Threshold...");
setAutoThreshold("IsoData");
run("Convert to Mask");
x=x+100;
}  while (x<=1000);
y=y+100;
}while (y<=1000);

Alex Valm wrote:

> Hello,
> I am trying to combine a do ... while loop with a macro that I have
> recorded and am having trouble.
> What I would like to do is take an image, say 1000 x 1000 pixels, and
> chop it up into smaller square ROIs, each 100 x 100 pixels, starting
> from the top left of the image and moving down to the bottom right.  I
> then want to threshold each ROI, then put all the ROIs together in a
> stack.
>
> I started by opening my image, then recording the following macro for
> the first ROI, using Edit>Selection>Specify...
>
> run("Specify...", "width=100 height=100 x=0 y=0");
> run("Duplicate...", "title=testlargeareasquare-1.tif");
> setAutoThreshold("IsoData");
> //run("Threshold...");
> setAutoThreshold("IsoData");
> run("Convert to Mask");
>
> This gives me a 100x100 pixel ROI from the top left corner, then
> duplicates and segments it.  Great.   Now I tried editing the recorded
> macro so that I could have it sequentially perform this on 100x100
> ROIs across the whole length and height of the image with the following:
>
> x=0;
> y=0;
> do {
> run("Specify...", "width=100 height=100 x y");
> run("Duplicate...", "title=testlargeareasquare-1.tif");
> setAutoThreshold("IsoData");
> //run("Threshold...");
> setAutoThreshold("IsoData");
> run("Convert to Mask");
> x=x+100;
> y=y+100;
> }  while (x<=1000);
> while (y<=1000);
>
> This did not work at all.  It still only gives me one ROI:  the first
> top left.
> Thank you in advance for any help you can give!!!!
>
> Best,
> Alex


--
Mario Faretta
Department of Experimental Oncology
European Institute of Oncology
c/o IFOM-IEO Campus for Oncogenomics
via Adamello 16
20139 Milan
Italy
Phone: ++39-02574303054
email: [hidden email]
http://www.ifom-ieo-campus.it