Adding a function that trims all non percolating paths from the image including edges.
@@ -99,6 +99,69 @@ def trim_floating_solid(im):
im[holes] = True
return im
+def trim_nonpercolating_paths(im, inlet_axis=0, outlet_axis=0):
+ r"""
+ Removes all disconnected solid clusters including edges that are
+ nonpercolating.
+
+ Parameters
+ ----------
+ im : ND-array
+ The image of the porous material
+
+ inlet_axis : int
+ Inlet axis of boundary condition. For three dimensional image the
+ number ranges from 0 to 2. For two dimensional image the range is
+ between 0 to 1.
+
+ outlet_axis : int
+ Outlet axis of boundary condition. For three dimensional image the
+ number ranges from 0 to 2. For two dimensional image the range is
+ between 0 to 1.
+
+ Returns
+ -------
+ A version of ``im`` but with all the disconnected solid removed.
+
+ See Also
+ --------
+ find_disconnected_voxels
+
+ """
+ im = trim_floating_solid(im)
+ labels = spim.label(im)[0]
+ inlet = sp.zeros_like(im,dtype=int)
+ outlet = sp.zeros_like(im,dtype=int)
+ if im.ndim == 3
+ if inlet_axis = 0:
+ inlet[0,:,:] = 1
+ elif inlet_axis = 1:
+ inlet[:,0,:] = 1
+ else inlet_axis = 2:
+ inlet[:,:,0] = 1
+
+ if outlet_axis = 0:
+ outlet[-1,:,:] = 1
+ elif outlet_axis = 1:
+ outlet[:,-1,:] = 1
+ else outlet_axis = 2:
+ outlet[:,:,-1] = 1
+
+ if im.ndim == 2
+ if inlet_axis = 0:
+ inlet[0,:] = 1
+ else inlet_axis = 1:
+ inlet[:,0] = 1
+
+ if outlet_axis = 0:
+ outlet[-1,:] = 1
+ else outlet_axis = 1:
+ outlet[:,-1] = 1
+ IN = sp.unique(labels*inlet)
+ OUT = sp.unique(labels*outlet)
+ new_im = sp.isin(im,list(set(IN) ^ set(OUT)))
+ im[new_im == True] = False
+ return im
def trim_extrema(im, h, mode='maxima'):
r"""
