Jython Scripting "Grid/Collection stitching"

I’m trying to develop a Jython Script using the Grid/Collection stitching plugin.

Using the macro recorder I’ve figure out I can something like the following :

from ij import IJ

inDir = "/panoramas/data/D8/"
outDir = "/panoramas/data/D8/"

IJ.run("Grid/Collection stitching", 
	   "type=[Sequential Images] " + 
	   "order=[All files in directory] " +
	   "directory=" + inDir + " " + 
	   "output_textfile_name=TileConfiguration.txt " + 
	   "fusion_method=[Linear Blending] " + 
	   "regression_threshold=0.30 " +
	   "max/avg_displacement_threshold=2.50 " + 
	   "absolute_displacement_threshold=3.50 " + 
	   "frame=1 " + 
	   "subpixel_accuracy " + 
	   "display_fusion " + 
	   "computation_parameters=[Save computation time (but use more RAM)] " +
	   "image_output=[Write to disk] " +
	   "output_directory=" + outDir);

The problem is most of my data isn’t organized into a folders for each collection to be stitched. I can manage this but is there a way to pass a series of ImagePlus objects to the plugin rather than point it at a folder on the drive?

Likewise, is there a way to specify the output image name was it’s written to disk? Currently it seems to default to img_t1_z1_c1 without a file extension. This is obviously problematic if I’m writing more than one stitched file to a single location.

Finally, I would have expected the display_fusion command to have displayed the resulting stitched image, however, this appears not tow work when used in conjunction with image_output=[Write to disk].

Is there a lower level means of accessing the functionality I’m looking for rather than using IJ.run()?

Thanks

There is a forum entry discussing your problem: Is there a way to run FIji's Stitching from a script?

There is an API for it: https://javadoc.scijava.org/Fiji/index.html?plugin/Stitching_Grid.html

BigStitcher is a new project that offers similar capabilites: https://imagej.net/BigStitcher

1 Like

Thanks @schmiedc … I think you may have pasted the wrong link to the forum entry. I’ll check out all of your suggestions.

Thanks

Aha thanks, fixed it =)

@schmiedc Thanks for the earlier references but now I think I’m more confused than when I started. Let me start with that I’ve had good luck using the lower level classes for various aspects of ImageJ, most in ij but for some reason I’m not getting to far with this one.

I can’t see to tell from the class you reference Stitching_Grid what the actual method is that does the stitching. I also looked that the other forum thread and it seems to reference a bunch of methods in the mpicbg.stitching class.

It’s hard for me to follow what’s going on the the example given in the other thread as a) there seems to be a ton going on besides just stitching and b) I’m not a java / groovy person. It seem like there’s a bunch of objects based on different classes that need to be built before everything gets handed off to the Fusion.fuse method.

Am I off base here? Is there any sort of minimum viable example (preferably in jython) that shows how to take a few overlapping images and stitch them together?

Sorry for being so dense on this one.

Hi,

I never worked with this plugin. You could contact the authors.

I would then rather stick to the macro code and streamline the workflow around that.
You could save into different output folders to work around your second issue.

Cheers,
Christopher

FWIW, I also use this plugin in a jython script and have found it easier to just copy the files I need into a temp dir with shutil, point the plugin at that, and then remove the temp dir when I’m done.

That could be a nice work around!