Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot access Big Warp command through API #131

Open
nanthony21 opened this issue Oct 26, 2021 · 6 comments
Open

Cannot access Big Warp command through API #131

nanthony21 opened this issue Oct 26, 2021 · 6 comments

Comments

@nanthony21
Copy link

I'm not sure if this is really an issue with Big Warp or with ImageJ itself.

I would like to open the Big Warp plugin from a Python script using pyimagej

I can use ij.commands().getPlugins() to view a list of available plugins but when I do I only find 'bdv.ij.BigWarpBdvCommand', menu='Plugins > BigDataViewer > Big Warp XML/HDF5'. The other commands do not appear even though they are installed.

I think this is happening because Big Warp XML/HDF5 uses the @Plugin(..... style of declaring itself as a plugin while the other plugins have no annotation but are instead declared in plugins.config.

Note that this is not limited just to pyimagej. It can also be demonstrated directly in ImageJ. Here is a groovy macro to print out the available plugins through the API.

import net.imagej.ImageJ;

ImageJ ij = new net.imagej.ImageJ();

for (p : ij.command().getPlugins()) {
	System.out.println(p);
}
@bogovicj
Copy link
Contributor

Hi @nanthony21 ,

I've not used pyimagej much, but initializing it differently may help, see here:
https://github.com/imagej/pyimagej/blob/master/doc/Initialization.md#ways-to-initialize

specifically, maybe initializing with imagej1 support could help. It's mentioned on the troubleshooting page - that makes me optimistic.

Let me know how that goes.

@nanthony21
Copy link
Author

Thanks for getting back to me.

I tried adding ['net.imagej:imagej', 'net.imagej:imagej-legacy'] to the initializer but didn't see any change in behavior.

It's worth noting that if we completely forget pyimagej this issue is still there. Using the above Groovy macro with a fresh install of FIJI only finds 'bdv.ij.BigWarpBdvCommand', menu='Plugins > BigDataViewer > Big Warp XML/HDF5'

@nanthony21
Copy link
Author

My hope is to write a script that will:

  • Open 2 images in Big Warp
  • Configure a specific transformation type
  • Wait for the user to indicate they are done drawing landmarks.
  • Save the resulting transformation matrix to a text file.

I suppose if Big Warp doesn't have support for access through macros then this may not work anyway. Do you think it's possible to do these things via a script rather than requiring a user to properly configure things through the GUI?

@bogovicj
Copy link
Contributor

It's worth noting that if we completely forget pyimagej this issue is still there. Using the above Groovy macro with a fresh install of FIJI only finds

That's right, thanks for including that. This is probably because of how imagej2 discovers plugins - seems like expected behavior that the "main" bigwarp plugin is not found in this way. I can investigate.

could you try running bigwarp with a macro using
ij.py.run_macro( ... ) or similar?

This macro runs bigwarp:

run("Big Warp", "moving_image=my-moving-img-title.tif target_image=my-target-image-title.tif moving=[] moving_0=[] target=[] target_0=[] landmarks=[]");

Thanks for clarifying what your goal is.

The last step of saving " the resulting transformation matrix to a text file." seems to be the only one that needs the bigwarp api, as far as I can tell. This is easy if you're working in java - if you can call arbitrary methods from pyimagej, I can show you how to do this, I'm just not sure how / if its possible to call arbitrary java methods from pyimagej.

Good luck

@nanthony21
Copy link
Author

Thanks for your help @bogovicj

I think it's just a matter of using the @Plugin annotation rather than the "plugins.config" file, but I don't know enough about ImageJ to know if there are any complicating factors.

The run_macro solution you suggested does in fact work and based on this I could even dynamically pass in arguments to the macro from a Python dictionary. However I don't think this solution will allow me to access the API of the plugin class which would be pretty nice.

I believe pyimagej just works as a bridge between ImageJ and Python using JPype so if I do manage to access the BigWarpImagePlusPlugin class directly via ij.plugins().getPlugin("bdv.ij.BigWarpImagePlusPlugin") then I should be able to access any public Java methods of the class.

@nanthony21
Copy link
Author

This PR would resolve this issue #133

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants