"Grid/collection stitching" registered coordinates not saving correctly with pyimagej

Hello!

I am new to ImageJ/Fiji, and I am trying to create an image stitching pipeline for my microscope images. I am trying to use Python via pyimagej, and after struggling with installation for a while, I think I managed to figure it out. However, I am having an issue with calling the “Grid/collection stitching” plugin using pyimagej. In particular, I would like for the program to save both the estimated coordinates as well as the registered coordinates that are generated by the stitching algorithm, but it only saves the estimated coordinates. However, if I run the algorithm using the Fiji GUI, I get both sets of coordinates. What is the issue?

Here is the relevant excerpt of my code:

# ImageJ/Fiji setup
    ij = imagej.init('/path/to/Fiji.app')
    IJM_EXTENSION = ".ijm"
    STITCHING_MACRO = """
            #@ String sourceDirectory
            #@ String outputDirectory
            #@ int cols
            #@ int rows
    
            print(outputDirectory);
            function action(sourceDirectory, outputDirectory, genericFilename, filename, coordinateFilename) {
                run("Grid/Collection stitching", "type=[Grid: snake by rows] order=[Right & Down ] grid_size_x=" + cols + " grid_size_y=" + rows + " tile_overlap=6 first_file_index_i=0 directory=" + sourceDirectory + " file_names=" + genericFilename + " output_textfile_name=" + coordinateFilename + " fusion_method=[Linear Blending] regression_threshold=0.30 max/avg_displacement_threshold=2.50 absolute_displacement_threshold=3.50 subpixel_accuracy computation_parameters=[Save computation time (but use more RAM)] image_output=[Fuse and display]");
                saveAs("png", outputDirectory + filename);
                close();
            }
    
            action(sourceDirectory, outputDirectory, "fov_{i}.png", "reference_stitch", "../stitching_coordinates.txt");
            
            """


    cols = args.cols
    rows = args.rows
    for round_directory in round_directories:
        dapi_directory = glob.glob(os.path.join(round_directory, "DAPI*/"))[0]
        print(dapi_directory)
        args = {
                'sourceDirectory': dapi_directory,
                'outputDirectory': round_directory,
                'cols': cols,
                'rows': rows

Did you use the macro recorder to get the exact option string for your run("Grid/Collection Stitching", ...) command?

In your code, you’re missing the compute_overlap keyword in the option string, so the plugin won’t compute the overlap but use just the estimated coordinates.

Yes, that was the problem! Thanks a lot.