Context: Java plugin.
Assume that I have an ImageStack ++++++++++++++++++++++++++ ImageStack enFaceStack; ...populate the stack with individual images... ++++++++++++++++++++++++++ I would like to register this stack - probably using SIFT (but I'm open to suggestion). From the macro recorder, I get: ++++++++++++++++++++++++++ run("Linear Stack Alignment with SIFT", "initial_gaussian_blur=1.60 steps_per_scale_octave=3 minimum_image_size=64 maximum_image_size=1024 feature_descriptor_size=4 feature_descriptor_orientation_bins=8 closest/next_closest_ratio=0.92 maximal_alignment_error=25 inlier_ratio=0.05 expected_transformation=Rigid interpolate"); ++++++++++++++++++++++++++ Based on the online documentation, I'm guessing I want to code this in Java as something like: ++++++++++++++++++++++++++ ImagePlus ipl = new ImagePlus("enFaceStack", enFaceStack); run(ipl,"Linear Stack Alignment with SIFT", "initial_gaussian_blur=1.60 steps_per_scale_octave=3 minimum_image_size=64 maximum_image_size=1024 feature_descriptor_size=4 feature_descriptor_orientation_bins=8 closest/next_closest_ratio=0.92 maximal_alignment_error=25 inlier_ratio=0.05 expected_transformation=Rigid interpolate", null); ++++++++++++++++++++++++++ My questions are: a) does the above look correct? b) How do I get a reference to the resulting ImageStack? When I do this manually, the original ImageStack (packaged up in a StackWindow) is left untouched, and a new StackWindow is created with the title "Aligned 9 of 9" - there were 9 slices. But, I want my Java program to (perhaps at the user's option) replace the original slices, in the original ImageStack, with the registered versions. If it matters, the original StackWindow is actually a MyStackWindow which extends StackWindow. So, I want to keep the same MyStackWindow but replace the contained ImageStack. I'd be happy to either replace the entire stack, or remove/add slices to replace the individual slices. I'm guessing that one way to do this is to (how?) get a list of all open windows and search for the one with the right title. Better would be some way to get a reference to the window created by the "run" command. This is probably very basic - but I haven't done it before, and haven't been able to find anything in the documentation. At a different level, is it possible to get lower level access to the "Linear Stack Alignment with SIFT" (or something else - but it seems to work just fine) s.t. I can pass an ImageStack and get an aligned ImageStack returned? It might be convenient to *not* display another StackWindow. But, that would be a bonus. -- Kenneth Sloan [hidden email] Vision is the art of seeing what is invisible to others. -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
Hi Kenneth,
The plugin source code is here: https://github.com/axtimwalde/mpicbg/blob/2f411b380cffb580e35410b6517ffeb2c72489e2/mpicbg_/src/main/java/SIFT_Align.java The run method does many things; the next level down programmatically is probably the SIFT class here: https://github.com/axtimwalde/mpicbg/blob/2f411b380cffb580e35410b6517ffeb2c72489e2/mpicbg/src/main/java/mpicbg/ij/SIFT.java But it is quite low level. It may be simplest to copy/paste/edit code from the plugin. And of course, PRs welcome if you want to improve the modularity. Regards, Curtis -- Curtis Rueden LOCI software architect - https://loci.wisc.edu/software ImageJ2 lead, Fiji maintainer - https://imagej.net/User:Rueden Did you know ImageJ has a forum? http://forum.imagej.net/ On Mon, Mar 5, 2018 at 12:34 PM, Kenneth Sloan <[hidden email]> wrote: > Context: Java plugin. > > Assume that I have an ImageStack > > ++++++++++++++++++++++++++ > ImageStack enFaceStack; > ...populate the stack with individual images... > ++++++++++++++++++++++++++ > > I would like to register this stack - probably using SIFT (but I'm open to > suggestion). > > From the macro recorder, I get: > > ++++++++++++++++++++++++++ > run("Linear Stack Alignment with SIFT", "initial_gaussian_blur=1.60 > steps_per_scale_octave=3 minimum_image_size=64 maximum_image_size=1024 > feature_descriptor_size=4 feature_descriptor_orientation_bins=8 > closest/next_closest_ratio=0.92 maximal_alignment_error=25 > inlier_ratio=0.05 expected_transformation=Rigid interpolate"); > ++++++++++++++++++++++++++ > > Based on the online documentation, I'm guessing I want to code this in > Java as something like: > > ++++++++++++++++++++++++++ > ImagePlus ipl = new ImagePlus("enFaceStack", enFaceStack); > > run(ipl,"Linear Stack Alignment with SIFT", "initial_gaussian_blur=1.60 > steps_per_scale_octave=3 minimum_image_size=64 maximum_image_size=1024 > feature_descriptor_size=4 feature_descriptor_orientation_bins=8 > closest/next_closest_ratio=0.92 maximal_alignment_error=25 > inlier_ratio=0.05 expected_transformation=Rigid interpolate", null); > ++++++++++++++++++++++++++ > > My questions are: > > a) does the above look correct? > > b) How do I get a reference to the resulting ImageStack? > > When I do this manually, the original ImageStack (packaged up in a > StackWindow) is left untouched, and a new StackWindow is created with the > title "Aligned 9 of 9" - there were 9 slices. > > But, I want my Java program to (perhaps at the user's option) replace the > original slices, in the original ImageStack, with the registered versions. > > If it matters, the original StackWindow is actually a MyStackWindow which > extends StackWindow. So, I want to keep the same MyStackWindow but replace > the contained ImageStack. I'd be happy to either replace the entire stack, > or remove/add slices to replace the individual slices. > > I'm guessing that one way to do this is to (how?) get a list of all open > windows and search for the one with the right title. Better would be some > way to get a reference to the window created by the "run" command. > > This is probably very basic - but I haven't done it before, and haven't > been able to find anything in the documentation. > > At a different level, is it possible to get lower level access to the > "Linear Stack Alignment with SIFT" (or something else - but it seems to > work just fine) s.t. I can pass an ImageStack and get an aligned ImageStack > returned? It might be convenient to *not* display another StackWindow. > But, that would be a bonus. > > > -- > Kenneth Sloan > [hidden email] > Vision is the art of seeing what is invisible to others. > > -- > ImageJ mailing list: http://imagej.nih.gov/ij/list.html > -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
Thank you for the prompt response.
Does "run" set the "current image"? I see that WindowManager offers methods such as: getActiveWindow() getCurrentImage() Next on my list would be: getImageTitles() finding one starting with "aligned", and then getImage(title) The best bet seems to be "getActiveWindow()" or "getCurrentImage()" - since I think the top window is the aligned stack, on completion. This might be confounded by the log window showing progress. Searching titles has the flaw that a careless user may leave old windows laying about, which would confuse things. I think I'll experiment with these before trying to modify someone else's plugin. -- Kenneth Sloan [hidden email] Vision is the art of seeing what is invisible to others. > On 5 Mar 2018, at 13:18 , Curtis Rueden <[hidden email]> wrote: > > Hi Kenneth, > > The plugin source code is here: > https://github.com/axtimwalde/mpicbg/blob/2f411b380cffb580e35410b6517ffeb2c72489e2/mpicbg_/src/main/java/SIFT_Align.java > > The run method does many things; the next level down programmatically is > probably the SIFT class here: > https://github.com/axtimwalde/mpicbg/blob/2f411b380cffb580e35410b6517ffeb2c72489e2/mpicbg/src/main/java/mpicbg/ij/SIFT.java > > But it is quite low level. It may be simplest to copy/paste/edit code from > the plugin. > > And of course, PRs welcome if you want to improve the modularity. > > Regards, > Curtis > > -- > Curtis Rueden > LOCI software architect - https://loci.wisc.edu/software > ImageJ2 lead, Fiji maintainer - https://imagej.net/User:Rueden > Did you know ImageJ has a forum? http://forum.imagej.net/ -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
Answering my own question...
This seems to work: ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ImageStack enFaceStack = ....create original stack... ImageStack originalEnFaceStack = enFaceStack; ImagePlus originalImagePlus = new ImagePlus("original", originalEnFaceStack); IJ.run(originalImagePlus, "Linear Stack Alignment with SIFT", "initial_gaussian_blur=1.60 " + "steps_per_scale_octave=3 " + "minimum_image_size=64 " + "maximum_image_size=1024 " + "feature_descriptor_size=4 " + "feature_descriptor_orientation_bins=8 " + "closest/next_closest_ratio=0.92 " + "maximal_alignment_error=25 " + "inlier_ratio=0.05 " + "expected_transformation=Rigid interpolate" ); ImagePlus alignedImagePlus = WindowManager.getCurrentImage(); ImageStack alignedImageStack = alignedImagePlus.getImageStack(); for(int i=1;i<=alignedImageStack.getSize();i++) alignedImageStack.setSliceLabel(enFaceStack.getSliceLabel(i)+" aligned",i); enFaceStack = alignedImageStack; ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ This leaves a "log" window, and the "aligned n of n" window visible. I'll probably start using the "log" window for my own reporting, and I suppose I can make the "aligned n of n" invisible. I'm not thrilled with depending on a global "current Image" to get a handle on the result of running a command, but I suppose this is necessary for scripting. Thanks again for the response. -- Kenneth Sloan [hidden email] Vision is the art of seeing what is invisible to others. -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
Free forum by Nabble | Edit this page |