I have set myself the task of writing a simple IJ2-style
plugin that takes an open image, blends it with an image
retrieved from a resource in the plugin’s jar, and stores
the result in the open image.
I will start with a specific question, and then ask about
more general OpService usage.
To start, I am trying to get OpService.math().multiply()
to work. My problem is that it seems to require an
ArrayImg, while I have an Image (or ImagePluse or Img).
I also don’t see any prepackaged method for converting
various flavors of images to an ArrayImg. (I see the
same issue for math().divide().)
// from the internet: // IJ1 (?) method for opening an image stored as a resource url = getClass().getResource (resourcePath + imgName); Image image = Toolkit.getDefaultToolkit().getImage(url); opService.math().multiply (image, 2.0);
gives the compile-time error:
MyPlugin.java:94: error: no suitable method found for multiply(Image,double) opService.math().multiply (image, 2.0); ^ method MathNamespace.<B#1>multiply(ArrayImg<B#1,ByteArray>,byte) is not applicable (cannot infer type-variable(s) B#1 (argument mismatch; Image cannot be converted to ArrayImg<B#1,ByteArray>)) method MathNamespace.multiply(ArrayImg<DoubleType,DoubleArray>,double) is not applicable (argument mismatch; Image cannot be converted to ArrayImg<DoubleType,DoubleArray>) method MathNamespace.multiply(ArrayImg<FloatType,FloatArray>,float) is not applicable (argument mismatch; Image cannot be converted to ArrayImg<FloatType,FloatArray>) ... (more of the same)
I see similar errors if I wrap the Image in an ImagePlus,
and if I use an Img obtained from the input harvester via:
// from FrangiVesselness.java @Parameter private Img<T> input;
How do I (assuming that using OpService.math() is the
appropriate IJ2 way to blend two images together) turn the
various image beasties into an ArrayImg? Or can I get
OpService.math() to operate on other kinds of images?
Is my plan of using OpService.math() (basically multiply
and add) to blend two images together a sensible “IJ2
way” of proceeding? Would you have any pointers in advance
for me to help me along my way?
Third (minor) question:
Is there a better, IJ2-approved way to fetch an image from
a resource in the jar?
Again, my (educational) specification is to take an existing
image that is open in Fiji, and blend it in place with a
Thanks for any advice, mm.