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