From 36fe97b3af5334cd07ec3fb6462df4571726c1bf Mon Sep 17 00:00:00 2001 From: "kai.schleicher@unibas.ch" Date: Mon, 18 Aug 2025 10:44:23 +0200 Subject: [PATCH 1/6] Add option to crop region --- src/imcflibs/imagej/bioformats.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/imcflibs/imagej/bioformats.py b/src/imcflibs/imagej/bioformats.py index 5ef19a6b..ba99197f 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)) From d5d5b924b4291e287cc3f05b130abaeefd714b5f Mon Sep 17 00:00:00 2001 From: Niko Ehrenfeuchter Date: Wed, 14 Jan 2026 17:10:28 +0100 Subject: [PATCH 2/6] Fix formatting in bioformats.py docstring --- src/imcflibs/imagej/bioformats.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/imcflibs/imagej/bioformats.py b/src/imcflibs/imagej/bioformats.py index ba99197f..523045c2 100644 --- a/src/imcflibs/imagej/bioformats.py +++ b/src/imcflibs/imagej/bioformats.py @@ -235,7 +235,7 @@ def import_image( 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] + Format: `[start_x, start_y, width_in_px, height_in_px]`. Returns ------- From e8e3ff953eea066ace3ab788cab3aa31db294417 Mon Sep 17 00:00:00 2001 From: Kai Schleicher Date: Fri, 16 Jan 2026 09:12:03 +0100 Subject: [PATCH 3/6] Add Region import --- src/imcflibs/imagej/_loci.py | 1 + 1 file changed, 1 insertion(+) diff --git a/src/imcflibs/imagej/_loci.py b/src/imcflibs/imagej/_loci.py index 0c354373..dd6446e8 100644 --- a/src/imcflibs/imagej/_loci.py +++ b/src/imcflibs/imagej/_loci.py @@ -26,6 +26,7 @@ from loci.plugins import BF +from loci.common import Region # dummy objects to prevent failing imports in a non-ImageJ / Jython context: ImporterOptions = None From 754d101bad8546288fc748333e8314f97c64f294 Mon Sep 17 00:00:00 2001 From: Kai Schleicher Date: Fri, 16 Jan 2026 09:12:59 +0100 Subject: [PATCH 4/6] Group unproblematic imports --- src/imcflibs/imagej/_loci.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/imcflibs/imagej/_loci.py b/src/imcflibs/imagej/_loci.py index dd6446e8..f2d7295f 100644 --- a/src/imcflibs/imagej/_loci.py +++ b/src/imcflibs/imagej/_loci.py @@ -27,6 +27,7 @@ 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 @@ -51,5 +52,3 @@ DynamicMetadataOptions = _loci_formats_in.DynamicMetadataOptions MetadataOptions = _loci_formats_in.MetadataOptions del _python_platform - -from loci.formats import ImageReader, Memoizer, MetadataTools From 747a3650748dbae4cd9ce6a12e5a3d320baa61d5 Mon Sep 17 00:00:00 2001 From: Kai Schleicher Date: Fri, 16 Jan 2026 09:13:20 +0100 Subject: [PATCH 5/6] Add comment to clarify structure --- src/imcflibs/imagej/_loci.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/imcflibs/imagej/_loci.py b/src/imcflibs/imagej/_loci.py index f2d7295f..b6562e85 100644 --- a/src/imcflibs/imagej/_loci.py +++ b/src/imcflibs/imagej/_loci.py @@ -24,7 +24,7 @@ ### *** 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 From ae85ea8d3c2808581b73effa459221f4fe52f87d Mon Sep 17 00:00:00 2001 From: Niko Ehrenfeuchter Date: Fri, 16 Jan 2026 11:22:34 +0100 Subject: [PATCH 6/6] Add missing / forgotten dummy object "MetadataOptions" --- src/imcflibs/imagej/_loci.py | 1 + 1 file changed, 1 insertion(+) diff --git a/src/imcflibs/imagej/_loci.py b/src/imcflibs/imagej/_loci.py index b6562e85..75d415c6 100644 --- a/src/imcflibs/imagej/_loci.py +++ b/src/imcflibs/imagej/_loci.py @@ -35,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