[ImageJ-devel] Using imagej-ops to crop images

Hadrien Mary hadrien.mary at gmail.com
Sun Jan 25 09:14:13 CST 2015


Hi,

I am having an issue with a script which crop an image with
imagej-ops. The error shows a "TODO" so I am not sure wether it's a
bug or it's something not supported right now.

-------------------------------
# @DatasetService data
# @ImageJ ij

from jarray import array

from net.imglib2 import FinalInterval
from net.imglib2.img.array import ArrayImgs
from net.imagej.axis import Axes
from net.imglib2.util import Intervals

fname = "/home/hadim/test_small.ome.tif"
ds = data.open(fname)

# Initiate dimensions
dims = {}
dim_names = [None] * 5
for ax in [Axes.X, Axes.Y, Axes.Z, Axes.TIME, Axes.CHANNEL]:
    ax_index = ds.dimensionIndex(ax)
    dim_names[ax_index] = str(ax)
    if int(ds.dimension(ax_index)) == 1:
        dims[str(ax)] = (0, 0)
    else:
        dims[str(ax)] = (0, int(ds.dimension(ax_index)) - 1)

# Set cropped regions
dims['X'] = (10, 40)
dims['Y'] = (5, 20)

# Set crop intervals
begin_interval = [dims[name][0] for name in dim_names]
end_interval = [dims[name][1] for name in dim_names]
interval = FinalInterval(begin_interval, end_interval)
print(begin_interval)
print(end_interval)
print(Intervals.contains(ds, interval))

ds2 = ij.op().crop(interval, ds)
ij.ui().show(ds2.getName(), ds2)
----------------------------------------------------

Error shows:

----------------------------------------------------
ds2 = ij.op().crop(interval, ds)
at net.imagej.DefaultDataset.factory(DefaultDataset.java:735)
at net.imagej.ImgPlus.factory(ImgPlus.java:280)
at net.imagej.ops.crop.CropImgPlus.run(CropImgPlus.java:74)
at org.scijava.command.CommandModule.run(CommandModule.java:201)
at net.imagej.ops.DefaultOpService.run(DefaultOpService.java:363)
at net.imagej.ops.DefaultOpService.run(DefaultOpService.java:78)
at net.imagej.ops.DefaultOpService.crop(DefaultOpService.java:215)
at sun.reflect.GeneratedMethodAccessor29.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)

java.lang.UnsupportedOperationException:
java.lang.UnsupportedOperationException: TODO
-------------------------------------------------------

Thank you

--
Hadrien Mary

Ph.D student in Biology
Tournier-Gachet Team
CNRS - LBCMCP - UMR 5088

Université de Toulouse - Bât. 4R3B1
118, route de Narbonne - 31062 Toulouse



More information about the ImageJ-devel mailing list