PreibischLab / BigStitcher

ImgLib2/BDV implementation of Stitching for large datasets
GNU General Public License v2.0
68 stars 15 forks source link

Proper macro for headless bounding box calculation #92

Open miketaormina opened 3 years ago

miketaormina commented 3 years ago

I'm using the following macro to calculate the maximum bounding box (called from pyimagej):

#@ String basePath
run("Define Bounding Box for Fusion",
        "select=" + basePath + " "+
        "process_angle=[All angles] process_channel=[All channels] "+
        "process_illumination=[All illuminations] process_tile=[All tiles] "+
        "process_timepoint=[All Timepoints] "+
        "bounding_box=[Maximal Bounding Box spanning all transformed views] bounding_box_name=[MAX Bounding Box]

This sometimes, but not always yields a different bounding box than if I do the operation from the plugin (which yields the correct answer). Is this the proper way to calculate the max bounding box in headless mode? When I try to record the macro with ImageJ, it seems to do the calculation of the bounding box before constructing the command:

run("Define Bounding Box for Fusion",
"select=XXXXX.xml
process_angle=[All angles] process_channel=[All channels]
process_illumination=[All illuminations] process_tile=[All tiles]
process_timepoint=[All Timepoints]
bounding_box=[Maximal Bounding Box spanning all transformed views] bounding_box_name=[My Bounding Box1]
minimal_x=-1 minimal_y=64 minimal_z=-1 maximal_x=4820 maximal_y=5734 maximal_z=1385");

But this isn't really helpful for a scripting application, since these are the numbers I'm trying to determine. Should I be reading/calculating these numbers from the xml file directly?

hoerldavid commented 3 years ago

Hi @miketaormina ,

I can answer why the numbers (minimal_x, minimal_y, ...) show up in the recorded command: If you click through the dialogs by hand, it will show you the box it has determined and allow manual adjustments - those values will show up in the recording. If you delete the parameters, as you did in your first snippet, it should just use whatever is determined automatically.

The divergent behaviour in a macro vs. GUI is more puzzling - in both cases we are using the same code... Do you have an example of how these numbers differ? Ideally, you could send us the corresponding XML file so we can do some probing into what goes wrong...

Best, David

miketaormina commented 3 years ago

Thanks @hoerldavid ,

Reproducing the issue is pretty hit or miss, but I'll see if I can find you an example file where this happens. I think that I mostly see this when performing this operation on several files sequentially, where the first is flawless and subsequent ones misbehave. I wonder if it has more to do with keeping one initialization of pyimagej around. There is also a possibility that I'm simply mucking it up!

Sorry for the delay in response here, I have been circumventing the problem by calculating the maximum bounding box directly from the XML file bounds and transforms, which is maybe how I should be doing this operation anyways. Once I pull those numbers, I can use a script to define the bounding box explicitly and fuse from there.

The stitching and fusion with this plugin work impressively well, by the way, kudos to the team for this incredibly useful tool!

Thanks again and I'll see if I can make an XML file and notebook that reproduce this. -Mike