diff --git a/src/imcflibs/imagej/_loci.py b/src/imcflibs/imagej/_loci.py index 0c354373..75d415c6 100644 --- a/src/imcflibs/imagej/_loci.py +++ b/src/imcflibs/imagej/_loci.py @@ -24,8 +24,10 @@ ### *** 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 @@ -33,6 +35,7 @@ DefaultMetadataOptions = None MetadataLevel = None DynamicMetadataOptions = None +MetadataOptions = None # perform the actual imports when running under Jython using `importlib` calls: import platform as _python_platform @@ -50,5 +53,3 @@ DynamicMetadataOptions = _loci_formats_in.DynamicMetadataOptions MetadataOptions = _loci_formats_in.MetadataOptions del _python_platform - -from loci.formats import ImageReader, Memoizer, MetadataTools diff --git a/src/imcflibs/imagej/bioformats.py b/src/imcflibs/imagej/bioformats.py index ba1474cf..194fa352 100644 --- a/src/imcflibs/imagej/bioformats.py +++ b/src/imcflibs/imagej/bioformats.py @@ -24,6 +24,7 @@ Memoizer, MetadataTools, ZeissCZIReader, + Region, ) @@ -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. @@ -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 ------- @@ -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))