Hi everyone, This is my first time to try to write a ImageJ micro, so sorry for the easy question I will ask, The situation is that I have a plate within which there are 8 wells (4 wells in one row, 2 rows together, in the attachment you can find one pic showing this pattern), one fruit fly is moving around in each well. I recorded these 8 flies at a certain frequency within observation time, so I got a bunch of images in the end (the only thing moving is flies) . I want to crop each well from the whole plate picture, then run the object tracking plugin to check locomotion of this fly. Since the pattern of 8 wells is constant, instead of manually cropping each well, I hope I can write a macro to "pattern crop" the 8 wells at the same time.
My main logic is by changing the x and y value of "makeRectangle" to crop consequential wells. (below is two trials hoping to crop the 4 wells in the first row, after success I would go on to add the second row) I tried first the most straight-forward way, and it works: run("Image Sequence...", "open=[C:\\Documents and Settings\\Wang Lab\\Desktop\\20110628D\\ZZ20100628D100] number=20 starting=1 increment=1 scale=100 file=[] or=[] sort"); makeRectangle(60+100*0, 120, 200, 200); run("Duplicate...", "title=0 duplicate range=3-20"); saveAs("tiff", "C:\\Documents and Settings\\Wang Lab\\Desktop\\TRY ZZ\\0"); run("Close"); makeRectangle(60+100*1, 120, 200, 200); run("Duplicate...", "title=1 duplicate range=3-20"); saveAs("tiff", "C:\\Documents and Settings\\Wang Lab\\Desktop\\TRY ZZ\\1"); run("Close"); makeRectangle(60+100*2, 120, 200, 200); run("Duplicate...", "title=2 duplicate range=3-20"); saveAs("tiff", "C:\\Documents and Settings\\Wang Lab\\Desktop\\TRY ZZ\\2"); run("Close"); makeRectangle(60+100*3, 120, 200, 200); run("Duplicate...", "title=3 duplicate range=3-20"); saveAs("tiff", "C:\\Documents and Settings\\Wang Lab\\Desktop\\TRY ZZ\\3"); run("Close"); Then I used "for" loop as follows: run("Image Sequence...", "open=[C:\\Documents and Settings\\Wang Lab\\Desktop\\20110628D\\ZZ20100628D100] number=20 starting=1 increment=1 scale=100 file=[] or=[] sort"); for (i=0; i<4; i++) { makeRectangle(60+100*i, 120, 200, 200); run("Duplicate...", "title="+i+" duplicate range=3-20"); saveAs("tiff", "C:\\Documents and Settings\\Wang Lab\\Desktop\\TRYZZ\\"+i+"); run("close"); } After I run this macro, an error pop out: ")" expected in line 6 <run>("close"); How can I correct this? Anyone can help me? Thanks a lot in advance! Zheng ZZ20100703F115 .bmp (148K) Download Attachment |
Hi Zheng,
correct the last 'saveAs' statement saveAs("tiff", "C:\\Documents and Settings\\WangLab\\Desktop\\TRYZZ\\"+i+"); to saveAs("tiff", "C:\\Documents and Settings\\WangLab\\Desktop\\TRYZZ\\"+i+""); or saveAs("tiff", "C:\\Documents and Settings\\WangLab\\Desktop\\TRYZZ\\"+i); peter On 28.07.2011 05:33, zezh1112 wrote: > Hi everyone, > > This is my first time to try to write a ImageJ micro, so sorry for the easy > question I will ask, > > The situation is that I have a plate within which there are 8 wells (4 wells > in one row, 2 rows together, in the attachment you can find one pic showing > this pattern), one fruit fly is moving around in each well. I recorded these > 8 flies at a certain frequency within observation time, so I got a bunch of > images in the end (the only thing moving is flies) . I want to crop each > well from the whole plate picture, then run the object tracking plugin to > check locomotion of this fly. Since the pattern of 8 wells is constant, > instead of manually cropping each well, I hope I can write a macro to > "pattern crop" the 8 wells at the same time. > > My main logic is by changing the x and y value of "makeRectangle" to crop > consequential wells. (below is two trials hoping to crop the 4 wells in the > first row, after success I would go on to add the second row) > > *I tried first the most straight-forward way, and it works:* > > run("Image Sequence...", "open=[C:\\Documents and Settings\\WangLab\\Desktop\\20110628D\\ZZ20100628D100] number=20 starting=1 increment=1 scale=100 file=[] or=[] sort"); > > > makeRectangle(60+100*0, 120, 200, 200); > > run("Duplicate...", "title=0 duplicate range=3-20"); > > saveAs("tiff", "C:\\Documents and Settings\\Wang Lab\\Desktop\\TRY ZZ\\0"); > > run("Close"); > > makeRectangle(60+100*1, 120, 200, 200); > > run("Duplicate...", "title=1 duplicate range=3-20"); > > saveAs("tiff", "C:\\Documents and Settings\\Wang Lab\\Desktop\\TRY ZZ\\1"); > > run("Close"); > > makeRectangle(60+100*2, 120, 200, 200); > > run("Duplicate...", "title=2 duplicate range=3-20"); > > saveAs("tiff", "C:\\Documents and Settings\\Wang Lab\\Desktop\\TRY ZZ\\2"); > > run("Close"); > > makeRectangle(60+100*3, 120, 200, 200); > > run("Duplicate...", "title=3 duplicate range=3-20"); > > saveAs("tiff", "C:\\Documents and Settings\\Wang Lab\\Desktop\\TRY ZZ\\3"); > > run("Close"); > > > *Then I used "for" loop as follows:* > > run("Image Sequence...", "open=[C:\\Documents and Settings\\WangLab\\Desktop\\20110628D\\ZZ20100628D100] number=20 starting=1 increment=1 > scale=100 file=[] or=[] sort"); > for (i=0; i<4; i++) { > makeRectangle(60+100*i, 120, 200, 200); > run("Duplicate...", "title="+i+" duplicate range=3-20"); > saveAs("tiff", "C:\\Documents and Settings\\WangLab\\Desktop\\TRYZZ\\"+i+"); > run("close"); > } > > After I run this macro, an error pop out: > ")" expected in line 6 > <run>("close"); > > How can I correct this? Anyone can help me? Thanks a lot in advance! > > Zheng > > > -- > View this message in context: http://imagej.588099.n2.nabble.com/pattern-cropping-tp6628531p6628531.html > Sent from the ImageJ mailing list archive at Nabble.com. > |
Hi Peter,
Sorry for the delay! Thanks so much for helping me! It works! I would try to be more careful about the completeness next time :) Best, Zheng 2011/7/27 Peter Haub <[hidden email]> > Hi Zheng, > > correct the last 'saveAs' statement > > saveAs("tiff", "C:\\Documents and Settings\\WangLab\\Desktop\\** > TRYZZ\\"+i+"); > > to > > saveAs("tiff", "C:\\Documents and Settings\\WangLab\\Desktop\\** > TRYZZ\\"+i+""); > > or > > saveAs("tiff", "C:\\Documents and Settings\\WangLab\\Desktop\\** > TRYZZ\\"+i); > > peter > > > > On 28.07.2011 05:33, zezh1112 wrote: > >> Hi everyone, >> >> This is my first time to try to write a ImageJ micro, so sorry for the >> easy >> question I will ask, >> >> The situation is that I have a plate within which there are 8 wells (4 >> wells >> in one row, 2 rows together, in the attachment you can find one pic >> showing >> this pattern), one fruit fly is moving around in each well. I recorded >> these >> 8 flies at a certain frequency within observation time, so I got a bunch >> of >> images in the end (the only thing moving is flies) . I want to crop each >> well from the whole plate picture, then run the object tracking plugin to >> check locomotion of this fly. Since the pattern of 8 wells is constant, >> instead of manually cropping each well, I hope I can write a macro to >> "pattern crop" the 8 wells at the same time. >> >> My main logic is by changing the x and y value of "makeRectangle" to crop >> consequential wells. (below is two trials hoping to crop the 4 wells in >> the >> first row, after success I would go on to add the second row) >> >> *I tried first the most straight-forward way, and it works:* >> >> run("Image Sequence...", "open=[C:\\Documents and >> Settings\\WangLab\\Desktop\\**20110628D\\ZZ20100628D100] number=20 >> starting=1 increment=1 scale=100 file=[] or=[] sort"); >> >> >> >> makeRectangle(60+100*0, 120, 200, 200); >> >> run("Duplicate...", "title=0 duplicate range=3-20"); >> >> saveAs("tiff", "C:\\Documents and Settings\\Wang Lab\\Desktop\\TRY >> ZZ\\0"); >> >> run("Close"); >> >> makeRectangle(60+100*1, 120, 200, 200); >> >> run("Duplicate...", "title=1 duplicate range=3-20"); >> >> saveAs("tiff", "C:\\Documents and Settings\\Wang Lab\\Desktop\\TRY >> ZZ\\1"); >> >> run("Close"); >> >> makeRectangle(60+100*2, 120, 200, 200); >> >> run("Duplicate...", "title=2 duplicate range=3-20"); >> >> saveAs("tiff", "C:\\Documents and Settings\\Wang Lab\\Desktop\\TRY >> ZZ\\2"); >> >> run("Close"); >> >> makeRectangle(60+100*3, 120, 200, 200); >> >> run("Duplicate...", "title=3 duplicate range=3-20"); >> >> saveAs("tiff", "C:\\Documents and Settings\\Wang Lab\\Desktop\\TRY >> ZZ\\3"); >> >> run("Close"); >> >> >> *Then I used "for" loop as follows:* >> >> run("Image Sequence...", "open=[C:\\Documents and >> Settings\\WangLab\\Desktop\\**20110628D\\ZZ20100628D100] number=20 >> starting=1 increment=1 >> >> scale=100 file=[] or=[] sort"); >> for (i=0; i<4; i++) { >> makeRectangle(60+100*i, 120, 200, 200); >> run("Duplicate...", "title="+i+" duplicate range=3-20"); >> saveAs("tiff", "C:\\Documents and Settings\\WangLab\\Desktop\\** >> TRYZZ\\"+i+"); >> >> run("close"); >> } >> >> After I run this macro, an error pop out: >> ")" expected in line 6 >> <run>("close"); >> >> How can I correct this? Anyone can help me? Thanks a lot in advance! >> >> Zheng >> >> >> -- >> View this message in context: http://imagej.588099.n2.** >> nabble.com/pattern-cropping-**tp6628531p6628531.html<http://imagej.588099.n2.nabble.com/pattern-cropping-tp6628531p6628531.html> >> Sent from the ImageJ mailing list archive at Nabble.com. >> >> |
In reply to this post by Peter Haub
After successfully cropping 8 wells from a folder (in the first post I just
aimed to crop 4 wells in first row, now I add another variant j to include second row), I moved on to make it easier for batch process: select a folder with raw data, pattern crop, create 8 subfolders in the same folder with raw data, the cropped images are saved in these 8 subfolders. This is what I did: *sdir = getDirectory("choose source directory "); run("Image Sequence...", "open=sdir number=20 starting=1 increment=1 scale=100 file=[] or=[] sort"); for (i=0; i<4; i++) { for (j=0; j<2; j++) { makeRectangle(78+251*i, 349+303*j, 216, 216); well ="well-"+i+j + File.separator; ddir = sdir+well; File.makeDirectory(ddir); run("Duplicate...", "title="+j+1+"_"+i+1+" duplicate range=6- 20"); run("Image Sequence... ", "format=TIFF name= ["+well+"] start=0 digits=4 save=["+ddir+"]"); run("Close"); } }* The problem is there are 5 subfolders created, with name such as "well-0" to "well-4", inside the cropped images respond to 0-0,1-0,2-0,3-0,3-1, if I name the 8 wells by "i-j" format: 0-0 1-0 2-0 3-0 0-1 1-1 2-1 3-1 My guess is imageJ read my macro "+i+j" in "*well ="well-"+i+j + File.separator;*" as a math addition, so 0-0 go into fldler well-0, 1-0 go into folder well-1, and so on, because 1-0 and 0-1' addition result are the same (0+1=1+0), somehow imageJ skip 0-1, the same for 1-1 and 2-1 were skipped. How can I fix this? Thanks again for the gracious help! Zheng 2011/7/27 Peter Haub <[hidden email]> > Hi Zheng, > > correct the last 'saveAs' statement > > saveAs("tiff", "C:\\Documents and Settings\\WangLab\\Desktop\\** > TRYZZ\\"+i+"); > > to > > saveAs("tiff", "C:\\Documents and Settings\\WangLab\\Desktop\\** > TRYZZ\\"+i+""); > > or > > saveAs("tiff", "C:\\Documents and Settings\\WangLab\\Desktop\\** > TRYZZ\\"+i); > > peter > > > > On 28.07.2011 05:33, zezh1112 wrote: > >> Hi everyone, >> >> This is my first time to try to write a ImageJ micro, so sorry for the >> easy >> question I will ask, >> >> The situation is that I have a plate within which there are 8 wells (4 >> wells >> in one row, 2 rows together, in the attachment you can find one pic >> showing >> this pattern), one fruit fly is moving around in each well. I recorded >> these >> 8 flies at a certain frequency within observation time, so I got a bunch >> of >> images in the end (the only thing moving is flies) . I want to crop each >> well from the whole plate picture, then run the object tracking plugin to >> check locomotion of this fly. Since the pattern of 8 wells is constant, >> instead of manually cropping each well, I hope I can write a macro to >> "pattern crop" the 8 wells at the same time. >> >> My main logic is by changing the x and y value of "makeRectangle" to crop >> consequential wells. (below is two trials hoping to crop the 4 wells in >> the >> first row, after success I would go on to add the second row) >> >> *I tried first the most straight-forward way, and it works:* >> >> run("Image Sequence...", "open=[C:\\Documents and >> Settings\\WangLab\\Desktop\\**20110628D\\ZZ20100628D100] number=20 >> starting=1 increment=1 scale=100 file=[] or=[] sort"); >> >> >> >> makeRectangle(60+100*0, 120, 200, 200); >> >> run("Duplicate...", "title=0 duplicate range=3-20"); >> >> saveAs("tiff", "C:\\Documents and Settings\\Wang Lab\\Desktop\\TRY >> ZZ\\0"); >> >> run("Close"); >> >> makeRectangle(60+100*1, 120, 200, 200); >> >> run("Duplicate...", "title=1 duplicate range=3-20"); >> >> saveAs("tiff", "C:\\Documents and Settings\\Wang Lab\\Desktop\\TRY >> ZZ\\1"); >> >> run("Close"); >> >> makeRectangle(60+100*2, 120, 200, 200); >> >> run("Duplicate...", "title=2 duplicate range=3-20"); >> >> saveAs("tiff", "C:\\Documents and Settings\\Wang Lab\\Desktop\\TRY >> ZZ\\2"); >> >> run("Close"); >> >> makeRectangle(60+100*3, 120, 200, 200); >> >> run("Duplicate...", "title=3 duplicate range=3-20"); >> >> saveAs("tiff", "C:\\Documents and Settings\\Wang Lab\\Desktop\\TRY >> ZZ\\3"); >> >> run("Close"); >> >> >> *Then I used "for" loop as follows:* >> >> run("Image Sequence...", "open=[C:\\Documents and >> Settings\\WangLab\\Desktop\\**20110628D\\ZZ20100628D100] number=20 >> starting=1 increment=1 >> >> scale=100 file=[] or=[] sort"); >> for (i=0; i<4; i++) { >> makeRectangle(60+100*i, 120, 200, 200); >> run("Duplicate...", "title="+i+" duplicate range=3-20"); >> saveAs("tiff", "C:\\Documents and Settings\\WangLab\\Desktop\\** >> TRYZZ\\"+i+"); >> >> run("close"); >> } >> >> After I run this macro, an error pop out: >> ")" expected in line 6 >> <run>("close"); >> >> How can I correct this? Anyone can help me? Thanks a lot in advance! >> >> Zheng >> >> >> -- >> View this message in context: http://imagej.588099.n2.** >> nabble.com/pattern-cropping-**tp6628531p6628531.html<http://imagej.588099.n2.nabble.com/pattern-cropping-tp6628531p6628531.html> >> Sent from the ImageJ mailing list archive at Nabble.com. >> >> |
try
well ="well-"+ (i*2)+j + File.separator; peter On 30.07.2011 04:04, Zheng Zeng wrote: > After successfully cropping 8 wells from a folder (in the first post I just > aimed to crop 4 wells in first row, now I add another variant j to include > second row), I moved on to make it easier for batch process: > select a folder with raw data, pattern crop, create 8 subfolders in the > same folder with raw data, the cropped images are saved in these 8 > subfolders. > > This is what I did: > > *sdir = getDirectory("choose source directory "); > run("Image Sequence...", "open=sdir number=20 starting=1 increment=1 > > scale=100 file=[] or=[] sort"); > for (i=0; i<4; i++) { > for (j=0; j<2; j++) { > makeRectangle(78+251*i, 349+303*j, 216, 216); > well ="well-"+i+j + File.separator; > ddir = sdir+well; > File.makeDirectory(ddir); > run("Duplicate...", "title="+j+1+"_"+i+1+" duplicate range=6- > > 20"); > run("Image Sequence... ", "format=TIFF name= ["+well+"] > start=0 digits=4 save=["+ddir+"]"); > run("Close"); > } > }* > > The problem is there are 5 subfolders created, with name such as "well-0" to > "well-4", inside the cropped images respond to 0-0,1-0,2-0,3-0,3-1, if I > name the 8 wells by "i-j" format: > > 0-0 1-0 2-0 3-0 > 0-1 1-1 2-1 3-1 > > My guess is imageJ read my macro "+i+j" in "*well ="well-"+i+j + > File.separator;*" as a math addition, so 0-0 go into fldler well-0, 1-0 go > into folder well-1, and so on, because 1-0 and 0-1' addition result are the > same (0+1=1+0), somehow imageJ skip 0-1, the same for 1-1 and 2-1 were > skipped. > > How can I fix this? Thanks again for the gracious help! > > Zheng > > 2011/7/27 Peter Haub <[hidden email]> > >> Hi Zheng, >> >> correct the last 'saveAs' statement >> >> saveAs("tiff", "C:\\Documents and Settings\\WangLab\\Desktop\\** >> TRYZZ\\"+i+"); >> >> to >> >> saveAs("tiff", "C:\\Documents and Settings\\WangLab\\Desktop\\** >> TRYZZ\\"+i+""); >> >> or >> >> saveAs("tiff", "C:\\Documents and Settings\\WangLab\\Desktop\\** >> TRYZZ\\"+i); >> >> peter >> >> >> >> On 28.07.2011 05:33, zezh1112 wrote: >> >>> Hi everyone, >>> >>> This is my first time to try to write a ImageJ micro, so sorry for the >>> easy >>> question I will ask, >>> >>> The situation is that I have a plate within which there are 8 wells (4 >>> wells >>> in one row, 2 rows together, in the attachment you can find one pic >>> showing >>> this pattern), one fruit fly is moving around in each well. I recorded >>> these >>> 8 flies at a certain frequency within observation time, so I got a bunch >>> of >>> images in the end (the only thing moving is flies) . I want to crop each >>> well from the whole plate picture, then run the object tracking plugin to >>> check locomotion of this fly. Since the pattern of 8 wells is constant, >>> instead of manually cropping each well, I hope I can write a macro to >>> "pattern crop" the 8 wells at the same time. >>> >>> My main logic is by changing the x and y value of "makeRectangle" to crop >>> consequential wells. (below is two trials hoping to crop the 4 wells in >>> the >>> first row, after success I would go on to add the second row) >>> >>> *I tried first the most straight-forward way, and it works:* >>> >>> run("Image Sequence...", "open=[C:\\Documents and >>> Settings\\WangLab\\Desktop\\**20110628D\\ZZ20100628D100] number=20 >>> starting=1 increment=1 scale=100 file=[] or=[] sort"); >>> >>> >>> >>> makeRectangle(60+100*0, 120, 200, 200); >>> >>> run("Duplicate...", "title=0 duplicate range=3-20"); >>> >>> saveAs("tiff", "C:\\Documents and Settings\\Wang Lab\\Desktop\\TRY >>> ZZ\\0"); >>> >>> run("Close"); >>> >>> makeRectangle(60+100*1, 120, 200, 200); >>> >>> run("Duplicate...", "title=1 duplicate range=3-20"); >>> >>> saveAs("tiff", "C:\\Documents and Settings\\Wang Lab\\Desktop\\TRY >>> ZZ\\1"); >>> >>> run("Close"); >>> >>> makeRectangle(60+100*2, 120, 200, 200); >>> >>> run("Duplicate...", "title=2 duplicate range=3-20"); >>> >>> saveAs("tiff", "C:\\Documents and Settings\\Wang Lab\\Desktop\\TRY >>> ZZ\\2"); >>> >>> run("Close"); >>> >>> makeRectangle(60+100*3, 120, 200, 200); >>> >>> run("Duplicate...", "title=3 duplicate range=3-20"); >>> >>> saveAs("tiff", "C:\\Documents and Settings\\Wang Lab\\Desktop\\TRY >>> ZZ\\3"); >>> >>> run("Close"); >>> >>> >>> *Then I used "for" loop as follows:* >>> >>> run("Image Sequence...", "open=[C:\\Documents and >>> Settings\\WangLab\\Desktop\\**20110628D\\ZZ20100628D100] number=20 >>> starting=1 increment=1 >>> >>> scale=100 file=[] or=[] sort"); >>> for (i=0; i<4; i++) { >>> makeRectangle(60+100*i, 120, 200, 200); >>> run("Duplicate...", "title="+i+" duplicate range=3-20"); >>> saveAs("tiff", "C:\\Documents and Settings\\WangLab\\Desktop\\** >>> TRYZZ\\"+i+"); >>> >>> run("close"); >>> } >>> >>> After I run this macro, an error pop out: >>> ")" expected in line 6 >>> <run>("close"); >>> >>> How can I correct this? Anyone can help me? Thanks a lot in advance! >>> >>> Zheng >>> >>> >>> -- >>> View this message in context: http://imagej.588099.n2.** >>> nabble.com/pattern-cropping-**tp6628531p6628531.html<http://imagej.588099.n2.nabble.com/pattern-cropping-tp6628531p6628531.html> >>> Sent from the ImageJ mailing list archive at Nabble.com. >>> >>> |
Free forum by Nabble | Edit this page |