Hello all,
After a couple of years of playing with ImageJ, I'm only now starting to write macros. What I have is a stack of 9 images, and I'd like to: 1. run the Image CorrelationJ plugin on the first slice 2. save the output to a text file 3. skip to the next slice 4. run the Image CorrelationJ plugin 5. go back to step 2 and loop through until the end of the stack Using the macro recorder, the command for running Image CorrelationJ is: -------------- run("Image CorrelationJ 1o", "target=filename.tif source=filename.tif correlation=[Fix slide (Source)] statistic=Average markers=Circle local=1 decimal=2"); -------------- So my first question is, how do I replace filename.tif with the a variable name of the current active image? I'm assuming there is some 'get filename' command that I could run, and then I could assign the result to a variable that I could use in the above statement. After that I need to save the data. The macro recorder shows this as: -------------- saveAs("Text", "active directory/foo.bar"); -------------- Similar to my first question, how do I use a variable for the directory which I can assign the directory to be the current working directory? Thanks, Dan |
Hi Dan,
I think the commands you want are below. For a list of other built in macro commands, look here: http://rsb.info.nih.gov/ij/developer/macro/functions.html dir = getDirectory("image"); will get the directory of the current image and assign it to the variable "dir" name=getTitle; will get the name of the current image and assign it to the variable "name" saveAs("Text", dir); will save the .txt file to the same directory as the current image, without a name. path = dir+name; will create a path to the current directory and lead the command saveAs("Text", path); below to include the current image name. For some reason, saveAs("Text", dir+name); will not work. Maybe someone more experienced can explain why. So your macro should read: dir = getDirectory("image"); name=getTitle; path = dir+name; //run commands, etc. here with variables substituted in (i.e. //target=name). saveAs("Text", dir); OR saveAs("Text", path); Best, Christine ---- Original message ---- >Date: Tue, 5 Aug 2008 18:08:56 -0400 >From: Dan Siegal-Gaskins <[hidden email]> >Subject: get current image filename/directory for macros >To: [hidden email] > >Hello all, > >After a couple of years of playing with ImageJ, I'm only now starting to >write macros. What I have is a stack of 9 images, and I'd like to: > >1. run the Image CorrelationJ plugin on the first slice >2. save the output to a text file >3. skip to the next slice >4. run the Image CorrelationJ plugin >5. go back to step 2 and loop through until the end of the stack > >Using the macro recorder, the command for running Image CorrelationJ is: > >-------------- >run("Image CorrelationJ 1o", "target=filename.tif source=filename.tif >correlation=[Fix slide (Source)] statistic=Average markers=Circle local=1 >decimal=2"); >-------------- > >So my first question is, how do I replace filename.tif with the a variable >name of the current active image? I'm assuming there is some 'get filename' >command that I could run, and then I could assign the result to a variable >that I could use in the above statement. After that I need to save the >data. The macro recorder shows this as: > >-------------- >saveAs("Text", "active directory/foo.bar"); >-------------- > >Similar to my first question, how do I use a variable for the directory >which I can assign the directory to be the current working directory? > >Thanks, >Dan |
Free forum by Nabble | Edit this page |