@@ -71,7 +71,15 @@ def imgplus_to_population3d(imp):
7171 return Objects3DPopulation (img )
7272
7373
74- def segment_3d_image (imp , title = None , min_thresh = 1 , min_vol = None , max_vol = None ):
74+ def segment_3d_image (
75+ imp ,
76+ title = None ,
77+ min_thresh = 1 ,
78+ min_vol = None ,
79+ max_vol = None ,
80+ remove_touching_borders = False ,
81+ remove_touching_borders_z = False ,
82+ ):
7583 """Segment a 3D binary image to get a labelled stack.
7684
7785 Parameters
@@ -90,6 +98,11 @@ def segment_3d_image(imp, title=None, min_thresh=1, min_vol=None, max_vol=None):
9098 max_vol : int, optional
9199 Maximum volume (in voxels) above which objects get filtered.
92100 Defaults to None.
101+ remove_touching_borders : bool, optional
102+ Whether to remove objects that touch the borders in X and Y. Defaults to False.
103+ remove_touching_borders_z : bool, optional
104+ Whether to remove objects that touch the z-axis borders. Defaults to False.
105+
93106
94107 Returns
95108 -------
@@ -107,10 +120,15 @@ def segment_3d_image(imp, title=None, min_thresh=1, min_vol=None, max_vol=None):
107120 labeler .setMinSizeCalibrated (min_vol , img )
108121 if max_vol :
109122 labeler .setMaxSizeCalibrated (max_vol , img )
110-
111123 # Generate labelled segmentation
112124 seg = labeler .getLabels (img )
113125 seg .setScale (cal .pixelWidth , cal .pixelDepth , cal .getUnits ())
126+
127+ if remove_touching_borders :
128+ obj = seg .getObjects3DPopulation ()
129+ obj .removeObjectsTouchingBorders (seg , remove_touching_borders_z )
130+ seg = ImageHandler .wrap (population3d_to_imgplus (imp , obj ))
131+
114132 if title :
115133 seg .setTitle (title )
116134
0 commit comments