![]() | ![]() |
![]() |
Previous Message |
Next Message Previous in Topic | Next in Topic Previous by Same Author | Next by Same Author Previous Page (May 2002) | Back to Main IMAGEJ Page | | ![]()
Reply
| Post a New Message |
Join or Leave IMAGEJ, or Change Options
|
Search | ![]()
Chronologically |
Most Recent First |
Wrap Text (Proportional Font) |
Don't Wrap Text (Non-proportional Font) | ![]() |
Content-Type: text/plain; charset=US-ASCII; format=flowed Message-ID: <[log in to unmask]> Date: Fri, 24 May 2002 15:24:57 -0400 Reply-To: ImageJ Interest Group <[log in to unmask]> Sender: ImageJ Interest Group <[log in to unmask]> From: Wayne Rasband <[log in to unmask]> Subject: Re: ImageJ: Is there a clean way to write a command line tool that uses ImageJ In-Reply-To: <[log in to unmask]>> Hi. I'm using ImageJ both on the Windows side and on a Linux box. On the > Linux box, > I'm trying create a set of command-line tools that I can call and use > for > batch processing of images from > shell scripts (on 3D Analyze format images using Guy William's > Plugins). The > following > class example appears to do the job: > > import ij.*; > import ij.measure.*; > import java.io.*; > > public class CommandLineMaskImage{ > public static void main(String argv[]){ > if (argv.length!=3){ > System.out.println("MaskImage usage:"+ > "MaskImage [mask image] [input image] [outputimage]"); > return; > } > else{ > ImageJ mainFrame=null; > if (IJ.getInstance()==null){ > mainFrame= new ImageJ(); > } > > IJ.run("Analyze Reader", "path='"+argv[0]+".hdr'"); > IJ.run("Rename...", "title=mask"); > IJ.run("Analyze Reader", "path='"+argv[1]+".hdr'"); > IJ.run("Rename...", "title=image"); > ImagePlus imp=WindowManager.getCurrentImage(); > Calibration c = imp.getCalibration(); > IJ.run("Image Calculator...", "image1=mask operation=AND > image2=mask create"); > > IJ.selectWindow("Result"); > ImagePlus rimp =WindowManager.getCurrentImage(); > rimp.setCalibration(c); > > IJ.run("Analyze Writer", "path='"+argv[2]+".hdr'"); > > mainFrame.quit(); > } > } > } > > It can be executed from the command line with something like: > > java CommandLineMaskImage /home/cjtaylor/javaf/maskimage > /home/cjtaylor/javaf/actualimage /home/cjtaylor/javaf/outputImage > > Two Questions: > > 1) When I run this, I need to have the plugins folder directly > underneath > the folder containing CommandLineMaskImage.class. Is there someway to > set > this folder by calling an ImageJ instance or through an IJ static > method > when not running the standard ImageJ GUI? You can specify the path to the plugins directory by setting the "plugins.dir" property. This can be done from the command line using the -D option, for example: java -Dplugins.dir=path-to-plugins-dir -cp ij.jar:. ClassThatUsesImageJ You can also set this property from within a program: Properties p = System.getProperties(); p.setProperty("plugins.dir", "path-to-plugins-dir"); System.setProperties(p); Set the "plugins-dir" property to "user.home" and ImageJ will look for the plugins directory in the users home directory. > 2) Since each of the IJ.run() commands are supposed to run on separate > threads, I would have throught that this code might not work properly > due to > synchronization issues, but it appears to be working. Is this simply a > machine timing fluke and, in truth, I'm playing with fire or is there > something that guarantees that each command waits for the previous > command > to complete? The IJ.run() commands do not run on a separate thread. -wayne
![]() |
![]() Center for Information Technology National Institutes of Health Bethesda, Maryland 20892 301 594 6248 (v) 301 496 8294 (TDD) Comments and Assistance Accessibility ![]() |