<div dir="ltr">Hi Hadrien,<div><br></div><div>><span style="font-size:13px">Exception in thread "DrawAndDrop" java.lang.NoSuchMethodError:</span></div><span style="font-size:13px">>io.scif.ImageMetadata.</span><span style="font-size:13px">setAxisLength(Lnet/imglib2/</span><span style="font-size:13px">meta/AxisType;J)V</span><div><span style="font-size:13px"><br></span></div><div><span style="font-size:13px">Ah sorry - my fault again for responding too quickly. ImageJ.git doesn't have a dependency on scifio-ome-xml; it's a dependency in Fiji itself[1]. So when you installed ImageJ into your Fiji, it updated all the dependencies but didn't actually update scifio-ome-xml.</span></div><div><span style="font-size:13px"><br></span></div><div><span style="font-size:13px">You can either manually copy scifio-ome-xml[2] over, or try installing from the latest Fiji master[3] which I just updated to have the latest dependencies.</span></div><div><span style="font-size:13px"><br></span></div><div><span style="font-size:13px">[1] </span><a href="https://github.com/fiji/fiji/blob/2bc6266ff5ad5dfa155db9c0631db9baae396062/pom.xml#L608-612">https://github.com/fiji/fiji/blob/2bc6266ff5ad5dfa155db9c0631db9baae396062/pom.xml#L608-612</a></div><div>[2] <a href="https://github.com/scifio/scifio-ome-xml/releases/tag/scifio-ome-xml-0.12.0">https://github.com/scifio/scifio-ome-xml/releases/tag/scifio-ome-xml-0.12.0</a></div><div>[3] <a href="https://github.com/fiji/fiji/commit/2bc6266ff5ad5dfa155db9c0631db9baae396062">https://github.com/fiji/fiji/commit/2bc6266ff5ad5dfa155db9c0631db9baae396062</a></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Jan 14, 2015 at 7:05 AM, Hadrien Mary <span dir="ltr"><<a href="mailto:hadrien.mary@gmail.com" target="_blank">hadrien.mary@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Ok it makes sense now !<br>
<br>
So I did what you told me about cloning imagej repo, building and<br>
install it with maven inside my local Fiji.app/. I don't know if it's<br>
a bug or a missing dependency but I am now unable to open OME Tiff<br>
files (other kind of file works well) wether it is by drag and drop or<br>
with my script. The error is the following:<br>
<br>
-------------------------------------------------<br>
Exception in thread "DrawAndDrop" java.lang.NoSuchMethodError:<br>
io.scif.ImageMetadata.setAxisLength(Lnet/imglib2/meta/AxisType;J)V<br>
at io.scif.ome.formats.OMETIFFFormat$Metadata.populateImageMetadata(OMETIFFFormat.java:273)<br>
at io.scif.AbstractParser.parse(AbstractParser.java:254)<br>
at io.scif.ome.formats.OMETIFFFormat$Parser.parse(OMETIFFFormat.java:609)<br>
at io.scif.ome.formats.OMETIFFFormat$Parser.parse(OMETIFFFormat.java:552)<br>
at io.scif.AbstractParser.parse(AbstractParser.java:335)<br>
at io.scif.AbstractParser.parse(AbstractParser.java:52)<br>
at io.scif.AbstractReader.setSource(AbstractReader.java:270)<br>
at io.scif.services.DefaultInitializeService.initializeReader(DefaultInitializeService.java:90)<br>
at io.scif.img.ImgOpener.createReader(ImgOpener.java:542)<br>
at io.scif.img.ImgOpener.openImgs(ImgOpener.java:144)<br>
at io.scif.io.DatasetIOPlugin.open(DatasetIOPlugin.java:133)<br>
at io.scif.io.DatasetIOPlugin.open(DatasetIOPlugin.java:109)<br>
at io.scif.io.DatasetIOPlugin.open(DatasetIOPlugin.java:63)<br>
at net.imagej.legacy.plugin.DefaultLegacyOpener.open(DefaultLegacyOpener.java:134)<br>
at net.imagej.legacy.DefaultLegacyHooks.interceptDragAndDropFile(DefaultLegacyHooks.java:358)<br>
at ij.plugin.DragAndDrop.openFile(DragAndDrop.java)<br>
at ij.plugin.DragAndDrop.run(DragAndDrop.java:152)<br>
at java.lang.Thread.run(Thread.java:745)<br>
-----------------------------------------------<br>
<br>
I guess something in scifio has not been updated to use the new<br>
net.imagej.axis or maybe the update is not built/downloaded when I run<br>
maven on my imagej clone.<br>
<span class="im HOEnZb"><br>
<br>
--<br>
Hadrien Mary<br>
<br>
Ph.D student in Biology<br>
Tournier-Gachet Team<br>
CNRS - LBCMCP - UMR 5088<br>
<br>
Université de Toulouse - Bât. 4R3B1<br>
118, route de Narbonne - 31062 Toulouse<br>
<br>
<br>
</span><div class="HOEnZb"><div class="h5">On Wed, Jan 14, 2015 at 12:58 PM, Mark Hiner <<a href="mailto:hiner@wisc.edu">hiner@wisc.edu</a>> wrote:<br>
> Hi Hadrien,<br>
><br>
>>Sorry if it's off topic but I tried to run my script and I got a python<br>
>> error<br>
><br>
> Oh no! This is totally my fault. I had to update your script for the new<br>
> dependencies I mentioned and forgot to paste the new version in my response<br>
> yesterday:<br>
><br>
>>from net.imglib2.meta import Axes<br>
><br>
> This import needs to change to:<br>
><br>
> from net.imagej.axis import Axes<br>
><br>
> Sorry about that!<br>
><br>
> Best,<br>
> Mark<br>
><br>
><br>
> On Tue, Jan 13, 2015 at 3:59 PM, Hadrien Mary <<a href="mailto:hadrien.mary@gmail.com">hadrien.mary@gmail.com</a>><br>
> wrote:<br>
>><br>
>> Thank you Mark !<br>
>><br>
>> Sorry if it's off topic but I tried to run my script and I got a<br>
>> python error probably related to type difference between python and<br>
>> java. It's not the first time I saw this kind of message and I'd like<br>
>> to know how to resolve it. Note that for python script I mainly use<br>
>> javadoc as documentation.<br>
>><br>
>> The error is below coming from almost the same script as before in this<br>
>> thread.<br>
>><br>
>> ********************************<br>
>> Started test_open_save.py at Tue Jan 13 22:54:36 CET 2015<br>
>> Traceback (most recent call last):<br>
>>   File<br>
>> "/home/hadim/Documents/phd/dev/scripts/imagej_scripts/test_open_save.py",<br>
>> line 17, in <module><br>
>>     config.imgOpenerSetRegion(ImageRegion(axes, ranges))<br>
>> TypeError: io.scif.img.ImageRegion(): 1st arg can't be coerced to<br>
>> net.imagej.axis.AxisType[]<br>
>><br>
>> at org.python.core.Py.TypeError(Py.java:235)<br>
>> at<br>
>> org.python.core.PyReflectedFunction.throwError(PyReflectedFunction.java:209)<br>
>> at<br>
>> org.python.core.PyReflectedFunction.throwBadArgError(PyReflectedFunction.java:312)<br>
>> at<br>
>> org.python.core.PyReflectedFunction.throwError(PyReflectedFunction.java:321)<br>
>> at<br>
>> org.python.core.PyReflectedConstructor.__call__(PyReflectedConstructor.java:176)<br>
>> at org.python.core.PyObject.__call__(PyObject.java:345)<br>
>> at org.python.core.PyMethod.instancemethod___call__(PyMethod.java:220)<br>
>> at org.python.core.PyMethod.__call__(PyMethod.java:211)<br>
>> at org.python.core.PyMethod.__call__(PyMethod.java:206)<br>
>> at org.python.core.Deriveds.dispatch__init__(Deriveds.java:19)<br>
>> at<br>
>> org.python.core.PyObjectDerived.dispatch__init__(PyObjectDerived.java:1057)<br>
>> at org.python.core.PyType.type___call__(PyType.java:1565)<br>
>> at org.python.core.PyType.__call__(PyType.java:1548)<br>
>> at org.python.core.PyObject.__call__(PyObject.java:404)<br>
>> at org.python.core.PyObject.__call__(PyObject.java:408)<br>
>> at<br>
>> org.python.pycode._pyx0.f$0(/home/hadim/Documents/phd/dev/scripts/imagej_scripts/test_open_save.py:26)<br>
>> at<br>
>> org.python.pycode._pyx0.call_function(/home/hadim/Documents/phd/dev/scripts/imagej_scripts/test_open_save.py)<br>
>> at org.python.core.PyTableCode.call(PyTableCode.java:165)<br>
>> at org.python.core.PyCode.call(PyCode.java:18)<br>
>> at org.python.core.Py.runCode(Py.java:1275)<br>
>> at<br>
>> org.scijava.plugins.scripting.jython.JythonScriptEngine.eval(JythonScriptEngine.java:76)<br>
>> at org.scijava.script.ScriptModule.run(ScriptModule.java:175)<br>
>> at org.scijava.module.ModuleRunner.run(ModuleRunner.java:167)<br>
>> at org.scijava.module.ModuleRunner.call(ModuleRunner.java:126)<br>
>> at org.scijava.module.ModuleRunner.call(ModuleRunner.java:65)<br>
>> at<br>
>> org.scijava.thread.DefaultThreadService$2.call(DefaultThreadService.java:164)<br>
>> at java.util.concurrent.FutureTask.run(FutureTask.java:262)<br>
>> at<br>
>> java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)<br>
>> at<br>
>> java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)<br>
>> at java.lang.Thread.run(Thread.java:745)<br>
>> ************************************<br>
>><br>
>> --<br>
>> Hadrien Mary<br>
>><br>
>> Ph.D student in Biology<br>
>> Tournier-Gachet Team<br>
>> CNRS - LBCMCP - UMR 5088<br>
>><br>
>> Université de Toulouse - Bât. 4R3B1<br>
>> 118, route de Narbonne - 31062 Toulouse<br>
>><br>
>><br>
>> On Tue, Jan 13, 2015 at 10:20 PM, Mark Hiner <<a href="mailto:hiner@wisc.edu">hiner@wisc.edu</a>> wrote:<br>
>> > Hi Hadrien,<br>
>> ><br>
>> >  Unsurprisingly, cropping and writing OME-TIFFs was quite broken.<br>
>> ><br>
>> >  It's working for me now, as of the latest SCIFIO[1] and<br>
>> > SCIFIO-OME-XML[2].<br>
>> > Note that these libraries have updated dependencies compared to what's<br>
>> > currently on Fiji, so you can't just drop these .jars into your Fiji<br>
>> > installation if you want to test locally; you need to update the<br>
>> > dependencies as well. The easiest way to do this would be to just clone<br>
>> > Imagej.git[3] and install it into your Fiji.app directory by running:<br>
>> ><br>
>> > mvn -Dimagej.app.directory=/path/to/Fiji.app/<br>
>> > -Ddelete.other.versions=true<br>
>> ><br>
>> > We'll push these changes up to Fiji this week, and I will find or write<br>
>> > better instructions for local testing.<br>
>> ><br>
>> > Hope this helps. Let us know if you have any questions/problems. Thanks<br>
>> > again for finding this issue!<br>
>> ><br>
>> > Best,<br>
>> > - Mark<br>
>> ><br>
>> > [1] <a href="https://github.com/scifio/scifio/releases/tag/scifio-0.19.0" target="_blank">https://github.com/scifio/scifio/releases/tag/scifio-0.19.0</a><br>
>> > [2]<br>
>> ><br>
>> > <a href="https://github.com/scifio/scifio-ome-xml/releases/tag/scifio-ome-xml-0.12.0" target="_blank">https://github.com/scifio/scifio-ome-xml/releases/tag/scifio-ome-xml-0.12.0</a><br>
>> > [3] <a href="https://github.com/imagej/imagej" target="_blank">https://github.com/imagej/imagej</a><br>
>> ><br>
>> > On Sat, Jan 10, 2015 at 5:13 AM, Hadrien Mary <<a href="mailto:hadrien.mary@gmail.com">hadrien.mary@gmail.com</a>><br>
>> > wrote:<br>
>> >><br>
>> >> Ok. Let me know when you want me to test your changes. I also tested<br>
>> >> fix-writing branch and I didn't notice any changes.<br>
>> >><br>
>> >> --<br>
>> >> Hadrien Mary<br>
>> >><br>
>> >> Ph.D student in Biology<br>
>> >> Tournier-Gachet Team<br>
>> >> CNRS - LBCMCP - UMR 5088<br>
>> >><br>
>> >> Université de Toulouse - Bât. 4R3B1<br>
>> >> 118, route de Narbonne - 31062 Toulouse<br>
>> >><br>
>> >><br>
>> >> On Fri, Jan 9, 2015 at 10:14 PM, Mark Hiner <<a href="mailto:hiner@wisc.edu">hiner@wisc.edu</a>> wrote:<br>
>> >> > Hi Hadrien,<br>
>> >> ><br>
>> >> > I've identified at least two bugs that could be affecting you here.<br>
>> >> ><br>
>> >> > First of all, there was a bug in the OME-TIFF format writing out<br>
>> >> > multi-dimensional images. That's fixed on a branch but not uploaded<br>
>> >> > to<br>
>> >> > Fiji<br>
>> >> > yet [1].<br>
>> >> ><br>
>> >> > Second, it seems like cropping is restricting pixel reads to the<br>
>> >> > correct<br>
>> >> > region but then doesn't change the image size.<br>
>> >> ><br>
>> >> > I'm hoping when I fix the second issue writing cropped regions will<br>
>> >> > be<br>
>> >> > fixed.<br>
>> >> ><br>
>> >> > Thanks for the great feedback!<br>
>> >> > - Mark<br>
>> >> ><br>
>> >> > [1] <a href="https://github.com/scifio/scifio-ome-xml/tree/fix-writing" target="_blank">https://github.com/scifio/scifio-ome-xml/tree/fix-writing</a><br>
>> >> ><br>
>> >> > On Fri, Jan 9, 2015 at 11:49 AM, Hadrien Mary<br>
>> >> > <<a href="mailto:hadrien.mary@gmail.com">hadrien.mary@gmail.com</a>><br>
>> >> > wrote:<br>
>> >> >><br>
>> >> >> I also confirm the same behaviour when replacing original file by<br>
>> >> >> OME<br>
>> >> >> sample data :<br>
>> >> >><br>
>> >> >><br>
>> >> >> <a href="http://www.openmicroscopy.org/Schemas/Samples/2013-06/bioformats-artificial/multi-channel-4D-series.ome.tif.zip" target="_blank">http://www.openmicroscopy.org/Schemas/Samples/2013-06/bioformats-artificial/multi-channel-4D-series.ome.tif.zip</a>.<br>
>> >> >><br>
>> >> >> --<br>
>> >> >> Hadrien Mary<br>
>> >> >><br>
>> >> >> Ph.D student in Biology<br>
>> >> >> Tournier-Gachet Team<br>
>> >> >> CNRS - LBCMCP - UMR 5088<br>
>> >> >><br>
>> >> >> Université de Toulouse - Bât. 4R3B1<br>
>> >> >> 118, route de Narbonne - 31062 Toulouse<br>
>> >> >><br>
>> >> >><br>
>> >> >> On Fri, Jan 9, 2015 at 6:46 PM, Hadrien Mary<br>
>> >> >> <<a href="mailto:hadrien.mary@gmail.com">hadrien.mary@gmail.com</a>><br>
>> >> >> wrote:<br>
>> >> >> > After some investigations I think there is a bug with ImgSaver. In<br>
>> >> >> > the<br>
>> >> >> > following script, X, Y crop is fine but axes informations (T and<br>
>> >> >> > Z)<br>
>> >> >> > are lost and all frames appears on the same axes. Now if I replace<br>
>> >> >> > "target = "/home/hadim/cropped.tif" by "target =<br>
>> >> >> > "/home/hadim/cropped.ome.tif" on line 9. X, Y crop fails, cropped<br>
>> >> >> > image has the same dimensions than original however axes<br>
>> >> >> > informations<br>
>> >> >> > (T and Z) are ok. Note that in cropped.ome.tif, pixel values are<br>
>> >> >> > totally incoherent which is not the case in cropped.tif.<br>
>> >> >> ><br>
>> >> >> > Files can be found here :<br>
>> >> >> ><br>
>> >> >> ><br>
>> >> >> ><br>
>> >> >> > <a href="https://arwen.hadim.fr/public.php?service=files&t=71aa17336dcccb3437d9a3dff789d2c0" target="_blank">https://arwen.hadim.fr/public.php?service=files&t=71aa17336dcccb3437d9a3dff789d2c0</a><br>
>> >> >> ><br>
>> >> >> > Archive contains cropped.tif, cropped.ome.tif and<br>
>> >> >> > original.ome.tif.<br>
>> >> >> ><br>
>> >> >> > The script:<br>
>> >> >> ><br>
>> >> >> > ---------------------------------------------------<br>
>> >> >> > from io.scif import SCIFIO<br>
>> >> >> > from io.scif.config import SCIFIOConfig<br>
>> >> >> > from io.scif.img import ImageRegion<br>
>> >> >> > from io.scif.img import ImgOpener<br>
>> >> >> > from io.scif.img import ImgSaver<br>
>> >> >> > from net.imglib2.meta import Axes<br>
>> >> >> ><br>
>> >> >> > fname = "/home/hadim/original.ome.tif"<br>
>> >> >> > target = "/home/hadim/cropped.tif"<br>
>> >> >> ><br>
>> >> >> > axes = [Axes.X, Axes.Y]<br>
>> >> >> > ranges = ["%i-%i" % (0, 15), "%i-%i" % (0, 25)]<br>
>> >> >> > config = SCIFIOConfig()<br>
>> >> >> > config.imgOpenerSetRegion(ImageRegion(axes, ranges))<br>
>> >> >> ><br>
>> >> >> > opener = ImgOpener()<br>
>> >> >> > imps = opener.openImgs(fname, config)<br>
>> >> >> > imp = imps[0]<br>
>> >> >> ><br>
>> >> >> > saver = ImgSaver()<br>
>> >> >> > saver.saveImg(target, imp)<br>
>> >> >> ><br>
>> >> >> > print('Done')<br>
>> >> >> > ---------------------------------------------------<br>
>> >> >> ><br>
>> >> >> ><br>
>> >> >> > --<br>
>> >> >> > Hadrien Mary<br>
>> >> >> ><br>
>> >> >> ><br>
>> >> >> > On Fri, Jan 9, 2015 at 12:25 AM, Hadrien Mary<br>
>> >> >> > <<a href="mailto:hadrien.mary@gmail.com">hadrien.mary@gmail.com</a>><br>
>> >> >> > wrote:<br>
>> >> >> >> Thanks for the tip (reminder to me: always look for example in<br>
>> >> >> >> tests!).<br>
>> >> >> >><br>
>> >> >> >> Unfortunately crop does not work... I will try to do more tests<br>
>> >> >> >> tomorrow or wait for you or someone else to have a look.<br>
>> >> >> >><br>
>> >> >> >> Updated code:<br>
>> >> >> >><br>
>> >> >> >> from ij import IJ<br>
>> >> >> >> from ij import ImagePlus<br>
>> >> >> >><br>
>> >> >> >> from io.scif import SCIFIO<br>
>> >> >> >> from io.scif.config import SCIFIOConfig<br>
>> >> >> >> from io.scif.img import ImageRegion<br>
>> >> >> >> from io.scif.img import ImgOpener<br>
>> >> >> >> from io.scif.img import ImgSaver<br>
>> >> >> >> from net.imglib2.meta import Axes<br>
>> >> >> >><br>
>> >> >> >> fname = "/home/hadim/original.ome.tif"<br>
>> >> >> >> target = "/home/hadim/cropped.ome.tif"<br>
>> >> >> >><br>
>> >> >> >> axes = [Axes.X, Axes.Y]<br>
>> >> >> >> ranges = ["%i-%i" % (2, 15), "%i-%i" % (2, 25)]<br>
>> >> >> >> config = SCIFIOConfig()<br>
>> >> >> >> config.imgOpenerSetRegion(ImageRegion(axes, ranges))<br>
>> >> >> >><br>
>> >> >> >> opener = ImgOpener()<br>
>> >> >> >> imps = opener.openImgs(fname, config)<br>
>> >> >> >> imp = imps[0]<br>
>> >> >> >><br>
>> >> >> >> saver = ImgSaver()<br>
>> >> >> >> saver.saveImg(target, imp)<br>
>> >> >> >><br>
>> >> >> >> print('Done')<br>
>> >> >> >><br>
>> >> >> >> --<br>
>> >> >> >> Hadrien Mary<br>
>> >> >> >><br>
>> >> >> >><br>
>> >> >> >> On Fri, Jan 9, 2015 at 12:09 AM, Curtis Rueden<br>
>> >> >> >> <<a href="mailto:ctrueden@wisc.edu">ctrueden@wisc.edu</a>><br>
>> >> >> >> wrote:<br>
>> >> >> >>> Hi Hadrien,<br>
>> >> >> >>><br>
>> >> >> >>>> I would like to be able to crop a region in X and Y while<br>
>> >> >> >>>> keeping any other dimensions which could exist (C, Z, T).<br>
>> >> >> >>><br>
>> >> >> >>> Here's some Java:<br>
>> >> >> >>><br>
>> >> >> >>>     int minX = 128, maxX = 255, minY = 128, minY = 255;<br>
>> >> >> >>>     AxisType[] axes = { Axes.X, Axes.Y };<br>
>> >> >> >>>     String[] ranges = { minX + "-" + maxX, minY + "-" + maxY };<br>
>> >> >> >>>     config.imgOpenerSetRegion(new ImageRegion(axes, ranges));<br>
>> >> >> >>><br>
>> >> >> >>> Adapted from here:<br>
>> >> >> >>><br>
>> >> >> >>><br>
>> >> >> >>><br>
>> >> >> >>> <a href="https://github.com/scifio/scifio/blob/scifio-0.18.0/src/test/java/io/scif/img/utests/ImgOpenerTest.java#L189-L191" target="_blank">https://github.com/scifio/scifio/blob/scifio-0.18.0/src/test/java/io/scif/img/utests/ImgOpenerTest.java#L189-L191</a><br>
>> >> >> >>><br>
>> >> >> >>> And untested.<br>
>> >> >> >>><br>
>> >> >> >>> HTH,<br>
>> >> >> >>> Curtis<br>
>> >> >> >>><br>
>> >> >> >>> On Thu, Jan 8, 2015 at 4:47 PM, Hadrien Mary<br>
>> >> >> >>> <<a href="mailto:hadrien.mary@gmail.com">hadrien.mary@gmail.com</a>><br>
>> >> >> >>> wrote:<br>
>> >> >> >>>><br>
>> >> >> >>>> After some investigations, I'm pretty sure I don't instanciate<br>
>> >> >> >>>> ImageRegion correctly. Doc and source code didn't help me... I<br>
>> >> >> >>>> would<br>
>> >> >> >>>> like to be able to crop a region in X and Y while keeping any<br>
>> >> >> >>>> other<br>
>> >> >> >>>> dimensions which could exist (C, Z, T).<br>
>> >> >> >>>><br>
>> >> >> >>>> --<br>
>> >> >> >>>> Hadrien Mary<br>
>> >> >> >>>><br>
>> >> >> >>>><br>
>> >> >> >>>><br>
>> >> >> >>>> On Thu, Jan 8, 2015 at 10:22 PM, Hadrien Mary<br>
>> >> >> >>>> <<a href="mailto:hadrien.mary@gmail.com">hadrien.mary@gmail.com</a>><br>
>> >> >> >>>> wrote:<br>
>> >> >> >>>> > Thank you Curtis for the answer.<br>
>> >> >> >>>> ><br>
>> >> >> >>>> > I tried to apply what you told me and the code now works<br>
>> >> >> >>>> > without<br>
>> >> >> >>>> > error. However the saved cropped image is not cropped (same<br>
>> >> >> >>>> > size<br>
>> >> >> >>>> > as<br>
>> >> >> >>>> > original) and pixel values are modified).<br>
>> >> >> >>>> ><br>
>> >> >> >>>> > Script:<br>
>> >> >> >>>> ><br>
>> >> >> >>>> > from io.scif.config import SCIFIOConfig<br>
>> >> >> >>>> > from io.scif.img import ImageRegion<br>
>> >> >> >>>> > from io.scif.img import ImgOpener<br>
>> >> >> >>>> > from io.scif.img import ImgSaver<br>
>> >> >> >>>> ><br>
>> >> >> >>>> > fname = "/home/hadim/original.ome.tif"<br>
>> >> >> >>>> > target = "/home/hadim/cropped.ome.tif"<br>
>> >> >> >>>> ><br>
>> >> >> >>>> > config = SCIFIOConfig()<br>
>> >> >> >>>> > region = ImageRegion(dict(x=2, y=2, width=10, height=10))<br>
>> >> >> >>>> > config.imgOpenerSetRegion(region)<br>
>> >> >> >>>> ><br>
>> >> >> >>>> > opener = ImgOpener()<br>
>> >> >> >>>> > imps = opener.openImgs(fname, config)<br>
>> >> >> >>>> > imp = imps[0]<br>
>> >> >> >>>> ><br>
>> >> >> >>>> > print(imps)<br>
>> >> >> >>>> ><br>
>> >> >> >>>> > saver = ImgSaver()<br>
>> >> >> >>>> > saver.saveImg(target, imp)<br>
>> >> >> >>>> ><br>
>> >> >> >>>> > Thanks again for your time. Don't be sorry if you don't have<br>
>> >> >> >>>> > time<br>
>> >> >> >>>> > to<br>
>> >> >> >>>> > write an example.<br>
>> >> >> >>>> ><br>
>> >> >> >>>> > I will be happy to provide some python/scifio examples<br>
>> >> >> >>>> > scripts.<br>
>> >> >> >>>> ><br>
>> >> >> >>>> ><br>
>> >> >> >>>> > --<br>
>> >> >> >>>> > Hadrien Mary<br>
>> >> >> >>>> ><br>
>> >> >> >>>> > Ph.D student in Biology<br>
>> >> >> >>>> > Tournier-Gachet Team<br>
>> >> >> >>>> > CNRS - LBCMCP - UMR 5088<br>
>> >> >> >>>> ><br>
>> >> >> >>>> > Université de Toulouse - Bât. 4R3B1<br>
>> >> >> >>>> > 118, route de Narbonne - 31062 Toulouse<br>
>> >> >> >>>> ><br>
>> >> >> >>>> ><br>
>> >> >> >>>> > On Thu, Jan 8, 2015 at 9:56 PM, Curtis Rueden<br>
>> >> >> >>>> > <<a href="mailto:ctrueden@wisc.edu">ctrueden@wisc.edu</a>><br>
>> >> >> >>>> > wrote:<br>
>> >> >> >>>> >> Hi Hadrien,<br>
>> >> >> >>>> >><br>
>> >> >> >>>> >>> I tried to use SCIFIO to write cropped image on disk but it<br>
>> >> >> >>>> >>> doesn<br>
>> >> >> >>>> >>> not<br>
>> >> >> >>>> >>> work.<br>
>> >> >> >>>> >><br>
>> >> >> >>>> >> The error you see is because SCIFIO operates on ImgLib2 data<br>
>> >> >> >>>> >> structures, not<br>
>> >> >> >>>> >> ImagePlus objects.<br>
>> >> >> >>>> >><br>
>> >> >> >>>> >>> Is there is any “easy” alternative to BF setCropRegion<br>
>> >> >> >>>> >>> function<br>
>> >> >> >>>> >>> in<br>
>> >> >> >>>> >>> SCIFIO ?<br>
>> >> >> >>>> >><br>
>> >> >> >>>> >> Yes: you create a SCIFIOConfig, calling imgOpenerSetRegion<br>
>> >> >> >>>> >> [1]<br>
>> >> >> >>>> >> on<br>
>> >> >> >>>> >> it,<br>
>> >> >> >>>> >> then<br>
>> >> >> >>>> >> pass it as an argument to the ImgOpener. You'll get back an<br>
>> >> >> >>>> >> ImgLib2<br>
>> >> >> >>>> >> data<br>
>> >> >> >>>> >> object which can then be fed to the SCIFIO ImgSaver.<br>
>> >> >> >>>> >><br>
>> >> >> >>>> >> I'm sorry that I don't have time to whip up an example for<br>
>> >> >> >>>> >> you<br>
>> >> >> >>>> >> right<br>
>> >> >> >>>> >> now. It<br>
>> >> >> >>>> >> would be great to add more SCIFIO tutorials [2] that use the<br>
>> >> >> >>>> >> ImgOpener<br>
>> >> >> >>>> >> and<br>
>> >> >> >>>> >> ImgSaver, since they are much higher level APIs akin to the<br>
>> >> >> >>>> >> Bio-Formats<br>
>> >> >> >>>> >> "BF"<br>
>> >> >> >>>> >> functionality... please feel welcome to contribute some!<br>
>> >> >> >>>> >><br>
>> >> >> >>>> >> Regards,<br>
>> >> >> >>>> >> Curtis<br>
>> >> >> >>>> >><br>
>> >> >> >>>> >> [1]<br>
>> >> >> >>>> >><br>
>> >> >> >>>> >><br>
>> >> >> >>>> >><br>
>> >> >> >>>> >><br>
>> >> >> >>>> >> <a href="http://javadoc.imagej.net/SCIFIO/io/scif/config/SCIFIOConfig.html#imgOpenerSetRegion(io.scif.img.ImageRegion)" target="_blank">http://javadoc.imagej.net/SCIFIO/io/scif/config/SCIFIOConfig.html#imgOpenerSetRegion(io.scif.img.ImageRegion)</a><br>
>> >> >> >>>> >> [2] <a href="https://github.com/scifio/scifio-tutorials" target="_blank">https://github.com/scifio/scifio-tutorials</a><br>
>> >> >> >>>> >><br>
>> >> >> >>>> >> On Thu, Jan 8, 2015 at 2:18 PM, Hadrien Mary<br>
>> >> >> >>>> >> <<a href="mailto:hadrien.mary@gmail.com">hadrien.mary@gmail.com</a>><br>
>> >> >> >>>> >> wrote:<br>
>> >> >> >>>> >>><br>
>> >> >> >>>> >>> Hi,<br>
>> >> >> >>>> >>><br>
>> >> >> >>>> >>> I am writing a python macro which iterate over all rois in<br>
>> >> >> >>>> >>> ROI<br>
>> >> >> >>>> >>> Manager<br>
>> >> >> >>>> >>> and then use setCropRegion function from bioformat plugin<br>
>> >> >> >>>> >>> to<br>
>> >> >> >>>> >>> open<br>
>> >> >> >>>> >>> a<br>
>> >> >> >>>> >>> cropped region of an image.<br>
>> >> >> >>>> >>><br>
>> >> >> >>>> >>> I tried to use SCIFIO to write cropped image on disk but it<br>
>> >> >> >>>> >>> doesn<br>
>> >> >> >>>> >>> not<br>
>> >> >> >>>> >>> work.<br>
>> >> >> >>>> >>><br>
>> >> >> >>>> >>> (I am using an updated version of Fiji.)<br>
>> >> >> >>>> >>><br>
>> >> >> >>>> >>> Here is my script:<br>
>> >> >> >>>> >>><br>
>> >> >> >>>> >>> from ij.plugin.frame import RoiManager<br>
>> >> >> >>>> >>> from ij import IJ<br>
>> >> >> >>>> >>> from io.scif.img import ImgSaver<br>
>> >> >> >>>> >>><br>
>> >> >> >>>> >>> from loci.plugins import BF<br>
>> >> >> >>>> >>> from <a href="http://loci.plugins.in" target="_blank">loci.plugins.in</a> import ImporterOptions<br>
>> >> >> >>>> >>> from loci.common import Region<br>
>> >> >> >>>> >>><br>
>> >> >> >>>> >>> import os<br>
>> >> >> >>>> >>><br>
>> >> >> >>>> >>> # Get current image filename<br>
>> >> >> >>>> >>> imp = IJ.getImage()<br>
>> >> >> >>>> >>> f = imp.getOriginalFileInfo()<br>
>> >> >> >>>> >>> fname = os.path.join(f.directory, f.fileName)<br>
>> >> >> >>>> >>><br>
>> >> >> >>>> >>> IJ.log('Image filename is %s' % fname)<br>
>> >> >> >>>> >>><br>
>> >> >> >>>> >>> # Iterate over all ROIs from ROI Manager<br>
>> >> >> >>>> >>> rois = RoiManager.getInstance().getRoisAsArray()<br>
>> >> >> >>>> >>> for i, roi in enumerate(rois):<br>
>> >> >> >>>> >>><br>
>> >> >> >>>> >>>     crop_id = i +1<br>
>> >> >> >>>> >>>     IJ.log("Opening crop %i / %i" % (crop_id, len(rois)))<br>
>> >> >> >>>> >>><br>
>> >> >> >>>> >>>     bounds = roi.getBounds()<br>
>> >> >> >>>> >>><br>
>> >> >> >>>> >>>     x = bounds.x<br>
>> >> >> >>>> >>>     y = bounds.y<br>
>> >> >> >>>> >>>     w = bounds.width<br>
>> >> >> >>>> >>>     h = bounds.height<br>
>> >> >> >>>> >>><br>
>> >> >> >>>> >>>     # Import only cropped region of the image<br>
>> >> >> >>>> >>>     options = ImporterOptions()<br>
>> >> >> >>>> >>>     options.setCrop(True)<br>
>> >> >> >>>> >>>     options.setCropRegion(0, Region(x, y, w, h))<br>
>> >> >> >>>> >>>     options.setId(fname)<br>
>> >> >> >>>> >>>     imps = BF.openImagePlus(options)<br>
>> >> >> >>>> >>><br>
>> >> >> >>>> >>>     imp = imps[0]<br>
>> >> >> >>>> >>>     imp.show()<br>
>> >> >> >>>> >>><br>
>> >> >> >>>> >>>     crop_basename = "crop%i_%s" % (crop_id, f.fileName)<br>
>> >> >> >>>> >>>     crop_fname = os.path.join(f.directory, crop_basename)<br>
>> >> >> >>>> >>>     imp.setTitle(crop_basename)<br>
>> >> >> >>>> >>><br>
>> >> >> >>>> >>>     # Save image<br>
>> >> >> >>>> >>>     IJ.log("Saving crop to %s" % crop_fname)<br>
>> >> >> >>>> >>>     saver = ImgSaver()<br>
>> >> >> >>>> >>>     saver.saveImg(crop_basename, imp)<br>
>> >> >> >>>> >>><br>
>> >> >> >>>> >>> IJ.log('Done')<br>
>> >> >> >>>> >>><br>
>> >> >> >>>> >>> It fails with this error:<br>
>> >> >> >>>> >>><br>
>> >> >> >>>> >>> Traceback (most recent call last):<br>
>> >> >> >>>> >>>   File<br>
>> >> >> >>>> >>> "/home/hadim/local/Fiji.app/plugins/Crop_Multi_Roi.py",<br>
>> >> >> >>>> >>> line<br>
>> >> >> >>>> >>> 49, in <module><br>
>> >> >> >>>> >>>     saver.saveImg(crop_basename, imp)<br>
>> >> >> >>>> >>> TypeError: saveImg(): 1st arg can't be coerced to<br>
>> >> >> >>>> >>> io.scif.Writer,<br>
>> >> >> >>>> >>> String<br>
>> >> >> >>>> >>><br>
>> >> >> >>>> >>> at org.python.core.Py.TypeError(Py.java:235)<br>
>> >> >> >>>> >>> at<br>
>> >> >> >>>> >>><br>
>> >> >> >>>> >>><br>
>> >> >> >>>> >>><br>
>> >> >> >>>> >>><br>
>> >> >> >>>> >>> org.python.core.PyReflectedFunction.throwError(PyReflectedFunction.java:209)<br>
>> >> >> >>>> >>> at<br>
>> >> >> >>>> >>><br>
>> >> >> >>>> >>><br>
>> >> >> >>>> >>><br>
>> >> >> >>>> >>><br>
>> >> >> >>>> >>> org.python.core.PyReflectedFunction.throwBadArgError(PyReflectedFunction.java:312)<br>
>> >> >> >>>> >>> at<br>
>> >> >> >>>> >>><br>
>> >> >> >>>> >>><br>
>> >> >> >>>> >>><br>
>> >> >> >>>> >>><br>
>> >> >> >>>> >>> org.python.core.PyReflectedFunction.throwError(PyReflectedFunction.java:321)<br>
>> >> >> >>>> >>> at<br>
>> >> >> >>>> >>><br>
>> >> >> >>>> >>><br>
>> >> >> >>>> >>><br>
>> >> >> >>>> >>><br>
>> >> >> >>>> >>> org.python.core.PyReflectedFunction.__call__(PyReflectedFunction.java:167)<br>
>> >> >> >>>> >>> at<br>
>> >> >> >>>> >>><br>
>> >> >> >>>> >>><br>
>> >> >> >>>> >>><br>
>> >> >> >>>> >>><br>
>> >> >> >>>> >>> org.python.core.PyReflectedFunction.__call__(PyReflectedFunction.java:204)<br>
>> >> >> >>>> >>> at org.python.core.PyObject.__call__(PyObject.java:422)<br>
>> >> >> >>>> >>> at org.python.core.PyObject.__call__(PyObject.java:426)<br>
>> >> >> >>>> >>> at org.python.core.PyMethod.__call__(PyMethod.java:139)<br>
>> >> >> >>>> >>> at<br>
>> >> >> >>>> >>><br>
>> >> >> >>>> >>><br>
>> >> >> >>>> >>><br>
>> >> >> >>>> >>><br>
>> >> >> >>>> >>> org.python.pycode._pyx7.f$0(/home/hadim/local/Fiji.app/plugins/Crop_Multi_Roi.py:51)<br>
>> >> >> >>>> >>> at<br>
>> >> >> >>>> >>><br>
>> >> >> >>>> >>><br>
>> >> >> >>>> >>><br>
>> >> >> >>>> >>><br>
>> >> >> >>>> >>> org.python.pycode._pyx7.call_function(/home/hadim/local/Fiji.app/plugins/Crop_Multi_Roi.py)<br>
>> >> >> >>>> >>> at org.python.core.PyTableCode.call(PyTableCode.java:165)<br>
>> >> >> >>>> >>> at org.python.core.PyCode.call(PyCode.java:18)<br>
>> >> >> >>>> >>> at org.python.core.Py.runCode(Py.java:1275)<br>
>> >> >> >>>> >>> at<br>
>> >> >> >>>> >>><br>
>> >> >> >>>> >>><br>
>> >> >> >>>> >>><br>
>> >> >> >>>> >>><br>
>> >> >> >>>> >>> org.scijava.plugins.scripting.jython.JythonScriptEngine.eval(JythonScriptEngine.java:76)<br>
>> >> >> >>>> >>> at<br>
>> >> >> >>>> >>> org.scijava.script.ScriptModule.run(ScriptModule.java:175)<br>
>> >> >> >>>> >>> at<br>
>> >> >> >>>> >>> org.scijava.module.ModuleRunner.run(ModuleRunner.java:167)<br>
>> >> >> >>>> >>> at<br>
>> >> >> >>>> >>> org.scijava.module.ModuleRunner.call(ModuleRunner.java:126)<br>
>> >> >> >>>> >>> at<br>
>> >> >> >>>> >>> org.scijava.module.ModuleRunner.call(ModuleRunner.java:65)<br>
>> >> >> >>>> >>> at<br>
>> >> >> >>>> >>><br>
>> >> >> >>>> >>><br>
>> >> >> >>>> >>><br>
>> >> >> >>>> >>><br>
>> >> >> >>>> >>> org.scijava.thread.DefaultThreadService$2.call(DefaultThreadService.java:164)<br>
>> >> >> >>>> >>> at java.util.concurrent.FutureTask.run(FutureTask.java:262)<br>
>> >> >> >>>> >>> at<br>
>> >> >> >>>> >>><br>
>> >> >> >>>> >>><br>
>> >> >> >>>> >>><br>
>> >> >> >>>> >>><br>
>> >> >> >>>> >>> java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)<br>
>> >> >> >>>> >>> at<br>
>> >> >> >>>> >>><br>
>> >> >> >>>> >>><br>
>> >> >> >>>> >>><br>
>> >> >> >>>> >>><br>
>> >> >> >>>> >>> java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)<br>
>> >> >> >>>> >>> at java.lang.Thread.run(Thread.java:745)<br>
>> >> >> >>>> >>><br>
>> >> >> >>>> >>> Three questions:<br>
>> >> >> >>>> >>><br>
>> >> >> >>>> >>> how can I write cropped image (I need to write them as OME<br>
>> >> >> >>>> >>> Tiff<br>
>> >> >> >>>> >>> so I<br>
>> >> >> >>>> >>> need BF or SCIFIO).<br>
>> >> >> >>>> >>> Is there is any “easy” alternative to BF setCropRegion<br>
>> >> >> >>>> >>> function<br>
>> >> >> >>>> >>> in<br>
>> >> >> >>>> >>> SCIFIO<br>
>> >> >> >>>> >>> ?<br>
>> >> >> >>>> >>> I am currently using<br>
>> >> >> >>>> >>> RoiManager.getInstance().getRoisAsArray()<br>
>> >> >> >>>> >>> to<br>
>> >> >> >>>> >>> retrieve all rois. How can I directly get a ROIManager<br>
>> >> >> >>>> >>> instance<br>
>> >> >> >>>> >>> from<br>
>> >> >> >>>> >>> RoiSet.zip file ?<br>
>> >> >> >>>> >>><br>
>> >> >> >>>> >>> Any help would be very appreciated.<br>
>> >> >> >>>> >>><br>
>> >> >> >>>> >>> Thanks !<br>
>> >> >> >>>> >>><br>
>> >> >> >>>> >>> —<br>
>> >> >> >>>> >>> Hadrien Mary<br>
>> >> >> >>>> >>><br>
>> >> >> >>>> >>> _______________________________________________<br>
>> >> >> >>>> >>> ImageJ-devel mailing list<br>
>> >> >> >>>> >>> <a href="mailto:ImageJ-devel@imagej.net">ImageJ-devel@imagej.net</a><br>
>> >> >> >>>> >>> <a href="http://imagej.net/mailman/listinfo/imagej-devel" target="_blank">http://imagej.net/mailman/listinfo/imagej-devel</a><br>
>> >> >> >>>> >><br>
>> >> >> >>>> >><br>
>> >> >> >>><br>
>> >> >> >>><br>
>> >> >><br>
>> >> >> _______________________________________________<br>
>> >> >> ImageJ-devel mailing list<br>
>> >> >> <a href="mailto:ImageJ-devel@imagej.net">ImageJ-devel@imagej.net</a><br>
>> >> >> <a href="http://imagej.net/mailman/listinfo/imagej-devel" target="_blank">http://imagej.net/mailman/listinfo/imagej-devel</a><br>
>> >> ><br>
>> >> ><br>
>> ><br>
>> ><br>
><br>
><br>
</div></div></blockquote></div><br></div>