[ImageJ-devel] Save/write image with SCIFIO/BF in python script

Hadrien Mary hadrien.mary at gmail.com
Sun Jan 25 15:22:19 CST 2015


I am now using 'ij.op().crop()' which works well.

I also test fix-cell branch with my previous code (using SCIFIOConfig
and ImageRegion) which fix the save issue (both with ImgSaver and
DatasetService). However cropped image histogram is very different
from the original.

This issue appears only with my dataset (it works well with Samples >
Track for Trackmate for example).

Please try the following script with this file :
https://arwen.hadim.fr/public.php?service=files&t=0d6a774bdfaeed521156ec8a8f9ccdcf

----------------------------------------------
# @DatasetService data

from ij import IJ
from ij.plugin.frame import RoiManager

from io.scif.config import SCIFIOConfig
from io.scif.img import ImageRegion
from io.scif.img import ImgOpener
from io.scif.img import ImgSaver
from net.imagej.axis import Axes

import os

# Get current image filename
imp = IJ.getImage()
f = imp.getOriginalFileInfo()
fname = os.path.join(f.directory, f.fileName)

IJ.log('Image filename is %s' % fname)

# Iterate over all ROIs from ROI Manager
rois = RoiManager.getInstance().getRoisAsArray()
for i, roi in enumerate(rois):

    crop_id = i +1
    IJ.log("Opening crop %i / %i" % (crop_id, len(rois)))

    # Get ROI bounds
    bounds = roi.getBounds()
    x = bounds.x
    y = bounds.y
    w = bounds.width
    h = bounds.height

    # Import only cropped region of the image
    axes = [Axes.X, Axes.Y]
    ranges = ["%i-%i" % (x, x+w), "%i-%i" % (y, y+h)]
    config = SCIFIOConfig()
    config.imgOpenerSetRegion(ImageRegion(axes, ranges))

    opener = ImgOpener()
    imps = opener.openImgs(fname, config)
    imp = imps[0]

    # Get filename and basename of the current cropped image
    crop_basename = "crop%i_%s" % (crop_id, f.fileName)
    crop_fname = os.path.join(f.directory, crop_basename)
    IJ.log("Saving crop to %s" % crop_fname)

    # Create dataset
    ds = data.create(imp)

    # Save cropped image
    data.save(ds, crop_fname)

IJ.log('Done')
------------------------------------------------------------------------

--
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


