mirror of
https://github.com/wassname/scikit-image.git
synced 2026-09-09 11:33:41 +08:00
@@ -13,8 +13,8 @@ from ..color import rgb2lab
|
||||
@cython.boundscheck(False)
|
||||
@cython.wraparound(False)
|
||||
@cython.cdivision(True)
|
||||
def quickshift(image, ratio=1., float kernel_size=5, max_dist=10, return_tree=False,
|
||||
sigma=0, convert2lab=True, random_seed=None):
|
||||
def quickshift(image, ratio=1., float kernel_size=5, max_dist=10,
|
||||
return_tree=False, sigma=0, convert2lab=True, random_seed=None):
|
||||
"""Segments image using quickshift clustering in Color-(x,y) space.
|
||||
|
||||
Produces an oversegmentation of the image using the quickshift mode-seeking
|
||||
@@ -106,7 +106,8 @@ def quickshift(image, ratio=1., float kernel_size=5, max_dist=10, return_tree=Fa
|
||||
for c_ in range(c_min, c_max):
|
||||
dist = 0
|
||||
for channel in range(channels):
|
||||
dist += (current_pixel_p[channel] - image_c[r_, c_, channel])**2
|
||||
dist += (current_pixel_p[channel] -
|
||||
image_c[r_, c_, channel])**2
|
||||
dist += (r - r_)**2 + (c - c_)**2
|
||||
densities[r, c] += exp(-dist / (2 * kernel_size**2))
|
||||
current_pixel_p += channels
|
||||
@@ -132,9 +133,11 @@ def quickshift(image, ratio=1., float kernel_size=5, max_dist=10, return_tree=Fa
|
||||
if densities[r_, c_] > current_density:
|
||||
dist = 0
|
||||
# We compute the distances twice since otherwise
|
||||
# we get crazy memory overhead (width * height * windowsize**2)
|
||||
# we get crazy memory overhead
|
||||
# (width * height * windowsize**2)
|
||||
for channel in range(channels):
|
||||
dist += (current_pixel_p[channel] - image_c[r_, c_, channel])**2
|
||||
dist += (current_pixel_p[channel] -
|
||||
image_c[r_, c_, channel])**2
|
||||
dist += (r - r_)**2 + (c - c_)**2
|
||||
if dist < closest:
|
||||
closest = dist
|
||||
|
||||
@@ -14,6 +14,8 @@ def slic(image, n_segments=100, ratio=10., max_iter=10, sigma=1,
|
||||
----------
|
||||
image : (width, height, 3) ndarray
|
||||
Input image.
|
||||
n_segments : int
|
||||
The (approximate) number of labels in the segmented output image.
|
||||
ratio: float
|
||||
Balances color-space proximity and image-space proximity.
|
||||
Higher values give more weight to color-space.
|
||||
@@ -42,6 +44,14 @@ def slic(image, n_segments=100, ratio=10., max_iter=10, sigma=1,
|
||||
Pascal Fua, and Sabine Süsstrunk, SLIC Superpixels Compared to
|
||||
State-of-the-art Superpixel Methods, TPAMI, May 2012.
|
||||
|
||||
Examples
|
||||
--------
|
||||
>>> from skimage.segmentation import slic
|
||||
>>> from skimage.data import lena
|
||||
>>> img = lena()
|
||||
>>> segments = slic(img, n_segments=100, ratio=10)
|
||||
>>> # Increasing the ratio parameter yields more square regions
|
||||
>>> segments = slic(img, n_segments=100, ratio=20)
|
||||
"""
|
||||
image = np.atleast_3d(image)
|
||||
if image.shape[2] != 3:
|
||||
|
||||
Reference in New Issue
Block a user