本文整理汇总了Python中skimage.segmentation.felzenszwalb方法的典型用法代码示例。如果您正苦于以下问题:Python segmentation.felzenszwalb方法的具体用法?Python segmentation.felzenszwalb怎么用?Python segmentation.felzenszwalb使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类skimage.segmentation
的用法示例。
在下文中一共展示了segmentation.felzenszwalb方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: felzenszwalb
# 需要导入模块: from skimage import segmentation [as 别名]
# 或者: from skimage.segmentation import felzenszwalb [as 别名]
def felzenszwalb(image, scale=SCALE, sigma=SIGMA, min_size=MIN_SIZE):
"""Computes Felsenszwalb's efficient graph based image segmentation.
Args:
image: The image.
scale: Float indicating largeness of clusters (optional).
sigma: Width of Gaussian kernel used in preprocessing (optional).
min_size: Minimum component size. Enforced using postprocessing
(optional).
Returns:
Integer mask indicating segment labels.
"""
image = tf.cast(image, tf.uint8)
def _felzenszwalb(image):
segmentation = skimage_felzenszwalb(image, scale, sigma, min_size)
return segmentation.astype(np.int32)
return tf.py_func(_felzenszwalb, [image], tf.int32, stateful=False,
name='felzenszwalb')
示例2: segment_image
# 需要导入模块: from skimage import segmentation [as 别名]
# 或者: from skimage.segmentation import felzenszwalb [as 别名]
def segment_image(im, parameter_object):
dims, rows, cols = im.shape
image2segment = np.dstack((rescale_intensity(im[0],
in_range=(parameter_object.image_min,
parameter_object.image_max),
out_range=(0, 255)),
rescale_intensity(im[1],
in_range=(parameter_object.image_min,
parameter_object.image_max),
out_range=(0, 255)),
rescale_intensity(im[2],
in_range=(parameter_object.image_min,
parameter_object.image_max),
out_range=(0, 255))))
felzer = felzenszwalb(np.uint8(image2segment),
scale=50,
sigma=.01,
min_size=5,
multichannel=True).reshape(rows, cols)
props = regionprops(felzer)
props = np.array([p.area for p in props], dtype='uint64')
return fill_labels(np.uint64(felzer), props)
示例3: create_patches
# 需要导入模块: from skimage import segmentation [as 别名]
# 或者: from skimage.segmentation import felzenszwalb [as 别名]
def create_patches(self, method='slic', discovery_images=None,
param_dict=None):
"""Creates a set of image patches using superpixel methods.
This method takes in the concept discovery images and transforms it to a
dataset made of the patches of those images.
Args:
method: The superpixel method used for creating image patches. One of
'slic', 'watershed', 'quickshift', 'felzenszwalb'.
discovery_images: Images used for creating patches. If None, the images in
the target class folder are used.
param_dict: Contains parameters of the superpixel method used in the form
of {'param1':[a,b,...], 'param2':[z,y,x,...], ...}. For instance
{'n_segments':[15,50,80], 'compactness':[10,10,10]} for slic
method.
"""
if param_dict is None:
param_dict = {}
dataset, image_numbers, patches = [], [], []
if discovery_images is None:
raw_imgs = self.load_concept_imgs(
self.target_class, self.num_discovery_imgs)
self.discovery_images = raw_imgs
else:
self.discovery_images = discovery_images
if self.num_workers:
pool = multiprocessing.Pool(self.num_workers)
outputs = pool.map(
lambda img: self._return_superpixels(img, method, param_dict),
self.discovery_images)
for fn, sp_outputs in enumerate(outputs):
image_superpixels, image_patches = sp_outputs
for superpixel, patch in zip(image_superpixels, image_patches):
dataset.append(superpixel)
patches.append(patch)
image_numbers.append(fn)
else:
for fn, img in enumerate(self.discovery_images):
image_superpixels, image_patches = self._return_superpixels(
img, method, param_dict)
for superpixel, patch in zip(image_superpixels, image_patches):
dataset.append(superpixel)
patches.append(patch)
image_numbers.append(fn)
self.dataset, self.image_numbers, self.patches =\
np.array(dataset), np.array(image_numbers), np.array(patches)