On Sun, Jan 25, 2015 at 9:42 PM, Mark Hiner <hiner at wisc.edu> wrote:
> Hi Hadrien,
>
>>I tried to use another method to save cropped images using DatasetService:
>
> 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.
>
>>    saver.saveImg(crop_fname, imp)
>> at
>> io.scif.img.cell.loaders.AbstractArrayLoader.loadArray(AbstractArrayLoader.java:156)
>> java.lang.NullPointerException: java.lang.NullPointerException
>
> Yes! This was definitely a bug - thank you for finding it. I think I have a
> fix here: https://github.com/scifio/scifio/commits/fix-cell
> Would you mind giving it a try locally in your workflow?
>
> Thank you!
> - Mark
>
> On Sat, Jan 24, 2015 at 3:01 PM, Hadrien Mary <hadrien.mary at gmail.com>
> wrote:
>>
>> Quick update:
>>
>> I tried to use another method to save cropped images using DatasetService:
>>
>> ---------------------------
>> # Create dataset
>> ds = data.create(imp)
>>
>> # Save cropped image
>> data.save(ds, crop_fname)
>> -------------------------
>>
>> And the error is exactly the same as before.
>>
>> --
>> 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
>>
>>
>> On Tue, Jan 20, 2015 at 10:17 AM, Hadrien Mary <hadrien.mary at gmail.com>
>> wrote:
>> > Another thing I noticed, it's that histogram is different when
>> > cropping manually inside Fiji (select area and do "Duplicate") or when
>> > it has been cropped with the python script (SCIFIO crop).
>> >
>> > See screenshot attachment.
>> >
>> >
>> >
>> > --
>> > 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
>> >
>> >
>> > On Mon, Jan 19, 2015 at 10:29 AM, Hadrien Mary <hadrien.mary at gmail.com>
>> > wrote:
>> >> Hi again,
>> >>
>> >> The script works well for small images (OME Tiff or normal Tiff) with
>> >> the recent Fiji update. However when I run it on large movies (13GB),
>> >> I have the following error.
>> >>
>> >> ----------------------------------------------------------
>> >> -- Classpath of ClassLoader --
>> >> /home/hadim/local/Fiji.app/plugins/
>> >>
>> >> at org.scijava.Context.inject(Context.java:431)
>> >> at org.scijava.Context.inject(Context.java:363)
>> >> at
>> >> org.scijava.plugin.DefaultPluginService.createInstance(DefaultPluginService.java:237)
>> >> at
>> >> org.scijava.ui.DefaultUIService.discoverUIs(DefaultUIService.java:500)
>> >> at org.scijava.ui.DefaultUIService.uiList(DefaultUIService.java:479)
>> >> at
>> >> org.scijava.ui.DefaultUIService.getAvailableUIs(DefaultUIService.java:231)
>> >> at org.scijava.ui.DefaultUIService.onEvent(DefaultUIService.java:457)
>> >> at sun.reflect.GeneratedMethodAccessor5.invoke(Unknown Source)
>> >> at
>> >> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
>> >> at java.lang.reflect.Method.invoke(Method.java:606)
>> >> at
>> >> org.scijava.event.DefaultEventService$ProxySubscriber.onEvent(DefaultEventService.java:280)
>> >> at
>> >> org.scijava.event.DefaultEventService$ProxySubscriber.onEvent(DefaultEventService.java:254)
>> >> at
>> >> org.bushe.swing.event.ThreadSafeEventService.publish(ThreadSafeEventService.java:971)
>> >> at
>> >> org.scijava.event.DefaultEventBus.access$201(DefaultEventBus.java:56)
>> >> at org.scijava.event.DefaultEventBus$2.run(DefaultEventBus.java:223)
>> >> at
>> >> org.scijava.thread.DefaultThreadService$1.run(DefaultThreadService.java:147)
>> >> at
>> >> java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
>> >> at java.util.concurrent.FutureTask.run(FutureTask.java:262)
>> >> at
>> >> java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
>> >> at
>> >> java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
>> >> at java.lang.Thread.run(Thread.java:745)
>> >> Traceback (most recent call last):
>> >>   File
>> >> "/home/hadim/local/Fiji.app/plugins/Scripts/Plugins/Crop_Multi_Roi.py",
>> >> line 50, in <module>
>> >>     saver.saveImg(crop_fname, imp)
>> >> at
>> >> io.scif.img.cell.loaders.AbstractArrayLoader.loadArray(AbstractArrayLoader.java:156)
>> >> at io.scif.img.cell.SCIFIOCellCache.load(SCIFIOCellCache.java:144)
>> >> at
>> >> io.scif.img.cell.SCIFIOImgCells$CachedCells.get(SCIFIOImgCells.java:122)
>> >> at
>> >> io.scif.img.cell.SCIFIOImgCells$CachedCells.get(SCIFIOImgCells.java:101)
>> >> at net.imglib2.img.list.ListCursor.get(ListCursor.java:80)
>> >> at net.imglib2.img.cell.CellCursor.getCell(CellCursor.java:92)
>> >> at net.imglib2.img.cell.CellCursor.moveToNextCell(CellCursor.java:180)
>> >> at net.imglib2.img.cell.CellCursor.reset(CellCursor.java:150)
>> >> at net.imglib2.img.cell.CellCursor.<init>(CellCursor.java:86)
>> >> at
>> >> net.imglib2.img.cell.AbstractCellImg.cursor(AbstractCellImg.java:113)
>> >> at net.imglib2.img.cell.AbstractCellImg.cursor(AbstractCellImg.java:47)
>> >> at net.imglib2.img.AbstractImg.firstElement(AbstractImg.java:81)
>> >> at net.imagej.ImgPlus.firstElement(ImgPlus.java:261)
>> >> at io.scif.img.ImgSaver.populateMeta(ImgSaver.java:894)
>> >> at io.scif.img.ImgSaver.writeImg(ImgSaver.java:514)
>> >> at io.scif.img.ImgSaver.writeImg(ImgSaver.java:495)
>> >> at io.scif.img.ImgSaver.writeImg(ImgSaver.java:457)
>> >> at io.scif.img.ImgSaver.saveImg(ImgSaver.java:174)
>> >> at io.scif.img.ImgSaver.saveImg(ImgSaver.java:158)
>> >> at io.scif.img.ImgSaver.saveImg(ImgSaver.java:128)
>> >> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>> >> at
>> >> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
>> >> at
>> >> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
>> >> at java.lang.reflect.Method.invoke(Method.java:606)
>> >>
>> >> java.lang.NullPointerException: java.lang.NullPointerException
>> >> -------------------------------------------------------------------
>> >>
>> >> The associated script is below.
>> >>
>> >>
>> >> ------------------------------------------------------------------------
>> >> from ij import IJ
>> >> from ij.plugin.frame import RoiManager
>> >>
>> >> from io.scif.config import SCIFIOConfig
>> >> from io.scif.img import ImageRegion
>> >> from io.scif.img import ImgOpener
>> >> from io.scif.img import ImgSaver
>> >> from net.imagej.axis import Axes
>> >>
>> >> import os
>> >>
>> >> # Get current image filename
>> >> imp = IJ.getImage()
>> >> f = imp.getOriginalFileInfo()
>> >> fname = os.path.join(f.directory, f.fileName)
>> >>
>> >> IJ.log('Image filename is %s' % fname)
>> >>
>> >> # Iterate over all ROIs from ROI Manager
>> >> rois = RoiManager.getInstance().getRoisAsArray()
>> >> for i, roi in enumerate(rois):
>> >>
>> >>     crop_id = i +1
>> >>     IJ.log("Opening crop %i / %i" % (crop_id, len(rois)))
>> >>
>> >>     # Get ROI bounds
>> >>     bounds = roi.getBounds()
>> >>     x = bounds.x
>> >>     y = bounds.y
>> >>     w = bounds.width
>> >>     h = bounds.height
>> >>
>> >>     # Import only cropped region of the image
>> >>     axes = [Axes.X, Axes.Y]
>> >>     ranges = ["%i-%i" % (x, x+w), "%i-%i" % (y, y+h)]
>> >>     config = SCIFIOConfig()
>> >>     config.imgOpenerSetRegion(ImageRegion(axes, ranges))
>> >>
>> >>     opener = ImgOpener()
>> >>     imps = opener.openImgs(fname, config)
>> >>     imp = imps[0]
>> >>
>> >>     # Get filename and basename of the current cropped image
>> >>     crop_basename = "crop%i_%s" % (crop_id, f.fileName)
>> >>     crop_fname = os.path.join(f.directory, crop_basename)
>> >>     IJ.log("Saving crop to %s" % crop_fname)
>> >>
>> >>     # Save cropped image
>> >>     saver = ImgSaver()
>> >>     saver.saveImg(crop_fname, imp)
>> >>
>> >> IJ.log('Done')
>> >>
>> >> ----------------------------------------------------------------------------
>> >>
>> >> Does opener.openImgs() wait for the image to open ? If it does not I
>> >> guess that saver.saveImg() is called on an image that does not exist
>> >> in memory.
>> >>
>> >> Thanks
>> >>
>> >> --
>> >> 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
>> >>
>> >>
>> >> On Wed, Jan 14, 2015 at 4:35 PM, Hadrien Mary <hadrien.mary at gmail.com>
>> >> wrote:
>> >>> I confirm it works !
>> >>>
>> >>> Thanks again
>> >>>
>> >>> --
>> >>> 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
>> >>>
>> >>>
>> >>> On Wed, Jan 14, 2015 at 3:32 PM, Mark Hiner <hiner at wisc.edu> wrote:
>> >>>> Hi Hadrien,
>> >>>>
>> >>>>>Exception in thread "DrawAndDrop" java.lang.NoSuchMethodError:
>> >>>>>io.scif.ImageMetadata.setAxisLength(Lnet/imglib2/meta/AxisType;J)V
>> >>>>
>> >>>> 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.
>> >>>>
>> >>>> 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.
>> >>>>
>> >>>> [1]
>> >>>>
>> >>>> https://github.com/fiji/fiji/blob/2bc6266ff5ad5dfa155db9c0631db9baae396062/pom.xml#L608-612
>> >>>> [2]
>> >>>>
>> >>>> https://github.com/scifio/scifio-ome-xml/releases/tag/scifio-ome-xml-0.12.0
>> >>>> [3]
>> >>>>
>> >>>> https://github.com/fiji/fiji/commit/2bc6266ff5ad5dfa155db9c0631db9baae396062
>> >>>>
>> >>>> On Wed, Jan 14, 2015 at 7:05 AM, Hadrien Mary
>> >>>> <hadrien.mary at gmail.com>
>> >>>> wrote:
>> >>>>>
>> >>>>> Ok it makes sense now !
>> >>>>>
>> >>>>> So I did what you told me about cloning imagej repo, building and
>> >>>>> install it with maven inside my local Fiji.app/. I don't know if
>> >>>>> it's
>> >>>>> a bug or a missing dependency but I am now unable to open OME Tiff
>> >>>>> files (other kind of file works well) wether it is by drag and drop
>> >>>>> or
>> >>>>> with my script. The error is the following:
>> >>>>>
>> >>>>> -------------------------------------------------
>> >>>>> Exception in thread "DrawAndDrop" java.lang.NoSuchMethodError:
>> >>>>> io.scif.ImageMetadata.setAxisLength(Lnet/imglib2/meta/AxisType;J)V
>> >>>>> at
>> >>>>>
>> >>>>> io.scif.ome.formats.OMETIFFFormat$Metadata.populateImageMetadata(OMETIFFFormat.java:273)
>> >>>>> at io.scif.AbstractParser.parse(AbstractParser.java:254)
>> >>>>> at
>> >>>>> io.scif.ome.formats.OMETIFFFormat$Parser.parse(OMETIFFFormat.java:609)
>> >>>>> at
>> >>>>> io.scif.ome.formats.OMETIFFFormat$Parser.parse(OMETIFFFormat.java:552)
>> >>>>> at io.scif.AbstractParser.parse(AbstractParser.java:335)
>> >>>>> at io.scif.AbstractParser.parse(AbstractParser.java:52)
>> >>>>> at io.scif.AbstractReader.setSource(AbstractReader.java:270)
>> >>>>> at
>> >>>>>
>> >>>>> io.scif.services.DefaultInitializeService.initializeReader(DefaultInitializeService.java:90)
>> >>>>> at io.scif.img.ImgOpener.createReader(ImgOpener.java:542)
>> >>>>> at io.scif.img.ImgOpener.openImgs(ImgOpener.java:144)
>> >>>>> at io.scif.io.DatasetIOPlugin.open(DatasetIOPlugin.java:133)
>> >>>>> at io.scif.io.DatasetIOPlugin.open(DatasetIOPlugin.java:109)
>> >>>>> at io.scif.io.DatasetIOPlugin.open(DatasetIOPlugin.java:63)
>> >>>>> at
>> >>>>>
>> >>>>> net.imagej.legacy.plugin.DefaultLegacyOpener.open(DefaultLegacyOpener.java:134)
>> >>>>> at
>> >>>>>
>> >>>>> net.imagej.legacy.DefaultLegacyHooks.interceptDragAndDropFile(DefaultLegacyHooks.java:358)
>> >>>>> at ij.plugin.DragAndDrop.openFile(DragAndDrop.java)
>> >>>>> at ij.plugin.DragAndDrop.run(DragAndDrop.java:152)
>> >>>>> at java.lang.Thread.run(Thread.java:745)
>> >>>>> -----------------------------------------------
>> >>>>>
>> >>>>> I guess something in scifio has not been updated to use the new
>> >>>>> net.imagej.axis or maybe the update is not built/downloaded when I
>> >>>>> run
>> >>>>> maven on my imagej clone.
>> >>>>>
>> >>>>>
>> >>>>> --
>> >>>>> 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
>> >>>>>
>> >>>>>
>> >>>>> On Wed, Jan 14, 2015 at 12:58 PM, Mark Hiner <hiner at wisc.edu> wrote:
>> >>>>> > Hi Hadrien,
>> >>>>> >
>> >>>>> >>Sorry if it's off topic but I tried to run my script and I got a
>> >>>>> >> python
>> >>>>> >> error
>> >>>>> >
>> >>>>> > Oh no! This is totally my fault. I had to update your script for
>> >>>>> > the new
>> >>>>> > dependencies I mentioned and forgot to paste the new version in my
>> >>>>> > response
>> >>>>> > yesterday:
>> >>>>> >
>> >>>>> >>from net.imglib2.meta import Axes
>> >>>>> >
>> >>>>> > This import needs to change to:
>> >>>>> >
>> >>>>> > from net.imagej.axis import Axes
>> >>>>> >
>> >>>>> > Sorry about that!
>> >>>>> >
>> >>>>> > Best,
>> >>>>> > Mark
>> >>>>> >
>> >>>>> >
>> >>>>> > On Tue, Jan 13, 2015 at 3:59 PM, Hadrien Mary
>> >>>>> > <hadrien.mary at gmail.com>
>> >>>>> > wrote:
>> >>>>> >>
>> >>>>> >> Thank you Mark !
>> >>>>> >>
>> >>>>> >> Sorry if it's off topic but I tried to run my script and I got a
>> >>>>> >> python error probably related to type difference between python
>> >>>>> >> and
>> >>>>> >> java. It's not the first time I saw this kind of message and I'd
>> >>>>> >> like
>> >>>>> >> to know how to resolve it. Note that for python script I mainly
>> >>>>> >> use
>> >>>>> >> javadoc as documentation.
>> >>>>> >>
>> >>>>> >> The error is below coming from almost the same script as before
>> >>>>> >> in this
>> >>>>> >> thread.
>> >>>>> >>
>> >>>>> >> ********************************
>> >>>>> >> Started test_open_save.py at Tue Jan 13 22:54:36 CET 2015
>> >>>>> >> Traceback (most recent call last):
>> >>>>> >>   File
>> >>>>> >>
>> >>>>> >>
>> >>>>> >> "/home/hadim/Documents/phd/dev/scripts/imagej_scripts/test_open_save.py",
>> >>>>> >> line 17, in <module>
>> >>>>> >>     config.imgOpenerSetRegion(ImageRegion(axes, ranges))
>> >>>>> >> TypeError: io.scif.img.ImageRegion(): 1st arg can't be coerced to
>> >>>>> >> net.imagej.axis.AxisType[]
>> >>>>> >>
>> >>>>> >> at org.python.core.Py.TypeError(Py.java:235)
>> >>>>> >> at
>> >>>>> >>
>> >>>>> >>
>> >>>>> >> org.python.core.PyReflectedFunction.throwError(PyReflectedFunction.java:209)
>> >>>>> >> at
>> >>>>> >>
>> >>>>> >>
>> >>>>> >> org.python.core.PyReflectedFunction.throwBadArgError(PyReflectedFunction.java:312)
>> >>>>> >> at
>> >>>>> >>
>> >>>>> >>
>> >>>>> >> org.python.core.PyReflectedFunction.throwError(PyReflectedFunction.java:321)
>> >>>>> >> at
>> >>>>> >>
>> >>>>> >>
>> >>>>> >> org.python.core.PyReflectedConstructor.__call__(PyReflectedConstructor.java:176)
>> >>>>> >> at org.python.core.PyObject.__call__(PyObject.java:345)
>> >>>>> >> at
>> >>>>> >> org.python.core.PyMethod.instancemethod___call__(PyMethod.java:220)
>> >>>>> >> at org.python.core.PyMethod.__call__(PyMethod.java:211)
>> >>>>> >> at org.python.core.PyMethod.__call__(PyMethod.java:206)
>> >>>>> >> at org.python.core.Deriveds.dispatch__init__(Deriveds.java:19)
>> >>>>> >> at
>> >>>>> >>
>> >>>>> >>
>> >>>>> >> org.python.core.PyObjectDerived.dispatch__init__(PyObjectDerived.java:1057)
>> >>>>> >> at org.python.core.PyType.type___call__(PyType.java:1565)
>> >>>>> >> at org.python.core.PyType.__call__(PyType.java:1548)
>> >>>>> >> at org.python.core.PyObject.__call__(PyObject.java:404)
>> >>>>> >> at org.python.core.PyObject.__call__(PyObject.java:408)
>> >>>>> >> at
>> >>>>> >>
>> >>>>> >>
>> >>>>> >> org.python.pycode._pyx0.f$0(/home/hadim/Documents/phd/dev/scripts/imagej_scripts/test_open_save.py:26)
>> >>>>> >> at
>> >>>>> >>
>> >>>>> >>
>> >>>>> >> org.python.pycode._pyx0.call_function(/home/hadim/Documents/phd/dev/scripts/imagej_scripts/test_open_save.py)
>> >>>>> >> at org.python.core.PyTableCode.call(PyTableCode.java:165)
>> >>>>> >> at org.python.core.PyCode.call(PyCode.java:18)
>> >>>>> >> at org.python.core.Py.runCode(Py.java:1275)
>> >>>>> >> at
>> >>>>> >>
>> >>>>> >>
>> >>>>> >> org.scijava.plugins.scripting.jython.JythonScriptEngine.eval(JythonScriptEngine.java:76)
>> >>>>> >> at org.scijava.script.ScriptModule.run(ScriptModule.java:175)
>> >>>>> >> at org.scijava.module.ModuleRunner.run(ModuleRunner.java:167)
>> >>>>> >> at org.scijava.module.ModuleRunner.call(ModuleRunner.java:126)
>> >>>>> >> at org.scijava.module.ModuleRunner.call(ModuleRunner.java:65)
>> >>>>> >> at
>> >>>>> >>
>> >>>>> >>
>> >>>>> >> org.scijava.thread.DefaultThreadService$2.call(DefaultThreadService.java:164)
>> >>>>> >> at java.util.concurrent.FutureTask.run(FutureTask.java:262)
>> >>>>> >> at
>> >>>>> >>
>> >>>>> >>
>> >>>>> >> java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
>> >>>>> >> at
>> >>>>> >>
>> >>>>> >>
>> >>>>> >> java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
>> >>>>> >> at java.lang.Thread.run(Thread.java:745)
>> >>>>> >> ************************************
>> >>>>> >>
>> >>>>> >> --
>> >>>>> >> 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
>> >>>>> >>
>> >>>>> >>
>> >>>>> >> On Tue, Jan 13, 2015 at 10:20 PM, Mark Hiner <hiner at wisc.edu>
>> >>>>> >> wrote:
>> >>>>> >> > Hi Hadrien,
>> >>>>> >> >
>> >>>>> >> >  Unsurprisingly, cropping and writing OME-TIFFs was quite
>> >>>>> >> > broken.
>> >>>>> >> >
>> >>>>> >> >  It's working for me now, as of the latest SCIFIO[1] and
>> >>>>> >> > SCIFIO-OME-XML[2].
>> >>>>> >> > Note that these libraries have updated dependencies compared to
>> >>>>> >> > what's
>> >>>>> >> > currently on Fiji, so you can't just drop these .jars into your
>> >>>>> >> > Fiji
>> >>>>> >> > installation if you want to test locally; you need to update
>> >>>>> >> > the
>> >>>>> >> > dependencies as well. The easiest way to do this would be to
>> >>>>> >> > just
>> >>>>> >> > clone
>> >>>>> >> > Imagej.git[3] and install it into your Fiji.app directory by
>> >>>>> >> > running:
>> >>>>> >> >
>> >>>>> >> > mvn -Dimagej.app.directory=/path/to/Fiji.app/
>> >>>>> >> > -Ddelete.other.versions=true
>> >>>>> >> >
>> >>>>> >> > We'll push these changes up to Fiji this week, and I will find
>> >>>>> >> > or
>> >>>>> >> > write
>> >>>>> >> > better instructions for local testing.
>> >>>>> >> >
>> >>>>> >> > Hope this helps. Let us know if you have any
>> >>>>> >> > questions/problems.
>> >>>>> >> > Thanks
>> >>>>> >> > again for finding this issue!
>> >>>>> >> >
>> >>>>> >> > Best,
>> >>>>> >> > - Mark
>> >>>>> >> >
>> >>>>> >> > [1] https://github.com/scifio/scifio/releases/tag/scifio-0.19.0
>> >>>>> >> > [2]
>> >>>>> >> >
>> >>>>> >> >
>> >>>>> >> >
>> >>>>> >> > https://github.com/scifio/scifio-ome-xml/releases/tag/scifio-ome-xml-0.12.0
>> >>>>> >> > [3] https://github.com/imagej/imagej
>> >>>>> >> >
>> >>>>> >> > On Sat, Jan 10, 2015 at 5:13 AM, Hadrien Mary
>> >>>>> >> > <hadrien.mary at gmail.com>
>> >>>>> >> > wrote:
>> >>>>> >> >>
>> >>>>> >> >> Ok. Let me know when you want me to test your changes. I also
>> >>>>> >> >> tested
>> >>>>> >> >> fix-writing branch and I didn't notice any changes.
>> >>>>> >> >>
>> >>>>> >> >> --
>> >>>>> >> >> 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
>> >>>>> >> >>
>> >>>>> >> >>
>> >>>>> >> >> On Fri, Jan 9, 2015 at 10:14 PM, Mark Hiner <hiner at wisc.edu>
>> >>>>> >> >> wrote:
>> >>>>> >> >> > Hi Hadrien,
>> >>>>> >> >> >
>> >>>>> >> >> > I've identified at least two bugs that could be affecting
>> >>>>> >> >> > you
>> >>>>> >> >> > here.
>> >>>>> >> >> >
>> >>>>> >> >> > First of all, there was a bug in the OME-TIFF format writing
>> >>>>> >> >> > out
>> >>>>> >> >> > multi-dimensional images. That's fixed on a branch but not
>> >>>>> >> >> > uploaded
>> >>>>> >> >> > to
>> >>>>> >> >> > Fiji
>> >>>>> >> >> > yet [1].
>> >>>>> >> >> >
>> >>>>> >> >> > Second, it seems like cropping is restricting pixel reads to
>> >>>>> >> >> > the
>> >>>>> >> >> > correct
>> >>>>> >> >> > region but then doesn't change the image size.
>> >>>>> >> >> >
>> >>>>> >> >> > I'm hoping when I fix the second issue writing cropped
>> >>>>> >> >> > regions
>> >>>>> >> >> > will
>> >>>>> >> >> > be
>> >>>>> >> >> > fixed.
>> >>>>> >> >> >
>> >>>>> >> >> > Thanks for the great feedback!
>> >>>>> >> >> > - Mark
>> >>>>> >> >> >
>> >>>>> >> >> > [1]
>> >>>>> >> >> > https://github.com/scifio/scifio-ome-xml/tree/fix-writing
>> >>>>> >> >> >
>> >>>>> >> >> > On Fri, Jan 9, 2015 at 11:49 AM, Hadrien Mary
>> >>>>> >> >> > <hadrien.mary at gmail.com>
>> >>>>> >> >> > wrote:
>> >>>>> >> >> >>
>> >>>>> >> >> >> I also confirm the same behaviour when replacing original
>> >>>>> >> >> >> file by
>> >>>>> >> >> >> OME
>> >>>>> >> >> >> sample data :
>> >>>>> >> >> >>
>> >>>>> >> >> >>
>> >>>>> >> >> >>
>> >>>>> >> >> >>
>> >>>>> >> >> >> http://www.openmicroscopy.org/Schemas/Samples/2013-06/bioformats-artificial/multi-channel-4D-series.ome.tif.zip.
>> >>>>> >> >> >>
>> >>>>> >> >> >> --
>> >>>>> >> >> >> 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
>> >>>>> >> >> >>
>> >>>>> >> >> >>
>> >>>>> >> >> >> On Fri, Jan 9, 2015 at 6:46 PM, Hadrien Mary
>> >>>>> >> >> >> <hadrien.mary at gmail.com>
>> >>>>> >> >> >> wrote:
>> >>>>> >> >> >> > After some investigations I think there is a bug with
>> >>>>> >> >> >> > ImgSaver.
>> >>>>> >> >> >> > In
>> >>>>> >> >> >> > the
>> >>>>> >> >> >> > following script, X, Y crop is fine but axes informations
>> >>>>> >> >> >> > (T
>> >>>>> >> >> >> > and
>> >>>>> >> >> >> > Z)
>> >>>>> >> >> >> > are lost and all frames appears on the same axes. Now if
>> >>>>> >> >> >> > I
>> >>>>> >> >> >> > replace
>> >>>>> >> >> >> > "target = "/home/hadim/cropped.tif" by "target =
>> >>>>> >> >> >> > "/home/hadim/cropped.ome.tif" on line 9. X, Y crop fails,
>> >>>>> >> >> >> > cropped
>> >>>>> >> >> >> > image has the same dimensions than original however axes
>> >>>>> >> >> >> > informations
>> >>>>> >> >> >> > (T and Z) are ok. Note that in cropped.ome.tif, pixel
>> >>>>> >> >> >> > values
>> >>>>> >> >> >> > are
>> >>>>> >> >> >> > totally incoherent which is not the case in cropped.tif.
>> >>>>> >> >> >> >
>> >>>>> >> >> >> > Files can be found here :
>> >>>>> >> >> >> >
>> >>>>> >> >> >> >
>> >>>>> >> >> >> >
>> >>>>> >> >> >> >
>> >>>>> >> >> >> >
>> >>>>> >> >> >> > https://arwen.hadim.fr/public.php?service=files&t=71aa17336dcccb3437d9a3dff789d2c0
>> >>>>> >> >> >> >
>> >>>>> >> >> >> > Archive contains cropped.tif, cropped.ome.tif and
>> >>>>> >> >> >> > original.ome.tif.
>> >>>>> >> >> >> >
>> >>>>> >> >> >> > The script:
>> >>>>> >> >> >> >
>> >>>>> >> >> >> > ---------------------------------------------------
>> >>>>> >> >> >> > from io.scif import SCIFIO
>> >>>>> >> >> >> > from io.scif.config import SCIFIOConfig
>> >>>>> >> >> >> > from io.scif.img import ImageRegion
>> >>>>> >> >> >> > from io.scif.img import ImgOpener
>> >>>>> >> >> >> > from io.scif.img import ImgSaver
>> >>>>> >> >> >> > from net.imglib2.meta import Axes
>> >>>>> >> >> >> >
>> >>>>> >> >> >> > fname = "/home/hadim/original.ome.tif"
>> >>>>> >> >> >> > target = "/home/hadim/cropped.tif"
>> >>>>> >> >> >> >
>> >>>>> >> >> >> > axes = [Axes.X, Axes.Y]
>> >>>>> >> >> >> > ranges = ["%i-%i" % (0, 15), "%i-%i" % (0, 25)]
>> >>>>> >> >> >> > config = SCIFIOConfig()
>> >>>>> >> >> >> > config.imgOpenerSetRegion(ImageRegion(axes, ranges))
>> >>>>> >> >> >> >
>> >>>>> >> >> >> > opener = ImgOpener()
>> >>>>> >> >> >> > imps = opener.openImgs(fname, config)
>> >>>>> >> >> >> > imp = imps[0]
>> >>>>> >> >> >> >
>> >>>>> >> >> >> > saver = ImgSaver()
>> >>>>> >> >> >> > saver.saveImg(target, imp)
>> >>>>> >> >> >> >
>> >>>>> >> >> >> > print('Done')
>> >>>>> >> >> >> > ---------------------------------------------------
>> >>>>> >> >> >> >
>> >>>>> >> >> >> >
>> >>>>> >> >> >> > --
>> >>>>> >> >> >> > Hadrien Mary
>> >>>>> >> >> >> >
>> >>>>> >> >> >> >
>> >>>>> >> >> >> > On Fri, Jan 9, 2015 at 12:25 AM, Hadrien Mary
>> >>>>> >> >> >> > <hadrien.mary at gmail.com>
>> >>>>> >> >> >> > wrote:
>> >>>>> >> >> >> >> Thanks for the tip (reminder to me: always look for
>> >>>>> >> >> >> >> example in
>> >>>>> >> >> >> >> tests!).
>> >>>>> >> >> >> >>
>> >>>>> >> >> >> >> Unfortunately crop does not work... I will try to do
>> >>>>> >> >> >> >> more
>> >>>>> >> >> >> >> tests
>> >>>>> >> >> >> >> tomorrow or wait for you or someone else to have a look.
>> >>>>> >> >> >> >>
>> >>>>> >> >> >> >> Updated code:
>> >>>>> >> >> >> >>
>> >>>>> >> >> >> >> from ij import IJ
>> >>>>> >> >> >> >> from ij import ImagePlus
>> >>>>> >> >> >> >>
>> >>>>> >> >> >> >> from io.scif import SCIFIO
>> >>>>> >> >> >> >> from io.scif.config import SCIFIOConfig
>> >>>>> >> >> >> >> from io.scif.img import ImageRegion
>> >>>>> >> >> >> >> from io.scif.img import ImgOpener
>> >>>>> >> >> >> >> from io.scif.img import ImgSaver
>> >>>>> >> >> >> >> from net.imglib2.meta import Axes
>> >>>>> >> >> >> >>
>> >>>>> >> >> >> >> fname = "/home/hadim/original.ome.tif"
>> >>>>> >> >> >> >> target = "/home/hadim/cropped.ome.tif"
>> >>>>> >> >> >> >>
>> >>>>> >> >> >> >> axes = [Axes.X, Axes.Y]
>> >>>>> >> >> >> >> ranges = ["%i-%i" % (2, 15), "%i-%i" % (2, 25)]
>> >>>>> >> >> >> >> config = SCIFIOConfig()
>> >>>>> >> >> >> >> config.imgOpenerSetRegion(ImageRegion(axes, ranges))
>> >>>>> >> >> >> >>
>> >>>>> >> >> >> >> opener = ImgOpener()
>> >>>>> >> >> >> >> imps = opener.openImgs(fname, config)
>> >>>>> >> >> >> >> imp = imps[0]
>> >>>>> >> >> >> >>
>> >>>>> >> >> >> >> saver = ImgSaver()
>> >>>>> >> >> >> >> saver.saveImg(target, imp)
>> >>>>> >> >> >> >>
>> >>>>> >> >> >> >> print('Done')
>> >>>>> >> >> >> >>
>> >>>>> >> >> >> >> --
>> >>>>> >> >> >> >> Hadrien Mary
>> >>>>> >> >> >> >>
>> >>>>> >> >> >> >>
>> >>>>> >> >> >> >> On Fri, Jan 9, 2015 at 12:09 AM, Curtis Rueden
>> >>>>> >> >> >> >> <ctrueden at wisc.edu>
>> >>>>> >> >> >> >> wrote:
>> >>>>> >> >> >> >>> Hi Hadrien,
>> >>>>> >> >> >> >>>
>> >>>>> >> >> >> >>>> I would like to be able to crop a region in X and Y
>> >>>>> >> >> >> >>>> while
>> >>>>> >> >> >> >>>> keeping any other dimensions which could exist (C, Z,
>> >>>>> >> >> >> >>>> T).
>> >>>>> >> >> >> >>>
>> >>>>> >> >> >> >>> Here's some Java:
>> >>>>> >> >> >> >>>
>> >>>>> >> >> >> >>>     int minX = 128, maxX = 255, minY = 128, minY = 255;
>> >>>>> >> >> >> >>>     AxisType[] axes = { Axes.X, Axes.Y };
>> >>>>> >> >> >> >>>     String[] ranges = { minX + "-" + maxX, minY + "-" +
>> >>>>> >> >> >> >>> maxY
>> >>>>> >> >> >> >>> };
>> >>>>> >> >> >> >>>     config.imgOpenerSetRegion(new ImageRegion(axes,
>> >>>>> >> >> >> >>> ranges));
>> >>>>> >> >> >> >>>
>> >>>>> >> >> >> >>> Adapted from here:
>> >>>>> >> >> >> >>>
>> >>>>> >> >> >> >>>
>> >>>>> >> >> >> >>>
>> >>>>> >> >> >> >>>
>> >>>>> >> >> >> >>>
>> >>>>> >> >> >> >>> https://github.com/scifio/scifio/blob/scifio-0.18.0/src/test/java/io/scif/img/utests/ImgOpenerTest.java#L189-L191
>> >>>>> >> >> >> >>>
>> >>>>> >> >> >> >>> And untested.
>> >>>>> >> >> >> >>>
>> >>>>> >> >> >> >>> HTH,
>> >>>>> >> >> >> >>> Curtis
>> >>>>> >> >> >> >>>
>> >>>>> >> >> >> >>> On Thu, Jan 8, 2015 at 4:47 PM, Hadrien Mary
>> >>>>> >> >> >> >>> <hadrien.mary at gmail.com>
>> >>>>> >> >> >> >>> wrote:
>> >>>>> >> >> >> >>>>
>> >>>>> >> >> >> >>>> After some investigations, I'm pretty sure I don't
>> >>>>> >> >> >> >>>> instanciate
>> >>>>> >> >> >> >>>> ImageRegion correctly. Doc and source code didn't help
>> >>>>> >> >> >> >>>> me...
>> >>>>> >> >> >> >>>> I
>> >>>>> >> >> >> >>>> would
>> >>>>> >> >> >> >>>> like to be able to crop a region in X and Y while
>> >>>>> >> >> >> >>>> keeping
>> >>>>> >> >> >> >>>> any
>> >>>>> >> >> >> >>>> other
>> >>>>> >> >> >> >>>> dimensions which could exist (C, Z, T).
>> >>>>> >> >> >> >>>>
>> >>>>> >> >> >> >>>> --
>> >>>>> >> >> >> >>>> Hadrien Mary
>> >>>>> >> >> >> >>>>
>> >>>>> >> >> >> >>>>
>> >>>>> >> >> >> >>>>
>> >>>>> >> >> >> >>>> On Thu, Jan 8, 2015 at 10:22 PM, Hadrien Mary
>> >>>>> >> >> >> >>>> <hadrien.mary at gmail.com>
>> >>>>> >> >> >> >>>> wrote:
>> >>>>> >> >> >> >>>> > Thank you Curtis for the answer.
>> >>>>> >> >> >> >>>> >
>> >>>>> >> >> >> >>>> > I tried to apply what you told me and the code now
>> >>>>> >> >> >> >>>> > works
>> >>>>> >> >> >> >>>> > without
>> >>>>> >> >> >> >>>> > error. However the saved cropped image is not
>> >>>>> >> >> >> >>>> > cropped
>> >>>>> >> >> >> >>>> > (same
>> >>>>> >> >> >> >>>> > size
>> >>>>> >> >> >> >>>> > as
>> >>>>> >> >> >> >>>> > original) and pixel values are modified).
>> >>>>> >> >> >> >>>> >
>> >>>>> >> >> >> >>>> > Script:
>> >>>>> >> >> >> >>>> >
>> >>>>> >> >> >> >>>> > from io.scif.config import SCIFIOConfig
>> >>>>> >> >> >> >>>> > from io.scif.img import ImageRegion
>> >>>>> >> >> >> >>>> > from io.scif.img import ImgOpener
>> >>>>> >> >> >> >>>> > from io.scif.img import ImgSaver
>> >>>>> >> >> >> >>>> >
>> >>>>> >> >> >> >>>> > fname = "/home/hadim/original.ome.tif"
>> >>>>> >> >> >> >>>> > target = "/home/hadim/cropped.ome.tif"
>> >>>>> >> >> >> >>>> >
>> >>>>> >> >> >> >>>> > config = SCIFIOConfig()
>> >>>>> >> >> >> >>>> > region = ImageRegion(dict(x=2, y=2, width=10,
>> >>>>> >> >> >> >>>> > height=10))
>> >>>>> >> >> >> >>>> > config.imgOpenerSetRegion(region)
>> >>>>> >> >> >> >>>> >
>> >>>>> >> >> >> >>>> > opener = ImgOpener()
>> >>>>> >> >> >> >>>> > imps = opener.openImgs(fname, config)
>> >>>>> >> >> >> >>>> > imp = imps[0]
>> >>>>> >> >> >> >>>> >
>> >>>>> >> >> >> >>>> > print(imps)
>> >>>>> >> >> >> >>>> >
>> >>>>> >> >> >> >>>> > saver = ImgSaver()
>> >>>>> >> >> >> >>>> > saver.saveImg(target, imp)
>> >>>>> >> >> >> >>>> >
>> >>>>> >> >> >> >>>> > Thanks again for your time. Don't be sorry if you
>> >>>>> >> >> >> >>>> > don't
>> >>>>> >> >> >> >>>> > have
>> >>>>> >> >> >> >>>> > time
>> >>>>> >> >> >> >>>> > to
>> >>>>> >> >> >> >>>> > write an example.
>> >>>>> >> >> >> >>>> >
>> >>>>> >> >> >> >>>> > I will be happy to provide some python/scifio
>> >>>>> >> >> >> >>>> > examples
>> >>>>> >> >> >> >>>> > scripts.
>> >>>>> >> >> >> >>>> >
>> >>>>> >> >> >> >>>> >
>> >>>>> >> >> >> >>>> > --
>> >>>>> >> >> >> >>>> > 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
>> >>>>> >> >> >> >>>> >
>> >>>>> >> >> >> >>>> >
>> >>>>> >> >> >> >>>> > On Thu, Jan 8, 2015 at 9:56 PM, Curtis Rueden
>> >>>>> >> >> >> >>>> > <ctrueden at wisc.edu>
>> >>>>> >> >> >> >>>> > wrote:
>> >>>>> >> >> >> >>>> >> Hi Hadrien,
>> >>>>> >> >> >> >>>> >>
>> >>>>> >> >> >> >>>> >>> I tried to use SCIFIO to write cropped image on
>> >>>>> >> >> >> >>>> >>> disk but
>> >>>>> >> >> >> >>>> >>> it
>> >>>>> >> >> >> >>>> >>> doesn
>> >>>>> >> >> >> >>>> >>> not
>> >>>>> >> >> >> >>>> >>> work.
>> >>>>> >> >> >> >>>> >>
>> >>>>> >> >> >> >>>> >> The error you see is because SCIFIO operates on
>> >>>>> >> >> >> >>>> >> ImgLib2
>> >>>>> >> >> >> >>>> >> data
>> >>>>> >> >> >> >>>> >> structures, not
>> >>>>> >> >> >> >>>> >> ImagePlus objects.
>> >>>>> >> >> >> >>>> >>
>> >>>>> >> >> >> >>>> >>> Is there is any “easy” alternative to BF
>> >>>>> >> >> >> >>>> >>> setCropRegion
>> >>>>> >> >> >> >>>> >>> function
>> >>>>> >> >> >> >>>> >>> in
>> >>>>> >> >> >> >>>> >>> SCIFIO ?
>> >>>>> >> >> >> >>>> >>
>> >>>>> >> >> >> >>>> >> Yes: you create a SCIFIOConfig, calling
>> >>>>> >> >> >> >>>> >> imgOpenerSetRegion
>> >>>>> >> >> >> >>>> >> [1]
>> >>>>> >> >> >> >>>> >> on
>> >>>>> >> >> >> >>>> >> it,
>> >>>>> >> >> >> >>>> >> then
>> >>>>> >> >> >> >>>> >> pass it as an argument to the ImgOpener. You'll get
>> >>>>> >> >> >> >>>> >> back
>> >>>>> >> >> >> >>>> >> an
>> >>>>> >> >> >> >>>> >> ImgLib2
>> >>>>> >> >> >> >>>> >> data
>> >>>>> >> >> >> >>>> >> object which can then be fed to the SCIFIO
>> >>>>> >> >> >> >>>> >> ImgSaver.
>> >>>>> >> >> >> >>>> >>
>> >>>>> >> >> >> >>>> >> I'm sorry that I don't have time to whip up an
>> >>>>> >> >> >> >>>> >> example
>> >>>>> >> >> >> >>>> >> for
>> >>>>> >> >> >> >>>> >> you
>> >>>>> >> >> >> >>>> >> right
>> >>>>> >> >> >> >>>> >> now. It
>> >>>>> >> >> >> >>>> >> would be great to add more SCIFIO tutorials [2]
>> >>>>> >> >> >> >>>> >> that use
>> >>>>> >> >> >> >>>> >> the
>> >>>>> >> >> >> >>>> >> ImgOpener
>> >>>>> >> >> >> >>>> >> and
>> >>>>> >> >> >> >>>> >> ImgSaver, since they are much higher level APIs
>> >>>>> >> >> >> >>>> >> akin to
>> >>>>> >> >> >> >>>> >> the
>> >>>>> >> >> >> >>>> >> Bio-Formats
>> >>>>> >> >> >> >>>> >> "BF"
>> >>>>> >> >> >> >>>> >> functionality... please feel welcome to contribute
>> >>>>> >> >> >> >>>> >> some!
>> >>>>> >> >> >> >>>> >>
>> >>>>> >> >> >> >>>> >> Regards,
>> >>>>> >> >> >> >>>> >> Curtis
>> >>>>> >> >> >> >>>> >>
>> >>>>> >> >> >> >>>> >> [1]
>> >>>>> >> >> >> >>>> >>
>> >>>>> >> >> >> >>>> >>
>> >>>>> >> >> >> >>>> >>
>> >>>>> >> >> >> >>>> >>
>> >>>>> >> >> >> >>>> >>
>> >>>>> >> >> >> >>>> >>
>> >>>>> >> >> >> >>>> >> http://javadoc.imagej.net/SCIFIO/io/scif/config/SCIFIOConfig.html#imgOpenerSetRegion(io.scif.img.ImageRegion)
>> >>>>> >> >> >> >>>> >> [2] https://github.com/scifio/scifio-tutorials
>> >>>>> >> >> >> >>>> >>
>> >>>>> >> >> >> >>>> >> On Thu, Jan 8, 2015 at 2:18 PM, Hadrien Mary
>> >>>>> >> >> >> >>>> >> <hadrien.mary at gmail.com>
>> >>>>> >> >> >> >>>> >> wrote:
>> >>>>> >> >> >> >>>> >>>
>> >>>>> >> >> >> >>>> >>> Hi,
>> >>>>> >> >> >> >>>> >>>
>> >>>>> >> >> >> >>>> >>> I am writing a python macro which iterate over all
>> >>>>> >> >> >> >>>> >>> rois
>> >>>>> >> >> >> >>>> >>> in
>> >>>>> >> >> >> >>>> >>> ROI
>> >>>>> >> >> >> >>>> >>> Manager
>> >>>>> >> >> >> >>>> >>> and then use setCropRegion function from bioformat
>> >>>>> >> >> >> >>>> >>> plugin
>> >>>>> >> >> >> >>>> >>> to
>> >>>>> >> >> >> >>>> >>> open
>> >>>>> >> >> >> >>>> >>> a
>> >>>>> >> >> >> >>>> >>> cropped region of an image.
>> >>>>> >> >> >> >>>> >>>
>> >>>>> >> >> >> >>>> >>> I tried to use SCIFIO to write cropped image on
>> >>>>> >> >> >> >>>> >>> disk but
>> >>>>> >> >> >> >>>> >>> it
>> >>>>> >> >> >> >>>> >>> doesn
>> >>>>> >> >> >> >>>> >>> not
>> >>>>> >> >> >> >>>> >>> work.
>> >>>>> >> >> >> >>>> >>>
>> >>>>> >> >> >> >>>> >>> (I am using an updated version of Fiji.)
>> >>>>> >> >> >> >>>> >>>
>> >>>>> >> >> >> >>>> >>> Here is my script:
>> >>>>> >> >> >> >>>> >>>
>> >>>>> >> >> >> >>>> >>> from ij.plugin.frame import RoiManager
>> >>>>> >> >> >> >>>> >>> from ij import IJ
>> >>>>> >> >> >> >>>> >>> from io.scif.img import ImgSaver
>> >>>>> >> >> >> >>>> >>>
>> >>>>> >> >> >> >>>> >>> from loci.plugins import BF
>> >>>>> >> >> >> >>>> >>> from loci.plugins.in import ImporterOptions
>> >>>>> >> >> >> >>>> >>> from loci.common import Region
>> >>>>> >> >> >> >>>> >>>
>> >>>>> >> >> >> >>>> >>> import os
>> >>>>> >> >> >> >>>> >>>
>> >>>>> >> >> >> >>>> >>> # Get current image filename
>> >>>>> >> >> >> >>>> >>> imp = IJ.getImage()
>> >>>>> >> >> >> >>>> >>> f = imp.getOriginalFileInfo()
>> >>>>> >> >> >> >>>> >>> fname = os.path.join(f.directory, f.fileName)
>> >>>>> >> >> >> >>>> >>>
>> >>>>> >> >> >> >>>> >>> IJ.log('Image filename is %s' % fname)
>> >>>>> >> >> >> >>>> >>>
>> >>>>> >> >> >> >>>> >>> # Iterate over all ROIs from ROI Manager
>> >>>>> >> >> >> >>>> >>> rois = RoiManager.getInstance().getRoisAsArray()
>> >>>>> >> >> >> >>>> >>> for i, roi in enumerate(rois):
>> >>>>> >> >> >> >>>> >>>
>> >>>>> >> >> >> >>>> >>>     crop_id = i +1
>> >>>>> >> >> >> >>>> >>>     IJ.log("Opening crop %i / %i" % (crop_id,
>> >>>>> >> >> >> >>>> >>> len(rois)))
>> >>>>> >> >> >> >>>> >>>
>> >>>>> >> >> >> >>>> >>>     bounds = roi.getBounds()
>> >>>>> >> >> >> >>>> >>>
>> >>>>> >> >> >> >>>> >>>     x = bounds.x
>> >>>>> >> >> >> >>>> >>>     y = bounds.y
>> >>>>> >> >> >> >>>> >>>     w = bounds.width
>> >>>>> >> >> >> >>>> >>>     h = bounds.height
>> >>>>> >> >> >> >>>> >>>
>> >>>>> >> >> >> >>>> >>>     # Import only cropped region of the image
>> >>>>> >> >> >> >>>> >>>     options = ImporterOptions()
>> >>>>> >> >> >> >>>> >>>     options.setCrop(True)
>> >>>>> >> >> >> >>>> >>>     options.setCropRegion(0, Region(x, y, w, h))
>> >>>>> >> >> >> >>>> >>>     options.setId(fname)
>> >>>>> >> >> >> >>>> >>>     imps = BF.openImagePlus(options)
>> >>>>> >> >> >> >>>> >>>
>> >>>>> >> >> >> >>>> >>>     imp = imps[0]
>> >>>>> >> >> >> >>>> >>>     imp.show()
>> >>>>> >> >> >> >>>> >>>
>> >>>>> >> >> >> >>>> >>>     crop_basename = "crop%i_%s" % (crop_id,
>> >>>>> >> >> >> >>>> >>> f.fileName)
>> >>>>> >> >> >> >>>> >>>     crop_fname = os.path.join(f.directory,
>> >>>>> >> >> >> >>>> >>> crop_basename)
>> >>>>> >> >> >> >>>> >>>     imp.setTitle(crop_basename)
>> >>>>> >> >> >> >>>> >>>
>> >>>>> >> >> >> >>>> >>>     # Save image
>> >>>>> >> >> >> >>>> >>>     IJ.log("Saving crop to %s" % crop_fname)
>> >>>>> >> >> >> >>>> >>>     saver = ImgSaver()
>> >>>>> >> >> >> >>>> >>>     saver.saveImg(crop_basename, imp)
>> >>>>> >> >> >> >>>> >>>
>> >>>>> >> >> >> >>>> >>> IJ.log('Done')
>> >>>>> >> >> >> >>>> >>>
>> >>>>> >> >> >> >>>> >>> It fails with this error:
>> >>>>> >> >> >> >>>> >>>
>> >>>>> >> >> >> >>>> >>> Traceback (most recent call last):
>> >>>>> >> >> >> >>>> >>>   File
>> >>>>> >> >> >> >>>> >>>
>> >>>>> >> >> >> >>>> >>> "/home/hadim/local/Fiji.app/plugins/Crop_Multi_Roi.py",
>> >>>>> >> >> >> >>>> >>> line
>> >>>>> >> >> >> >>>> >>> 49, in <module>
>> >>>>> >> >> >> >>>> >>>     saver.saveImg(crop_basename, imp)
>> >>>>> >> >> >> >>>> >>> TypeError: saveImg(): 1st arg can't be coerced to
>> >>>>> >> >> >> >>>> >>> io.scif.Writer,
>> >>>>> >> >> >> >>>> >>> String
>> >>>>> >> >> >> >>>> >>>
>> >>>>> >> >> >> >>>> >>> at org.python.core.Py.TypeError(Py.java:235)
>> >>>>> >> >> >> >>>> >>> at
>> >>>>> >> >> >> >>>> >>>
>> >>>>> >> >> >> >>>> >>>
>> >>>>> >> >> >> >>>> >>>
>> >>>>> >> >> >> >>>> >>>
>> >>>>> >> >> >> >>>> >>>
>> >>>>> >> >> >> >>>> >>>
>> >>>>> >> >> >> >>>> >>> org.python.core.PyReflectedFunction.throwError(PyReflectedFunction.java:209)
>> >>>>> >> >> >> >>>> >>> at
>> >>>>> >> >> >> >>>> >>>
>> >>>>> >> >> >> >>>> >>>
>> >>>>> >> >> >> >>>> >>>
>> >>>>> >> >> >> >>>> >>>
>> >>>>> >> >> >> >>>> >>>
>> >>>>> >> >> >> >>>> >>>
>> >>>>> >> >> >> >>>> >>> org.python.core.PyReflectedFunction.throwBadArgError(PyReflectedFunction.java:312)
>> >>>>> >> >> >> >>>> >>> at
>> >>>>> >> >> >> >>>> >>>
>> >>>>> >> >> >> >>>> >>>
>> >>>>> >> >> >> >>>> >>>
>> >>>>> >> >> >> >>>> >>>
>> >>>>> >> >> >> >>>> >>>
>> >>>>> >> >> >> >>>> >>>
>> >>>>> >> >> >> >>>> >>> org.python.core.PyReflectedFunction.throwError(PyReflectedFunction.java:321)
>> >>>>> >> >> >> >>>> >>> at
>> >>>>> >> >> >> >>>> >>>
>> >>>>> >> >> >> >>>> >>>
>> >>>>> >> >> >> >>>> >>>
>> >>>>> >> >> >> >>>> >>>
>> >>>>> >> >> >> >>>> >>>
>> >>>>> >> >> >> >>>> >>>
>> >>>>> >> >> >> >>>> >>> org.python.core.PyReflectedFunction.__call__(PyReflectedFunction.java:167)
>> >>>>> >> >> >> >>>> >>> at
>> >>>>> >> >> >> >>>> >>>
>> >>>>> >> >> >> >>>> >>>
>> >>>>> >> >> >> >>>> >>>
>> >>>>> >> >> >> >>>> >>>
>> >>>>> >> >> >> >>>> >>>
>> >>>>> >> >> >> >>>> >>>
>> >>>>> >> >> >> >>>> >>> org.python.core.PyReflectedFunction.__call__(PyReflectedFunction.java:204)
>> >>>>> >> >> >> >>>> >>> at
>> >>>>> >> >> >> >>>> >>> org.python.core.PyObject.__call__(PyObject.java:422)
>> >>>>> >> >> >> >>>> >>> at
>> >>>>> >> >> >> >>>> >>> org.python.core.PyObject.__call__(PyObject.java:426)
>> >>>>> >> >> >> >>>> >>> at
>> >>>>> >> >> >> >>>> >>> org.python.core.PyMethod.__call__(PyMethod.java:139)
>> >>>>> >> >> >> >>>> >>> at
>> >>>>> >> >> >> >>>> >>>
>> >>>>> >> >> >> >>>> >>>
>> >>>>> >> >> >> >>>> >>>
>> >>>>> >> >> >> >>>> >>>
>> >>>>> >> >> >> >>>> >>>
>> >>>>> >> >> >> >>>> >>>
>> >>>>> >> >> >> >>>> >>> org.python.pycode._pyx7.f$0(/home/hadim/local/Fiji.app/plugins/Crop_Multi_Roi.py:51)
>> >>>>> >> >> >> >>>> >>> at
>> >>>>> >> >> >> >>>> >>>
>> >>>>> >> >> >> >>>> >>>
>> >>>>> >> >> >> >>>> >>>
>> >>>>> >> >> >> >>>> >>>
>> >>>>> >> >> >> >>>> >>>
>> >>>>> >> >> >> >>>> >>>
>> >>>>> >> >> >> >>>> >>> org.python.pycode._pyx7.call_function(/home/hadim/local/Fiji.app/plugins/Crop_Multi_Roi.py)
>> >>>>> >> >> >> >>>> >>> at
>> >>>>> >> >> >> >>>> >>>
>> >>>>> >> >> >> >>>> >>> org.python.core.PyTableCode.call(PyTableCode.java:165)
>> >>>>> >> >> >> >>>> >>> at org.python.core.PyCode.call(PyCode.java:18)
>> >>>>> >> >> >> >>>> >>> at org.python.core.Py.runCode(Py.java:1275)
>> >>>>> >> >> >> >>>> >>> at
>> >>>>> >> >> >> >>>> >>>
>> >>>>> >> >> >> >>>> >>>
>> >>>>> >> >> >> >>>> >>>
>> >>>>> >> >> >> >>>> >>>
>> >>>>> >> >> >> >>>> >>>
>> >>>>> >> >> >> >>>> >>>
>> >>>>> >> >> >> >>>> >>> org.scijava.plugins.scripting.jython.JythonScriptEngine.eval(JythonScriptEngine.java:76)
>> >>>>> >> >> >> >>>> >>> at
>> >>>>> >> >> >> >>>> >>>
>> >>>>> >> >> >> >>>> >>>
>> >>>>> >> >> >> >>>> >>> org.scijava.script.ScriptModule.run(ScriptModule.java:175)
>> >>>>> >> >> >> >>>> >>> at
>> >>>>> >> >> >> >>>> >>>
>> >>>>> >> >> >> >>>> >>>
>> >>>>> >> >> >> >>>> >>> org.scijava.module.ModuleRunner.run(ModuleRunner.java:167)
>> >>>>> >> >> >> >>>> >>> at
>> >>>>> >> >> >> >>>> >>>
>> >>>>> >> >> >> >>>> >>>
>> >>>>> >> >> >> >>>> >>> org.scijava.module.ModuleRunner.call(ModuleRunner.java:126)
>> >>>>> >> >> >> >>>> >>> at
>> >>>>> >> >> >> >>>> >>>
>> >>>>> >> >> >> >>>> >>>
>> >>>>> >> >> >> >>>> >>> org.scijava.module.ModuleRunner.call(ModuleRunner.java:65)
>> >>>>> >> >> >> >>>> >>> at
>> >>>>> >> >> >> >>>> >>>
>> >>>>> >> >> >> >>>> >>>
>> >>>>> >> >> >> >>>> >>>
>> >>>>> >> >> >> >>>> >>>
>> >>>>> >> >> >> >>>> >>>
>> >>>>> >> >> >> >>>> >>>
>> >>>>> >> >> >> >>>> >>> org.scijava.thread.DefaultThreadService$2.call(DefaultThreadService.java:164)
>> >>>>> >> >> >> >>>> >>> at
>> >>>>> >> >> >> >>>> >>>
>> >>>>> >> >> >> >>>> >>> java.util.concurrent.FutureTask.run(FutureTask.java:262)
>> >>>>> >> >> >> >>>> >>> at
>> >>>>> >> >> >> >>>> >>>
>> >>>>> >> >> >> >>>> >>>
>> >>>>> >> >> >> >>>> >>>
>> >>>>> >> >> >> >>>> >>>
>> >>>>> >> >> >> >>>> >>>
>> >>>>> >> >> >> >>>> >>>
>> >>>>> >> >> >> >>>> >>> java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
>> >>>>> >> >> >> >>>> >>> at
>> >>>>> >> >> >> >>>> >>>
>> >>>>> >> >> >> >>>> >>>
>> >>>>> >> >> >> >>>> >>>
>> >>>>> >> >> >> >>>> >>>
>> >>>>> >> >> >> >>>> >>>
>> >>>>> >> >> >> >>>> >>>
>> >>>>> >> >> >> >>>> >>> java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
>> >>>>> >> >> >> >>>> >>> at java.lang.Thread.run(Thread.java:745)
>> >>>>> >> >> >> >>>> >>>
>> >>>>> >> >> >> >>>> >>> Three questions:
>> >>>>> >> >> >> >>>> >>>
>> >>>>> >> >> >> >>>> >>> how can I write cropped image (I need to write
>> >>>>> >> >> >> >>>> >>> them as
>> >>>>> >> >> >> >>>> >>> OME
>> >>>>> >> >> >> >>>> >>> Tiff
>> >>>>> >> >> >> >>>> >>> so I
>> >>>>> >> >> >> >>>> >>> need BF or SCIFIO).
>> >>>>> >> >> >> >>>> >>> Is there is any “easy” alternative to BF
>> >>>>> >> >> >> >>>> >>> setCropRegion
>> >>>>> >> >> >> >>>> >>> function
>> >>>>> >> >> >> >>>> >>> in
>> >>>>> >> >> >> >>>> >>> SCIFIO
>> >>>>> >> >> >> >>>> >>> ?
>> >>>>> >> >> >> >>>> >>> I am currently using
>> >>>>> >> >> >> >>>> >>> RoiManager.getInstance().getRoisAsArray()
>> >>>>> >> >> >> >>>> >>> to
>> >>>>> >> >> >> >>>> >>> retrieve all rois. How can I directly get a
>> >>>>> >> >> >> >>>> >>> ROIManager
>> >>>>> >> >> >> >>>> >>> instance
>> >>>>> >> >> >> >>>> >>> from
>> >>>>> >> >> >> >>>> >>> RoiSet.zip file ?
>> >>>>> >> >> >> >>>> >>>
>> >>>>> >> >> >> >>>> >>> Any help would be very appreciated.
>> >>>>> >> >> >> >>>> >>>
>> >>>>> >> >> >> >>>> >>> Thanks !
>> >>>>> >> >> >> >>>> >>>
>> >>>>> >> >> >> >>>> >>> —
>> >>>>> >> >> >> >>>> >>> Hadrien Mary
>> >>>>> >> >> >> >>>> >>>
>> >>>>> >> >> >> >>>> >>> _______________________________________________
>> >>>>> >> >> >> >>>> >>> ImageJ-devel mailing list
>> >>>>> >> >> >> >>>> >>> ImageJ-devel at imagej.net
>> >>>>> >> >> >> >>>> >>> http://imagej.net/mailman/listinfo/imagej-devel
>> >>>>> >> >> >> >>>> >>
>> >>>>> >> >> >> >>>> >>
>> >>>>> >> >> >> >>>
>> >>>>> >> >> >> >>>
>> >>>>> >> >> >>
>> >>>>> >> >> >> _______________________________________________
>> >>>>> >> >> >> ImageJ-devel mailing list
>> >>>>> >> >> >> ImageJ-devel at imagej.net
>> >>>>> >> >> >> http://imagej.net/mailman/listinfo/imagej-devel
>> >>>>> >> >> >
>> >>>>> >> >> >
>> >>>>> >> >
>> >>>>> >> >
>> >>>>> >
>> >>>>> >
>> >>>>
>> >>>>
>
>



More information about the ImageJ-devel mailing list