[ImageJ-devel] Using imagej-ops to crop images
Mark Hiner
hiner at wisc.edu
Sun Jan 25 12:53:06 CST 2015
Hi Hadrien!
>so I am not sure wether it's a bug or it's something not supported right
now.
It looks like it's a limitation of the DefaultDataset[1] right now. I
updated the message to suggest a workaround, at least[2].
So if you change your next to last line to:
ds2 = ij.op().crop(interval, ds.getImgPlus())
to crop the ImgPlus that's wrapped by the Dataset, your script should work
(or at least not crash).
Thanks, as always, for the report :)
Best,
Mark
[1]
https://github.com/imagej/imagej-common/blob/59bfc3cebf8204a48bc559adf079f227652514ed/src/main/java/net/imagej/DefaultDataset.java#L734-736
[2]
https://github.com/imagej/imagej-common/commit/75330a95c66013390cf4b6b4511e08357a8a28b0
On Sun, Jan 25, 2015 at 9:14 AM, Hadrien Mary <hadrien.mary at gmail.com>
wrote:
> 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
>
> _______________________________________________
> ImageJ-devel mailing list
> ImageJ-devel at imagej.net
> http://imagej.net/mailman/listinfo/imagej-devel
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://imagej.net/pipermail/imagej-devel/attachments/20150125/7df0eaf8/attachment.html>
More information about the ImageJ-devel
mailing list