Skip to content

Commit 4b11d8e

Browse files
authored
Merge pull request #108 from CellKai/modify-bf-import
Add option to crop region
2 parents c276511 + 7825f1e commit 4b11d8e

2 files changed

Lines changed: 16 additions & 4 deletions

File tree

src/imcflibs/imagej/_loci.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,18 @@
2424
### *** WARNING *** ### *** WARNING *** ### *** WARNING *** ### *** WARNING ***
2525
#
2626

27-
27+
# unproblematic imports kept here for consistency
2828
from loci.plugins import BF
29+
from loci.common import Region
30+
from loci.formats import ImageReader, Memoizer, MetadataTools
2931

3032
# dummy objects to prevent failing imports in a non-ImageJ / Jython context:
3133
ImporterOptions = None
3234
ZeissCZIReader = None
3335
DefaultMetadataOptions = None
3436
MetadataLevel = None
3537
DynamicMetadataOptions = None
38+
MetadataOptions = None
3639

3740
# perform the actual imports when running under Jython using `importlib` calls:
3841
import platform as _python_platform
@@ -50,5 +53,3 @@
5053
DynamicMetadataOptions = _loci_formats_in.DynamicMetadataOptions
5154
MetadataOptions = _loci_formats_in.MetadataOptions
5255
del _python_platform
53-
54-
from loci.formats import ImageReader, Memoizer, MetadataTools

src/imcflibs/imagej/bioformats.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
Memoizer,
2525
MetadataTools,
2626
ZeissCZIReader,
27+
Region,
2728
)
2829

2930

@@ -186,6 +187,7 @@ def import_image(
186187
t_start=None,
187188
t_end=None,
188189
t_interval=None,
190+
region=None,
189191
):
190192
"""Open an image file using the Bio-Formats importer.
191193
@@ -229,8 +231,11 @@ def import_image(
229231
only import a subset of time points ending with this one. Requires to
230232
set t_start and t_interval.
231233
t_interval : int, optional
232-
only import a subset of time points with thsi interval. Requires to set
234+
only import a subset of time points with this interval. Requires to set
233235
t_start and t_end.
236+
region : list, optional
237+
Bio-Formats crop region, by default None.
238+
Format: `[start_x, start_y, width_in_px, height_in_px]`.
234239
235240
Returns
236241
-------
@@ -276,6 +281,12 @@ def import_image(
276281
options.setTEnd(series_number, t_end)
277282
options.setTStep(series_number, t_interval)
278283

284+
if region is not None:
285+
options.setCrop(True)
286+
options.setCropRegion(
287+
series_number, Region(region[0], region[1], region[2], region[3])
288+
)
289+
279290
log.info("Reading [%s]", filename)
280291
orig_imps = BF.openImagePlus(options)
281292
log.debug("Opened [%s] %s", filename, type(orig_imps))

0 commit comments

Comments
 (0)