adding edges option to find disconnected blobs related funcs
@@ -213,7 +213,7 @@ def distance_transform_lin(im, axis=0, mode="both"):
return f
-def find_disconnected_voxels(im, conn=None):
+def find_disconnected_voxels(im, conn=None, edges=False):
r"""
Identifies all voxels that are not connected to the edge of the image.
@@ -226,12 +226,15 @@ def find_disconnected_voxels(im, conn=None):
For 2D the options are 4 and 8 for square and diagonal neighbors,
while for the 3D the options are 6 and 26, similarily for square
and diagonal neighbors. The default is the maximum option.
+ edges : bool
+ If ``True`` any isolated regions touch the edge of the image are
+ considered disconnected.
Returns
-------
image : ndarray
- An ndarray the same size as ``im``, with True values indicating
- voxels of the phase of interest (i.e. True values in the original
+ An ndarray the same size as ``im``, with ``True`` values indicating
+ voxels of the phase of interest (i.e. ``True`` values in the original
image) that are not connected to the outer edges.
See Also
@@ -267,13 +270,18 @@ def find_disconnected_voxels(im, conn=None):
else:
raise Exception("Received conn is not valid")
labels, N = spim.label(input=im, structure=strel)
+ if edges is False:
holes = clear_border(labels=labels) > 0
+ else:
+ counts = np.bincount(labels.flatten())[1:]
+ keep = np.where(counts == counts.max())[0] + 1
+ holes = (labels != keep)*im
return holes
-def fill_blind_pores(im, conn=None):
+def fill_blind_pores(im, conn=None, edges=False):
r"""
- Fills all pores that are not connected to the edges of the image.
+ Fills all blind pores that are isolated from the main void space.
Parameters
----------
@@ -288,6 +296,9 @@ def fill_blind_pores(im, conn=None):
For 2D the options are 4 and 8 for square and diagonal neighbors,
while for the 3D the options are 6 and 26, similarily for square
and diagonal neighbors. The default is the maximum option.
+ edges : bool
+ If ``True``, any isolated regions that are connected to the edge
+ of the image are also removed.
See Also
--------
@@ -301,7 +312,7 @@ def fill_blind_pores(im, conn=None):
"""
im = np.copy(im)
- holes = find_disconnected_voxels(im, conn=conn)
+ holes = find_disconnected_voxels(im, conn=conn, edges=edges)
im[holes] = False
return im
