我们从Python开源项目中,提取了以下11个代码示例,用于说明如何使用skimage.morphology.dilation()。
def input_wrapper(f): image = misc.imread(f) sx,sy = image.shape diff = np.abs(sx-sy) sx,sy = image.shape image = np.pad(image,((sx//8,sx//8),(sy//8,sy//8)),'constant') if sx > sy: image = np.pad(image,((0,0),(diff//2,diff//2)),'constant') else: image = np.pad(image,((diff//2,diff//2),(0,0)),'constant') image = dilation(image,disk(max(sx,sy)/32)) image = misc.imresize(image,(32,32)) if np.max(image) > 1: image = image/255. return image
def input_wrapper(f): image = misc.imread(f) # image[image>50]=255 # image[image<=50]=0 sx,sy = image.shape diff = np.abs(sx-sy) sx,sy = image.shape image = np.pad(image,((sx//8,sx//8),(sy//8,sy//8)),'constant') if sx > sy: image = np.pad(image,((0,0),(diff//2,diff//2)),'constant') else: image = np.pad(image,((diff//2,diff//2),(0,0)),'constant') image = dilation(image,disk(max(sx,sy)/32)) image = misc.imresize(image,(32,32)) if np.max(image) > 1: image = image/255. return image
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 input_wrapper_arr(self,image): sx,sy = image.shape diff = np.abs(sx-sy) sx,sy = image.shape image = np.pad(image,((sx//8,sx//8),(sy//8,sy//8)),'constant') if sx > sy: image = np.pad(image,((0,0),(diff//2,diff//2)),'constant') else: image = np.pad(image,((diff//2,diff//2),(0,0)),'constant') image = dilation(image,disk(max(sx,sy)/32)) image = misc.imresize(image,(32,32)) if np.max(image) > 1: image = image/255. return image
def whiteout_ramp(image, linecoords): # Dilation enlarge the bright segments and cut them out off the original image imagesection = image[linecoords.object] count = 0 for i in morph.dilation(linecoords.object_matrix, morph.square(10)): whitevalue = measurements.find_objects(i == linecoords.object_value + 1) if whitevalue: whitevalue = whitevalue[0][0] imagesection[count,whitevalue.start:whitevalue.stop] = 255 count +=1 return 0
def binary_dilation(x, radius=3): """ Return fast binary morphological dilation of an image. see `skimage.morphology.binary_dilation <http://scikit-image.org/docs/dev/api/skimage.morphology.html#skimage.morphology.binary_dilation>`_. Parameters ----------- x : 2D array image. radius : int for the radius of mask. """ from skimage.morphology import disk, binary_dilation mask = disk(radius) x = binary_dilation(x, selem=mask) return x
def dilation(x, radius=3): """ Return greyscale morphological dilation of an image, see `skimage.morphology.dilation <http://scikit-image.org/docs/dev/api/skimage.morphology.html#skimage.morphology.dilation>`_. Parameters ----------- x : 2D array image. radius : int for the radius of mask. """ from skimage.morphology import disk, dilation mask = disk(radius) x = dilation(x, selem=mask) return x
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_dilation(img): return dilation(img)
def get_stomata(max_proj_image, min_obj_size=200, max_obj_size=1000): """Performs image segmentation from a max_proj_image. Disposes of objects in range min_obj_size to max_obj_size :param max_proj_image: the maximum projection image :type max_proj_image: numpy.ndarray, uint16 :param min_obj_size: minimum size of object to keep :type min_obj_size: int :param max_obj_size: maximum size of object to keep :type max_obj_size: int :returns: list of [ [coordinates of kept objects - list of slice objects], binary object image - numpy.ndarray, labelled object image - numpy.ndarray ] """ # pore_margin = 10 # max_obj_size = 1000 # min_obj_size = 200 # for prop, value in segment_options: # if prop == 'pore_margin': # pore_margin = value # if prop == 'max_obj_size': # max_obj_size = value # if prop == 'min_obj_size': # min_obj_size = value # # print(pore_margin) # print(max_obj_size) # print(min_obj_size) #rescale_min = 50 #rescale_max= 100 #rescaled = exposure.rescale_intensity(max_proj_image, in_range=(rescale_min,rescale_max)) rescaled = max_proj_image seed = np.copy(rescaled) seed[1:-1, 1:-1] = rescaled.max() #mask = rescaled #if gamma != None: # rescaled = exposure.adjust_gamma(max_proj_image, gamma) #filled = reconstruction(seed, mask, method='erosion') closed = dilation(rescaled) seed = np.copy(closed) seed[1:-1, 1:-1] = closed.max() mask = closed filled = reconstruction(seed, mask, method='erosion') label_objects, nb_labels = ndimage.label(filled) sizes = np.bincount(label_objects.ravel()) mask_sizes = sizes mask_sizes = (sizes > min_obj_size) & (sizes < max_obj_size) #mask_sizes = (sizes > 200) & (sizes < 1000) mask_sizes[0] = 0 big_objs = mask_sizes[label_objects] stomata, _ = ndimage.label(big_objs) obj_slices = ndimage.find_objects(stomata) return [obj_slices, big_objs, stomata]