Skip to content

Commit 9f73e90

Browse files
committed
Move binary_to_label() to "labelimage" module
1 parent 457a911 commit 9f73e90

2 files changed

Lines changed: 42 additions & 41 deletions

File tree

src/imcflibs/imagej/labelimage.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from ij.process import FloatProcessor, ImageProcessor
77
from inra.ijpb.label import LabelImages as li
88
from inra.ijpb.plugins import AnalyzeRegions
9+
from mcib3d.image3d import ImageHandler, ImageLabeller
910

1011

1112
def label_image_to_roi_list(label_image, low_thresh=None):
@@ -138,3 +139,44 @@ def measure_objects_size_shape_2d(label_image):
138139
"""
139140
regions = AnalyzeRegions()
140141
return regions.process(label_image)
142+
143+
144+
def binary_to_label(imp, title, min_thresh=1, min_vol=None, max_vol=None):
145+
"""Segment a binary image to get a label image (2D/3D).
146+
147+
Works on: 2D and 3D binary data.
148+
149+
Parameters
150+
----------
151+
imp : ImagePlus
152+
Binary 3D stack or 2D image.
153+
title : str
154+
Title of the new image.
155+
min_thresh : int, optional
156+
Threshold to do segmentation, also allows for label filtering, by
157+
default 1.
158+
min_vol : float, optional
159+
Volume under which to exclude objects, by default None.
160+
max_vol : float, optional
161+
Volume above which to exclude objects, by default None.
162+
163+
Returns
164+
-------
165+
ImagePlus
166+
Segmented labeled ImagePlus.
167+
"""
168+
cal = imp.getCalibration()
169+
img = ImageHandler.wrap(imp)
170+
img = img.threshold(min_thresh, False, False)
171+
172+
labeler = ImageLabeller()
173+
if min_vol:
174+
labeler.setMinSize(min_vol)
175+
if max_vol:
176+
labeler.setMaxSize(max_vol)
177+
178+
seg = labeler.getLabels(img)
179+
seg.setScale(cal.pixelWidth, cal.pixelDepth, cal.getUnits())
180+
seg.setTitle(title)
181+
182+
return seg.getImagePlus()

src/imcflibs/imagej/roimgr3d.py

Lines changed: 0 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -3,47 +3,6 @@
33
from mcib3d.image3d import ImageHandler, ImageLabeller
44

55

6-
def binary_to_label(imp, title, min_thresh=1, min_vol=None, max_vol=None):
7-
"""Segment a binary image to get a label image (2D/3D).
8-
9-
Works on: 2D and 3D binary data.
10-
11-
Parameters
12-
----------
13-
imp : ImagePlus
14-
Binary 3D stack or 2D image.
15-
title : str
16-
Title of the new image.
17-
min_thresh : int, optional
18-
Threshold to do segmentation, also allows for label filtering, by
19-
default 1.
20-
min_vol : float, optional
21-
Volume under which to exclude objects, by default None.
22-
max_vol : float, optional
23-
Volume above which to exclude objects, by default None.
24-
25-
Returns
26-
-------
27-
ImagePlus
28-
Segmented labeled ImagePlus.
29-
"""
30-
cal = imp.getCalibration()
31-
img = ImageHandler.wrap(imp)
32-
img = img.threshold(min_thresh, False, False)
33-
34-
labeler = ImageLabeller()
35-
if min_vol:
36-
labeler.setMinSize(min_vol)
37-
if max_vol:
38-
labeler.setMaxSize(max_vol)
39-
40-
seg = labeler.getLabels(img)
41-
seg.setScale(cal.pixelWidth, cal.pixelDepth, cal.getUnits())
42-
seg.setTitle(title)
43-
44-
return seg.getImagePlus()
45-
46-
476
def population3d_to_imgplus(imp, population):
487
"""Make an ImagePlus from an Objects3DPopulation (2D/3D).
498

0 commit comments

Comments
 (0)