ImageJ2 scripting questions

Tags: #<Tag:0x00007fd6a011e558> #<Tag:0x00007fd6a011e2b0> #<Tag:0x00007fd6a011e148>



I have some question regarding ImageJ2 and imglib2 scripting with python (in Fiji).

First, is there a simple way to deal with out of bound error in this case:

from net.imglib2.algorithm.region.hypersphere import HyperSphere

If i understand it well HyperSphere allow me access img data with a new cursor which follow a sphere shape, and cursor and randomAccess doesn’t have out of bound check.

Second ops.math().add() and subtract() doesn’t work for me with to subtract or add a value froom an image. It work fine when i do it on 2 images. Is it normal or i’m doing it wrong?

Then what is the way to go to deal with ROI in ImageJ2 scripting? I suppose it’s to create new RandomAccessibleInterval() and/or IterableInterval() over existing image (like HyperSphere) but i have no idea how to do it.




Dear @r.flores,

welcome to the forum! :slight_smile:

Yes, that’s what the HyperSphere does. Do you generate img yourself or is it an image provided via the UI? The following script works fine for me after opening the Dot Blot sample:

# @OpService ops
# @Img img

from net.imglib2.algorithm.region.hypersphere import HyperSphere
from net.imglib2 import Point

point = Point([2, 2]);

Otherwise you can apply an OutOfBoundsFactory from net.imglib2.outofbounds:

from net.imglib2.outofbounds import OutOfBoundsMirrorFactory;
from net.imglib2.outofbounds.OutOfBoundsMirrorFactory import Boundary;
from net.imglib2.view import Views 

extendedImg = Views.extend(img, OutOfBoundsMirrorFactory(Boundary.SINGLE))

Looking at the MathNamespace there are only methods for value + value as well as image + image but not image + value. You can also do the following instead:

# @OpService ops
# @Img img

vars = {
	"img": img,
result = ops.eval("img+10", vars)

The future perspective of the ROI implementation is currently discussed in Implementation plan for Imglib2-rois 2D. Do you want to create the ROIs programatically with your own code from e.g. coordinates of a polygon? There are ops for executing a connected component analysis on binary images in the LabelingNamespace that might be helpful depending on what you want to do.



That’s not true. The following Groovy code works in an up-to-date Fiji:

// @OpService ops
// @Img img
// @OUTPUT Img result

result ="math.add", img, 10.0)


Thank you for your help, it work great !

It was a general question on how to do ROI detection and measurement with ImageJ2 scripting. I didn’t know where to start. I’ll have a look on the discussion and the Labeling namespace.

result =“math.add”, img, 10.0)

work, but

result = ops.math().add(img, 10.0)

doesn’t work with python or groovy.
I’ll use the first one from now.