我们从Python开源项目中,提取了以下5个代码示例,用于说明如何使用skimage.morphology.erosion()。
def trim_edge_cube(cube): """ trim_edge_cube: Function that reads in a cube and removes the edges in the cube. It runs the erode function to make sure that pixels within 3 pixels away from the edges are blanked. This is useful to remove very noisy pixels due to lower coverage by KFPA. ---------------------------------------- Warning: This function modifies the cube. """ # mask = np.isfinite(cube) if len(cube.shape) == 2: mask_2d = mask[:,:] else: mask_2d = mask[0,:,:] # remove image edges mask_2d[:,0] = mask_2d[:,-1] = False mask_2d[0,:] = mask_2d[-1,:] = False # now erode image (using disk) and convert back to 3D mask # then replace all voxels with NaN mask &= erosion(mask_2d,disk(5)) cube[~mask] = np.nan
def erosion(x, radius=3): """ Return greyscale morphological erosion of an image, see `skimage.morphology.erosion <http://scikit-image.org/docs/dev/api/skimage.morphology.html#skimage.morphology.erosion>`_. Parameters ----------- x : 2D array image. radius : int for the radius of mask. """ from skimage.morphology import disk, dilation, erosion mask = disk(radius) x = erosion(x, selem=mask) return x ## Object Detection
def extract_voxels(images,pred_1,truths=None): eroded = morphology.erosion(pred_1,np.ones([3,3,3])) dilation = morphology.dilation(eroded,np.ones([3,3,3])) labels = measure.label(dilation) # Different labels are displayed in different colors label_vals = np.unique(labels) regions = measure.regionprops(labels) kept = 0 removed = 0 data = [] for idx in range(len(regions)): b = regions[idx].bbox if regions[idx].area < 50: removed += 1 continue kept += 1 print "before->",b b = get_bounding_box(b,images.shape) print "after->",b image_voxel = images[b[0]:b[3],b[1]:b[4],b[2]:b[5]] label = 0 if not truths is None: print "finding region in truths" truth_voxel = truths[b[0]:b[3],b[1]:b[4],b[2]:b[5]] nonzeros = np.count_nonzero(truth_voxel) if nonzeros > 0: label = 1 assert(image_voxel.size==(VOXEL_DEPTH*VOXEL_DEPTH*VOXEL_DEPTH)) print "Appending voxel with label ",label data.append((image_voxel,label,b)) print "kept",kept,"removed",removed sys.stdout.flush() return data
def binary_erosion(x, radius=3): """ Return binary morphological erosion of an image, see `skimage.morphology.binary_erosion <http://scikit-image.org/docs/dev/api/skimage.morphology.html#skimage.morphology.binary_erosion>`_. Parameters ----------- x : 2D array image. radius : int for the radius of mask. """ from skimage.morphology import disk, dilation, binary_erosion mask = disk(radius) x = binary_erosion(x, selem=mask) return x
def TF_erosion(img): return erosion(img)