|
6 | 6 | from ij.process import FloatProcessor, ImageProcessor |
7 | 7 | from inra.ijpb.label import LabelImages as li |
8 | 8 | from inra.ijpb.plugins import AnalyzeRegions |
| 9 | +from mcib3d.image3d import ImageHandler, ImageLabeller |
9 | 10 |
|
10 | 11 |
|
11 | 12 | def label_image_to_roi_list(label_image, low_thresh=None): |
@@ -138,3 +139,44 @@ def measure_objects_size_shape_2d(label_image): |
138 | 139 | """ |
139 | 140 | regions = AnalyzeRegions() |
140 | 141 | 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() |
0 commit comments