Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions src/imcflibs/imagej/_loci.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,18 @@
### *** WARNING *** ### *** WARNING *** ### *** WARNING *** ### *** WARNING ***
#


# unproblematic imports kept here for consistency
from loci.plugins import BF
from loci.common import Region
from loci.formats import ImageReader, Memoizer, MetadataTools

# dummy objects to prevent failing imports in a non-ImageJ / Jython context:
ImporterOptions = None
ZeissCZIReader = None
DefaultMetadataOptions = None
MetadataLevel = None
DynamicMetadataOptions = None
MetadataOptions = None

# perform the actual imports when running under Jython using `importlib` calls:
import platform as _python_platform
Expand All @@ -50,5 +53,3 @@
DynamicMetadataOptions = _loci_formats_in.DynamicMetadataOptions
MetadataOptions = _loci_formats_in.MetadataOptions
del _python_platform

from loci.formats import ImageReader, Memoizer, MetadataTools
13 changes: 12 additions & 1 deletion src/imcflibs/imagej/bioformats.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
Memoizer,
MetadataTools,
ZeissCZIReader,
Region,
)


Expand Down Expand Up @@ -186,6 +187,7 @@ def import_image(
t_start=None,
t_end=None,
t_interval=None,
region=None,
):
"""Open an image file using the Bio-Formats importer.

Expand Down Expand Up @@ -229,8 +231,11 @@ def import_image(
only import a subset of time points ending with this one. Requires to
set t_start and t_interval.
t_interval : int, optional
only import a subset of time points with thsi interval. Requires to set
only import a subset of time points with this interval. Requires to set
t_start and t_end.
region : list, optional
Bio-Formats crop region, by default None.
Format: `[start_x, start_y, width_in_px, height_in_px]`.

Returns
-------
Expand Down Expand Up @@ -276,6 +281,12 @@ def import_image(
options.setTEnd(series_number, t_end)
options.setTStep(series_number, t_interval)

if region is not None:
options.setCrop(True)
options.setCropRegion(
series_number, Region(region[0], region[1], region[2], region[3])
)

log.info("Reading [%s]", filename)
orig_imps = BF.openImagePlus(options)
log.debug("Opened [%s] %s", filename, type(orig_imps))
Expand Down
Loading