<div dir="ltr">Hi Hadrien,<div><br></div><div>><span style="font-size:12.8000001907349px">I tried to use another method to save cropped images using DatasetService:</span></div><br style="font-size:12.8000001907349px"><div>I couldn't reproduce this failure.. it works for me using the DatasetService. Do you have any local changes? Did you update your Fiji to the latest version? If you're still having problems, you could also copy and paste the "Useful information about your system" contents generated by Help > Report a Bug.</div><div><br></div><div>><span style="font-size:12.8000001907349px"> saver.saveImg(crop_fname, imp)</span><br></div><span style="font-size:12.8000001907349px">> at io.scif.img.cell.loaders.</span><span style="font-size:12.8000001907349px">AbstractArrayLoader.loadArray(</span><span style="font-size:12.8000001907349px">AbstractArrayLoader.java:156)</span><div><div>> j<span style="font-size:12.8000001907349px">ava.lang.</span><span style="font-size:12.8000001907349px">NullPointerException: java.lang.NullPointerException</span></div></div><div><span style="font-size:12.8000001907349px"><br></span></div><div>Yes! This was definitely a bug - thank you for finding it. I think I have a fix here: <a href="https://github.com/scifio/scifio/commits/fix-cell">https://github.com/scifio/scifio/commits/fix-cell</a><br></div><div>Would you mind giving it a try locally in your workflow?</div><div><br></div><div>Thank you!</div><div>- Mark</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Sat, Jan 24, 2015 at 3:01 PM, 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">Quick update:<br>
<br>
I tried to use another method to save cropped images using DatasetService:<br>
<br>
---------------------------<br>
# Create dataset<br>
ds = data.create(imp)<br>
<br>
# Save cropped image<br>
data.save(ds, crop_fname)<br>
-------------------------<br>
<br>
And the error is exactly the same as before.<br>
<span class="im HOEnZb"><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 Tue, Jan 20, 2015 at 10:17 AM, Hadrien Mary <<a href="mailto:hadrien.mary@gmail.com">hadrien.mary@gmail.com</a>> wrote:<br>
> Another thing I noticed, it's that histogram is different when<br>
> cropping manually inside Fiji (select area and do "Duplicate") or when<br>
> it has been cropped with the python script (SCIFIO crop).<br>
><br>
> See screenshot attachment.<br>
><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 Mon, Jan 19, 2015 at 10:29 AM, Hadrien Mary <<a href="mailto:hadrien.mary@gmail.com">hadrien.mary@gmail.com</a>> wrote:<br>
>> Hi again,<br>
>><br>
>> The script works well for small images (OME Tiff or normal Tiff) with<br>
>> the recent Fiji update. However when I run it on large movies (13GB),<br>
>> I have the following error.<br>
>><br>
>> ----------------------------------------------------------<br>
>> -- Classpath of ClassLoader --<br>
>> /home/hadim/local/Fiji.app/plugins/<br>
>><br>
>> at org.scijava.Context.inject(Context.java:431)<br>
>> at org.scijava.Context.inject(Context.java:363)<br>
>> at org.scijava.plugin.DefaultPluginService.createInstance(DefaultPluginService.java:237)<br>
>> at org.scijava.ui.DefaultUIService.discoverUIs(DefaultUIService.java:500)<br>
>> at org.scijava.ui.DefaultUIService.uiList(DefaultUIService.java:479)<br>
>> at org.scijava.ui.DefaultUIService.getAvailableUIs(DefaultUIService.java:231)<br>
>> at org.scijava.ui.DefaultUIService.onEvent(DefaultUIService.java:457)<br>
>> at sun.reflect.GeneratedMethodAccessor5.invoke(Unknown Source)<br>
>> at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)<br>
>> at java.lang.reflect.Method.invoke(Method.java:606)<br>
>> at org.scijava.event.DefaultEventService$ProxySubscriber.onEvent(DefaultEventService.java:280)<br>
>> at org.scijava.event.DefaultEventService$ProxySubscriber.onEvent(DefaultEventService.java:254)<br>
>> at org.bushe.swing.event.ThreadSafeEventService.publish(ThreadSafeEventService.java:971)<br>
>> at org.scijava.event.DefaultEventBus.access$201(DefaultEventBus.java:56)<br>
>> at org.scijava.event.DefaultEventBus$2.run(DefaultEventBus.java:223)<br>
>> at org.scijava.thread.DefaultThreadService$1.run(DefaultThreadService.java:147)<br>
>> at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)<br>
>> at java.util.concurrent.FutureTask.run(FutureTask.java:262)<br>
>> at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)<br>
>> at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)<br>
>> at java.lang.Thread.run(Thread.java:745)<br>
>> Traceback (most recent call last):<br>
>> File "/home/hadim/local/Fiji.app/plugins/Scripts/Plugins/Crop_Multi_Roi.py",<br>
>> line 50, in <module><br>
>> saver.saveImg(crop_fname, imp)<br>
>> at io.scif.img.cell.loaders.AbstractArrayLoader.loadArray(AbstractArrayLoader.java:156)<br>
>> at io.scif.img.cell.SCIFIOCellCache.load(SCIFIOCellCache.java:144)<br>
>> at io.scif.img.cell.SCIFIOImgCells$CachedCells.get(SCIFIOImgCells.java:122)<br>
>> at io.scif.img.cell.SCIFIOImgCells$CachedCells.get(SCIFIOImgCells.java:101)<br>
>> at net.imglib2.img.list.ListCursor.get(ListCursor.java:80)<br>
>> at net.imglib2.img.cell.CellCursor.getCell(CellCursor.java:92)<br>
>> at net.imglib2.img.cell.CellCursor.moveToNextCell(CellCursor.java:180)<br>
>> at net.imglib2.img.cell.CellCursor.reset(CellCursor.java:150)<br>
>> at net.imglib2.img.cell.CellCursor.<init>(CellCursor.java:86)<br>
>> at net.imglib2.img.cell.AbstractCellImg.cursor(AbstractCellImg.java:113)<br>
>> at net.imglib2.img.cell.AbstractCellImg.cursor(AbstractCellImg.java:47)<br>
>> at net.imglib2.img.AbstractImg.firstElement(AbstractImg.java:81)<br>
>> at net.imagej.ImgPlus.firstElement(ImgPlus.java:261)<br>
>> at io.scif.img.ImgSaver.populateMeta(ImgSaver.java:894)<br>
>> at io.scif.img.ImgSaver.writeImg(ImgSaver.java:514)<br>
>> at io.scif.img.ImgSaver.writeImg(ImgSaver.java:495)<br>
>> at io.scif.img.ImgSaver.writeImg(ImgSaver.java:457)<br>
>> at io.scif.img.ImgSaver.saveImg(ImgSaver.java:174)<br>
>> at io.scif.img.ImgSaver.saveImg(ImgSaver.java:158)<br>
>> at io.scif.img.ImgSaver.saveImg(ImgSaver.java:128)<br>
>> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)<br>
>> at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)<br>
>> at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)<br>
>> at java.lang.reflect.Method.invoke(Method.java:606)<br>
>><br>
>> java.lang.NullPointerException: java.lang.NullPointerException<br>
>> -------------------------------------------------------------------<br>
>><br>
>> The associated script is below.<br>
>><br>
>> ------------------------------------------------------------------------<br>
>> from ij import IJ<br>
>> from ij.plugin.frame import RoiManager<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>
>> from net.imagej.axis import Axes<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>
>> # Get ROI bounds<br>
>> bounds = roi.getBounds()<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>
>> axes = [Axes.X, Axes.Y]<br>
>> ranges = ["%i-%i" % (x, x+w), "%i-%i" % (y, y+h)]<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>
>> # Get filename and basename of the current cropped image<br>
>> crop_basename = "crop%i_%s" % (crop_id, f.fileName)<br>
>> crop_fname = os.path.join(f.directory, crop_basename)<br>
>> IJ.log("Saving crop to %s" % crop_fname)<br>
>><br>
>> # Save cropped image<br>
>> saver = ImgSaver()<br>
>> saver.saveImg(crop_fname, imp)<br>
>><br>
>> IJ.log('Done')<br>
>> ----------------------------------------------------------------------------<br>
>><br>
>> Does opener.openImgs() wait for the image to open ? If it does not I<br>
>> guess that saver.saveImg() is called on an image that does not exist<br>
>> in memory.<br>
>><br>
>> Thanks<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 Wed, Jan 14, 2015 at 4:35 PM, Hadrien Mary <<a href="mailto:hadrien.mary@gmail.com">hadrien.mary@gmail.com</a>> wrote:<br>
>>> I confirm it works !<br>
>>><br>
>>> Thanks again<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 Wed, Jan 14, 2015 at 3:32 PM, Mark Hiner <<a href="mailto:hiner@wisc.edu">hiner@wisc.edu</a>> wrote:<br>
>>>> Hi Hadrien,<br>
>>>><br>
>>>>>Exception in thread "DrawAndDrop" java.lang.NoSuchMethodError:<br>
>>>>>io.scif.ImageMetadata.setAxisLength(Lnet/imglib2/meta/AxisType;J)V<br>
>>>><br>
>>>> Ah sorry - my fault again for responding too quickly. ImageJ.git doesn't<br>
>>>> have a dependency on scifio-ome-xml; it's a dependency in Fiji itself[1]. So<br>
>>>> when you installed ImageJ into your Fiji, it updated all the dependencies<br>
>>>> but didn't actually update scifio-ome-xml.<br>
>>>><br>
>>>> You can either manually copy scifio-ome-xml[2] over, or try installing from<br>
>>>> the latest Fiji master[3] which I just updated to have the latest<br>
>>>> dependencies.<br>
>>>><br>
>>>> [1]<br>
>>>> <a href="https://github.com/fiji/fiji/blob/2bc6266ff5ad5dfa155db9c0631db9baae396062/pom.xml#L608-612" target="_blank">https://github.com/fiji/fiji/blob/2bc6266ff5ad5dfa155db9c0631db9baae396062/pom.xml#L608-612</a><br>
>>>> [2]<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]<br>
>>>> <a href="https://github.com/fiji/fiji/commit/2bc6266ff5ad5dfa155db9c0631db9baae396062" target="_blank">https://github.com/fiji/fiji/commit/2bc6266ff5ad5dfa155db9c0631db9baae396062</a><br>
>>>><br>
>>>> On Wed, Jan 14, 2015 at 7:05 AM, Hadrien Mary <<a href="mailto:hadrien.mary@gmail.com">hadrien.mary@gmail.com</a>><br>
>>>> wrote:<br>
>>>>><br>
>>>>> 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<br>
>>>>> 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<br>
>>>>> 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<br>
>>>>> net.imagej.legacy.plugin.DefaultLegacyOpener.open(DefaultLegacyOpener.java:134)<br>
>>>>> at<br>
>>>>> 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>
>>>>><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 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<br>
>>>>> > 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>
>>>>> >><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>
>>>>> >><br>
>>>>> >> org.python.core.PyReflectedFunction.throwError(PyReflectedFunction.java:209)<br>
>>>>> >> at<br>
>>>>> >><br>
>>>>> >> org.python.core.PyReflectedFunction.throwBadArgError(PyReflectedFunction.java:312)<br>
>>>>> >> at<br>
>>>>> >><br>
>>>>> >> org.python.core.PyReflectedFunction.throwError(PyReflectedFunction.java:321)<br>
>>>>> >> at<br>
>>>>> >><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>
>>>>> >><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>
>>>>> >><br>
>>>>> >> org.python.pycode._pyx0.f$0(/home/hadim/Documents/phd/dev/scripts/imagej_scripts/test_open_save.py:26)<br>
>>>>> >> at<br>
>>>>> >><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>
>>>>> >><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>
>>>>> >><br>
>>>>> >> org.scijava.thread.DefaultThreadService$2.call(DefaultThreadService.java:164)<br>
>>>>> >> at java.util.concurrent.FutureTask.run(FutureTask.java:262)<br>
>>>>> >> at<br>
>>>>> >><br>
>>>>> >> java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)<br>
>>>>> >> at<br>
>>>>> >><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<br>
>>>>> >> > 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<br>
>>>>> >> > 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<br>
>>>>> >> > write<br>
>>>>> >> > better instructions for local testing.<br>
>>>>> >> ><br>
>>>>> >> > Hope this helps. Let us know if you have any questions/problems.<br>
>>>>> >> > 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>
>>>>> >> ><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<br>
>>>>> >> > <<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<br>
>>>>> >> >> > 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<br>
>>>>> >> >> > 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<br>
>>>>> >> >> > 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>
>>>>> >> >> >><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.<br>
>>>>> >> >> >> > In<br>
>>>>> >> >> >> > the<br>
>>>>> >> >> >> > following script, X, Y crop is fine but axes informations (T<br>
>>>>> >> >> >> > and<br>
>>>>> >> >> >> > Z)<br>
>>>>> >> >> >> > are lost and all frames appears on the same axes. Now if I<br>
>>>>> >> >> >> > replace<br>
>>>>> >> >> >> > "target = "/home/hadim/cropped.tif" by "target =<br>
>>>>> >> >> >> > "/home/hadim/cropped.ome.tif" on line 9. X, Y crop fails,<br>
>>>>> >> >> >> > 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<br>
>>>>> >> >> >> > are<br>
>>>>> >> >> >> > totally incoherent which is not the case in cropped.tif.<br>
>>>>> >> >> >> ><br>
>>>>> >> >> >> > Files can be found here :<br>
>>>>> >> >> >> ><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<br>
>>>>> >> >> >> >> 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>
>>>>> >> >> >> >>> };<br>
>>>>> >> >> >> >>> config.imgOpenerSetRegion(new ImageRegion(axes, ranges));<br>
>>>>> >> >> >> >>><br>
>>>>> >> >> >> >>> Adapted from here:<br>
>>>>> >> >> >> >>><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<br>
>>>>> >> >> >> >>>> instanciate<br>
>>>>> >> >> >> >>>> ImageRegion correctly. Doc and source code didn't help me...<br>
>>>>> >> >> >> >>>> I<br>
>>>>> >> >> >> >>>> would<br>
>>>>> >> >> >> >>>> like to be able to crop a region in X and Y while keeping<br>
>>>>> >> >> >> >>>> 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<br>
>>>>> >> >> >> >>>> > (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<br>
>>>>> >> >> >> >>>> > 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<br>
>>>>> >> >> >> >>>> >>> it<br>
>>>>> >> >> >> >>>> >>> doesn<br>
>>>>> >> >> >> >>>> >>> not<br>
>>>>> >> >> >> >>>> >>> work.<br>
>>>>> >> >> >> >>>> >><br>
>>>>> >> >> >> >>>> >> The error you see is because SCIFIO operates on ImgLib2<br>
>>>>> >> >> >> >>>> >> 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<br>
>>>>> >> >> >> >>>> >> imgOpenerSetRegion<br>
>>>>> >> >> >> >>>> >> [1]<br>
>>>>> >> >> >> >>>> >> on<br>
>>>>> >> >> >> >>>> >> it,<br>
>>>>> >> >> >> >>>> >> then<br>
>>>>> >> >> >> >>>> >> pass it as an argument to the ImgOpener. You'll get back<br>
>>>>> >> >> >> >>>> >> 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<br>
>>>>> >> >> >> >>>> >> for<br>
>>>>> >> >> >> >>>> >> you<br>
>>>>> >> >> >> >>>> >> right<br>
>>>>> >> >> >> >>>> >> now. It<br>
>>>>> >> >> >> >>>> >> would be great to add more SCIFIO tutorials [2] that use<br>
>>>>> >> >> >> >>>> >> the<br>
>>>>> >> >> >> >>>> >> ImgOpener<br>
>>>>> >> >> >> >>>> >> and<br>
>>>>> >> >> >> >>>> >> ImgSaver, since they are much higher level APIs akin to<br>
>>>>> >> >> >> >>>> >> 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>
>>>>> >> >> >> >>>> >><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<br>
>>>>> >> >> >> >>>> >>> in<br>
>>>>> >> >> >> >>>> >>> ROI<br>
>>>>> >> >> >> >>>> >>> Manager<br>
>>>>> >> >> >> >>>> >>> and then use setCropRegion function from bioformat<br>
>>>>> >> >> >> >>>> >>> 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<br>
>>>>> >> >> >> >>>> >>> 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,<br>
>>>>> >> >> >> >>>> >>> 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,<br>
>>>>> >> >> >> >>>> >>> 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>
>>>>> >> >> >> >>>> >>><br>
>>>>> >> >> >> >>>> >>> org.python.core.PyReflectedFunction.throwError(PyReflectedFunction.java:209)<br>
>>>>> >> >> >> >>>> >>> at<br>
>>>>> >> >> >> >>>> >>><br>
>>>>> >> >> >> >>>> >>><br>
>>>>> >> >> >> >>>> >>><br>
>>>>> >> >> >> >>>> >>><br>
>>>>> >> >> >> >>>> >>><br>
>>>>> >> >> >> >>>> >>> org.python.core.PyReflectedFunction.throwBadArgError(PyReflectedFunction.java:312)<br>
>>>>> >> >> >> >>>> >>> at<br>
>>>>> >> >> >> >>>> >>><br>
>>>>> >> >> >> >>>> >>><br>
>>>>> >> >> >> >>>> >>><br>
>>>>> >> >> >> >>>> >>><br>
>>>>> >> >> >> >>>> >>><br>
>>>>> >> >> >> >>>> >>> org.python.core.PyReflectedFunction.throwError(PyReflectedFunction.java:321)<br>
>>>>> >> >> >> >>>> >>> at<br>
>>>>> >> >> >> >>>> >>><br>
>>>>> >> >> >> >>>> >>><br>
>>>>> >> >> >> >>>> >>><br>
>>>>> >> >> >> >>>> >>><br>
>>>>> >> >> >> >>>> >>><br>
>>>>> >> >> >> >>>> >>> org.python.core.PyReflectedFunction.__call__(PyReflectedFunction.java:167)<br>
>>>>> >> >> >> >>>> >>> at<br>
>>>>> >> >> >> >>>> >>><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>
>>>>> >> >> >> >>>> >>><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>
>>>>> >> >> >> >>>> >>><br>
>>>>> >> >> >> >>>> >>> org.python.pycode._pyx7.call_function(/home/hadim/local/Fiji.app/plugins/Crop_Multi_Roi.py)<br>
>>>>> >> >> >> >>>> >>> at<br>
>>>>> >> >> >> >>>> >>> 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>
>>>>> >> >> >> >>>> >>><br>
>>>>> >> >> >> >>>> >>> org.scijava.plugins.scripting.jython.JythonScriptEngine.eval(JythonScriptEngine.java:76)<br>
>>>>> >> >> >> >>>> >>> at<br>
>>>>> >> >> >> >>>> >>><br>
>>>>> >> >> >> >>>> >>> org.scijava.script.ScriptModule.run(ScriptModule.java:175)<br>
>>>>> >> >> >> >>>> >>> at<br>
>>>>> >> >> >> >>>> >>><br>
>>>>> >> >> >> >>>> >>> org.scijava.module.ModuleRunner.run(ModuleRunner.java:167)<br>
>>>>> >> >> >> >>>> >>> at<br>
>>>>> >> >> >> >>>> >>><br>
>>>>> >> >> >> >>>> >>> org.scijava.module.ModuleRunner.call(ModuleRunner.java:126)<br>
>>>>> >> >> >> >>>> >>> at<br>
>>>>> >> >> >> >>>> >>><br>
>>>>> >> >> >> >>>> >>> org.scijava.module.ModuleRunner.call(ModuleRunner.java:65)<br>
>>>>> >> >> >> >>>> >>> at<br>
>>>>> >> >> >> >>>> >>><br>
>>>>> >> >> >> >>>> >>><br>
>>>>> >> >> >> >>>> >>><br>
>>>>> >> >> >> >>>> >>><br>
>>>>> >> >> >> >>>> >>><br>
>>>>> >> >> >> >>>> >>> org.scijava.thread.DefaultThreadService$2.call(DefaultThreadService.java:164)<br>
>>>>> >> >> >> >>>> >>> at<br>
>>>>> >> >> >> >>>> >>> java.util.concurrent.FutureTask.run(FutureTask.java:262)<br>
>>>>> >> >> >> >>>> >>> at<br>
>>>>> >> >> >> >>>> >>><br>
>>>>> >> >> >> >>>> >>><br>
>>>>> >> >> >> >>>> >>><br>
>>>>> >> >> >> >>>> >>><br>
>>>>> >> >> >> >>>> >>><br>
>>>>> >> >> >> >>>> >>> java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)<br>
>>>>> >> >> >> >>>> >>> at<br>
>>>>> >> >> >> >>>> >>><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<br>
>>>>> >> >> >> >>>> >>> 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>
>>>><br>
>>>><br>
</div></div></blockquote></div><br></div>