本文整理汇总了Python中skimage.segmentation方法的典型用法代码示例。如果您正苦于以下问题:Python skimage.segmentation方法的具体用法?Python skimage.segmentation怎么用?Python skimage.segmentation使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类skimage
的用法示例。
在下文中一共展示了skimage.segmentation方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: execute
# 需要导入模块: import skimage [as 别名]
# 或者: from skimage import segmentation [as 别名]
def execute(self, eopatch):
""" Main execute method
"""
feature_type, feature_name = next(self.feature_checker(eopatch))
data = eopatch[feature_type][feature_name]
if np.isnan(data).any():
warnings.warn('There are NaN values in given data, super-pixel segmentation might produce bad results',
RuntimeWarning)
if feature_type.is_time_dependent():
data = np.moveaxis(data, 0, 2)
data = data.reshape((data.shape[0], data.shape[1], data.shape[2] * data.shape[3]))
superpixel_mask = np.atleast_3d(self._create_superpixel_mask(data))
new_feature_type, new_feature_name = self.superpixel_feature
eopatch[new_feature_type][new_feature_name] = superpixel_mask
return eopatch
示例2: generate_markers
# 需要导入模块: import skimage [as 别名]
# 或者: from skimage import segmentation [as 别名]
def generate_markers(image):
#Creation of the internal Marker
marker_internal = image < -400
marker_internal = segmentation.clear_border(marker_internal)
marker_internal_labels = measure.label(marker_internal)
areas = [r.area for r in measure.regionprops(marker_internal_labels)]
areas.sort()
if len(areas) > 2:
for region in measure.regionprops(marker_internal_labels):
if region.area < areas[-2]:
for coordinates in region.coords:
marker_internal_labels[coordinates[0], coordinates[1]] = 0
marker_internal = marker_internal_labels > 0
#Creation of the external Marker
external_a = ndimage.binary_dilation(marker_internal, iterations=10)
external_b = ndimage.binary_dilation(marker_internal, iterations=55)
marker_external = external_b ^ external_a
#Creation of the Watershed Marker matrix
marker_watershed = np.zeros(image.shape, dtype=np.int)
marker_watershed += marker_internal * 255
marker_watershed += marker_external * 128
return marker_internal, marker_external, marker_watershed
示例3: get_masks
# 需要导入模块: import skimage [as 别名]
# 或者: from skimage import segmentation [as 别名]
def get_masks(img, n_seg=250):
logger.debug('SLIC segmentation initialised')
segments = skimage.segmentation.slic(img, n_segments=n_seg, compactness=10, sigma=1)
logger.debug('SLIC segmentation complete')
logger.debug('contour extraction...')
masks = [[numpy.zeros((img.shape[0], img.shape[1]), dtype=numpy.uint8), None]]
for region in skimage.measure.regionprops(segments):
masks.append([masks[0][0].copy(), region.bbox])
x_min, y_min, x_max, y_max = region.bbox
masks[-1][0][x_min:x_max, y_min:y_max] = skimage.img_as_ubyte(region.convex_image)
logger.debug('contours extracted')
return masks[1:]
示例4: __init__
# 需要导入模块: import skimage [as 别名]
# 或者: from skimage import segmentation [as 别名]
def __init__(self, feature, superpixel_feature, *, segmentation_object=skimage.segmentation.felzenszwalb,
**segmentation_params):
"""
:param feature: Raster feature which will be used in segmentation
:param superpixel_feature: A new mask timeless feature to hold super-pixel mask
:param segmentation_object: A function (object) which performs superpixel segmentation, by default that is
`skimage.segmentation.felzenszwalb`
:param segmentation_params: Additional parameters which will be passed to segmentation_object function
"""
self.feature_checker = self._parse_features(feature, allowed_feature_types=FeatureTypeSet.SPATIAL_TYPES)
self.superpixel_feature = next(self._parse_features(superpixel_feature,
allowed_feature_types={FeatureType.MASK_TIMELESS})())
self.segmentation_object = segmentation_object
self.segmentation_params = segmentation_params
示例5: _create_superpixel_mask
# 需要导入模块: import skimage [as 别名]
# 或者: from skimage import segmentation [as 别名]
def _create_superpixel_mask(self, data):
""" Method which performs the segmentation
"""
with warnings.catch_warnings():
warnings.filterwarnings('ignore', category=RuntimeWarning, module=skimage.segmentation.__name__)
return self.segmentation_object(data, **self.segmentation_params)
示例6: getMinorMajorRatio_2
# 需要导入模块: import skimage [as 别名]
# 或者: from skimage import segmentation [as 别名]
def getMinorMajorRatio_2(image):
image = image.copy()
# Create the thresholded image to eliminate some of the background
imagethr = np.where(image > np.mean(image),0.,1.0)
#Dilate the image
imdilated = morphology.dilation(imagethr, np.ones((4,4)))
# Create the label list
label_list = measure.label(imdilated)
label_list = imagethr*label_list
label_list = label_list.astype(int)
region_list = measure.regionprops(label_list)
maxregion = getLargestRegion(region_list, label_list, imagethr)
# guard against cases where the segmentation fails by providing zeros
ratio = 0.0
minor_axis_length = 0.0
major_axis_length = 0.0
area = 0.0
convex_area = 0.0
eccentricity = 0.0
equivalent_diameter = 0.0
euler_number = 0.0
extent = 0.0
filled_area = 0.0
orientation = 0.0
perimeter = 0.0
solidity = 0.0
centroid = [0.0,0.0]
if ((not maxregion is None) and (maxregion.major_axis_length != 0.0)):
ratio = 0.0 if maxregion is None else maxregion.minor_axis_length*1.0 / maxregion.major_axis_length
minor_axis_length = 0.0 if maxregion is None else maxregion.minor_axis_length
major_axis_length = 0.0 if maxregion is None else maxregion.major_axis_length
area = 0.0 if maxregion is None else maxregion.area
convex_area = 0.0 if maxregion is None else maxregion.convex_area
eccentricity = 0.0 if maxregion is None else maxregion.eccentricity
equivalent_diameter = 0.0 if maxregion is None else maxregion.equivalent_diameter
euler_number = 0.0 if maxregion is None else maxregion.euler_number
extent = 0.0 if maxregion is None else maxregion.extent
filled_area = 0.0 if maxregion is None else maxregion.filled_area
orientation = 0.0 if maxregion is None else maxregion.orientation
perimeter = 0.0 if maxregion is None else maxregion.perimeter
solidity = 0.0 if maxregion is None else maxregion.solidity
centroid = [0.0,0.0] if maxregion is None else maxregion.centroid
return ratio,minor_axis_length,major_axis_length,area,convex_area,eccentricity,\
equivalent_diameter,euler_number,extent,filled_area,orientation,perimeter,solidity, centroid[0], centroid[1]