@@ -144,43 +144,59 @@ def measure_objects_size_shape_2d(label_image):
144144
145145
146146def binary_to_label (imp , title , min_thresh = 1 , min_vol = None , max_vol = None ):
147- """Segment a binary image to get a label image (2D/3D).
147+ """
148+ Segment a binary image to get a label image (2D/3D).
148149
149- Works on: 2D and 3D binary data.
150+ This function works on both 2D and 3D binary data.
150151
151152 Parameters
152153 ----------
153- imp : ImagePlus
154+ imp : ij. ImagePlus
154155 Binary 3D stack or 2D image.
155156 title : str
156157 Title of the new image.
157158 min_thresh : int, optional
158- Threshold to do segmentation, also allows for label filtering, by
159- default 1.
159+ Threshold to do segmentation, also allows for label filtering, by default 1.
160160 min_vol : float, optional
161161 Volume under which to exclude objects, by default None.
162162 max_vol : float, optional
163163 Volume above which to exclude objects, by default None.
164164
165165 Returns
166166 -------
167- ImagePlus
167+ ij. ImagePlus
168168 Segmented labeled ImagePlus.
169169 """
170+ # Get the calibration of the input ImagePlus
170171 cal = imp .getCalibration ()
172+
173+ # Wrap the ImagePlus in an ImageHandler
171174 img = ImageHandler .wrap (imp )
175+
176+ # Threshold the image using the specified threshold value
172177 img = img .threshold (min_thresh , False , False )
173178
179+ # Create an ImageLabeller instance
174180 labeler = ImageLabeller ()
181+
182+ # Set the minimum size for labeling if provided
175183 if min_vol :
176184 labeler .setMinSize (min_vol )
185+
186+ # Set the maximum size for labeling if provided
177187 if max_vol :
178188 labeler .setMaxSize (max_vol )
179189
190+ # Get the labeled image
180191 seg = labeler .getLabels (img )
192+
193+ # Set the scale of the labeled image
181194 seg .setScale (cal .pixelWidth , cal .pixelDepth , cal .getUnits ())
195+
196+ # Set the title of the labeled image
182197 seg .setTitle (title )
183198
199+ # Return the segmented labeled ImagePlus
184200 return seg .getImagePlus ()
185201
186202
0 commit comments