我们从Python开源项目中,提取了以下6个代码示例,用于说明如何使用skimage.morphology.reconstruction()。
def regional_filter(z, h): """Perform a h-dome regional filtering of the an image for background subtraction. Parameters ---------- h : float h-dome cutoff value. Returns ------- h-dome subtracted image as np.array """ seed = np.copy(z) seed = z - h mask = z dilated = morphology.reconstruction(seed, mask, method='dilation') return z - dilated
def regional_flattener(z, h): """Localised erosion of the image 'z' for features below a value 'h'""" seed = np.copy(z) + h mask = z eroded = morphology.reconstruction(seed, mask, method='erosion') return eroded - h
def execMorphologicalDilation(filteredImg, h=0.4): mask = filteredImg seed = filteredImg - h dilatedImg = reconstruction(seed, mask, method='dilation') return dilatedImg
def bg_sub_signPreserveNorm(imageFile, path, extent, extension): vec = signPreserveNorm(imageFile, path, extent, extension) image = np.reshape(vec, (20,20), order="F") image = gaussian_filter(image, 1) seed = np.copy(image) seed[1:-1, 1:-1] = image.min() mask = image dilated = reconstruction(seed, mask, method='dilation') return np.ravel(image - dilated, order="F")
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]