I have been attempting to write a macro using the Grid/Collection Stitching command but I have ran into a bit of a problem. The problem is that when I attempt to set the filename I need to put a variable into the filename however if I try to put in for example, file_names= c-{i} the program will try to find a file with exactly that name.
Any help would be greatly appreciated, Henry Hardwick. |
Henry,
I am not sure if this will solve your problem, but I have had issues in the past in passing parameters to the Grid/Collection Stitching plugin from within an ImageJ macro script so I figured I would share some of the things that have tripped me up in the past. There is an ImageJ macro help document at http://rsbweb.nih.gov/ij/developer/macro/macros.html that I often reference for details about how to call macros. When calling a plugin from a macro there are two general methods I use, either I build a String containing all of the relevant parameters myself using string concatenation and then pass that string to the plugin using the run() command, or I build the parameter string within the call to run(). This is an excerpt from one of my macros that calls the Grid/Collection Stitching plugin where I build the parameters string myself: " // build parameters string paramsStr = "type=" + numbering + " order=" + gridOrigin + " grid_size_x=" + gridWidth + " grid_size_y=" + gridHeight + " tile_overlap=" + imgOverlap + " first_file_index_i=" + startTile + " directory=" + workingDirectory + " file_names=[" + filenamePattern + "] output_textfile_name=TileConfiguration.txt fusion_method=[Do not fuse images (only write TileConfiguration)] regression_threshold=0.30 max/avg_displacement_threshold=2.50 absolute_displacement_threshold=3.50 compute_overlap subpixel_accuracy computation_parameters=[Save computation time (but use more RAM)] image_output=[Write to disk] output_directory=" + outputDir; // print parameters string print(paramsStr); // call stitching plugin run("Grid/Collection stitching", paramsStr); " I use the string concatenation method here to build a String paramsStr which I then pass to the run() command. Alternatively there is a functionality to use &variableName within a string to specify the values to pass to the run command. The macro documentation link included above explains this in the section "Using run() to execute ImageJ commands". It is worth noting that if the value you are passing to the run command has spaces in it you need to surround the value with square brackets '[]'. You see this in my example above with '... file_names=[" + filenamePattern + "] ...' where I wrap my filenames variable in the square brackets because they might have spaces in the filename pattern. Adding the square brackets does nothing if there are no spaces so I use them preventatively if the parameter value might have spaces. Another ImageJ macro resource that I often find myself using is the built-in macro function documentation: http://rsbweb.nih.gov/ij/developer/macro/functions.html Regards, Michael Majurski -----Original Message----- From: ImageJ Interest Group [mailto:[hidden email]] On Behalf Of HenryHardwick Sent: Thursday, July 16, 2015 9:51 AM To: [hidden email] Subject: Variable in filename I have been attempting to write a macro using the Grid/Collection Stitching command but I have ran into a bit of a problem. The problem is that when I attempt to set the filename I need to put a variable into the filename however if I try to put in for example, file_names= c-{i} the program will try to find a file with exactly that name. Any help would be greatly appreciated, Henry Hardwick. -- View this message in context: http://imagej.1557.x6.nabble.com/Variable-in-filename-tp5013596.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 |
In reply to this post by HenryHardwick
Hi,
Thanks for the post. I run into the same problem and was able to solve by simply add "&" in front of my variable. Lihong Detailed explanation can be found in the following link. https://imagej.nih.gov/ij/developer/macro/macros.html With ImageJ 1.43 and later, there is an easier method that only requires adding "&" to the variable name in the options string: noise = 50; output = "Point Selection"; run("Find Maxima...", "noise=&noise output=&output light"); String variables passed using this method do not have to be enclosed in brackets. For more examples, see the ArgumentPassingDemo macro. -- Sent from: http://imagej.1557.x6.nabble.com/ -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
Free forum by Nabble | Edit this page |