當前位置: 首頁>>代碼示例>>Python>>正文


Python ndimage.sobel方法代碼示例

本文整理匯總了Python中scipy.ndimage.sobel方法的典型用法代碼示例。如果您正苦於以下問題:Python ndimage.sobel方法的具體用法?Python ndimage.sobel怎麽用?Python ndimage.sobel使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在scipy.ndimage的用法示例。


在下文中一共展示了ndimage.sobel方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: image_gradient

# 需要導入模塊: from scipy import ndimage [as 別名]
# 或者: from scipy.ndimage import sobel [as 別名]
def image_gradient(image, horv):
    """apply a sobel filter to the image to approximate the gradient

    Parameters
    ----------
    image : ndarray(h, v)
        image as an ndarray
    horv : string
        "h" or "v", direction of gradient.

    Returns
    -------
    image_dir : ndarray(h, v)
        directional gradient magnitude at each pixel

    """
    axis = 1 if horv == 'h' else 0
    grad = ndi.sobel(image, axis, mode='constant', cval=np.nan) / 8.0
    return np.nan_to_num(grad) 
開發者ID:welch,項目名稱:rasl,代碼行數:21,代碼來源:jacobian.py

示例2: test_sobel01

# 需要導入模塊: from scipy import ndimage [as 別名]
# 或者: from scipy.ndimage import sobel [as 別名]
def test_sobel01(self):
        for type in self.types:
            array = numpy.array([[3, 2, 5, 1, 4],
                                    [5, 8, 3, 7, 1],
                                    [5, 6, 9, 3, 5]], type)
            t = ndimage.correlate1d(array, [-1.0, 0.0, 1.0], 0)
            t = ndimage.correlate1d(t, [1.0, 2.0, 1.0], 1)
            output = ndimage.sobel(array, 0)
            assert_array_almost_equal(t, output) 
開發者ID:ktraunmueller,項目名稱:Computable,代碼行數:11,代碼來源:test_ndimage.py

示例3: test_sobel02

# 需要導入模塊: from scipy import ndimage [as 別名]
# 或者: from scipy.ndimage import sobel [as 別名]
def test_sobel02(self):
        for type in self.types:
            array = numpy.array([[3, 2, 5, 1, 4],
                                    [5, 8, 3, 7, 1],
                                    [5, 6, 9, 3, 5]], type)
            t = ndimage.correlate1d(array, [-1.0, 0.0, 1.0], 0)
            t = ndimage.correlate1d(t, [1.0, 2.0, 1.0], 1)
            output = numpy.zeros(array.shape, type)
            ndimage.sobel(array, 0, output)
            assert_array_almost_equal(t, output) 
開發者ID:ktraunmueller,項目名稱:Computable,代碼行數:12,代碼來源:test_ndimage.py

示例4: test_sobel03

# 需要導入模塊: from scipy import ndimage [as 別名]
# 或者: from scipy.ndimage import sobel [as 別名]
def test_sobel03(self):
        for type in self.types:
            array = numpy.array([[3, 2, 5, 1, 4],
                                    [5, 8, 3, 7, 1],
                                    [5, 6, 9, 3, 5]], type)
            t = ndimage.correlate1d(array, [-1.0, 0.0, 1.0], 1)
            t = ndimage.correlate1d(t, [1.0, 2.0, 1.0], 0)
            output = numpy.zeros(array.shape, type)
            output = ndimage.sobel(array, 1)
            assert_array_almost_equal(t, output) 
開發者ID:ktraunmueller,項目名稱:Computable,代碼行數:12,代碼來源:test_ndimage.py

示例5: test_sobel04

# 需要導入模塊: from scipy import ndimage [as 別名]
# 或者: from scipy.ndimage import sobel [as 別名]
def test_sobel04(self):
        for type in self.types:
            array = numpy.array([[3, 2, 5, 1, 4],
                                    [5, 8, 3, 7, 1],
                                    [5, 6, 9, 3, 5]], type)
            t = ndimage.sobel(array, -1)
            output = ndimage.sobel(array, 1)
            assert_array_almost_equal(t, output) 
開發者ID:ktraunmueller,項目名稱:Computable,代碼行數:10,代碼來源:test_ndimage.py

示例6: test_sobel01

# 需要導入模塊: from scipy import ndimage [as 別名]
# 或者: from scipy.ndimage import sobel [as 別名]
def test_sobel01(self):
        for type_ in self.types:
            array = numpy.array([[3, 2, 5, 1, 4],
                                 [5, 8, 3, 7, 1],
                                 [5, 6, 9, 3, 5]], type_)
            t = ndimage.correlate1d(array, [-1.0, 0.0, 1.0], 0)
            t = ndimage.correlate1d(t, [1.0, 2.0, 1.0], 1)
            output = ndimage.sobel(array, 0)
            assert_array_almost_equal(t, output) 
開發者ID:Relph1119,項目名稱:GraphicDesignPatternByPython,代碼行數:11,代碼來源:test_ndimage.py

示例7: test_sobel02

# 需要導入模塊: from scipy import ndimage [as 別名]
# 或者: from scipy.ndimage import sobel [as 別名]
def test_sobel02(self):
        for type_ in self.types:
            array = numpy.array([[3, 2, 5, 1, 4],
                                 [5, 8, 3, 7, 1],
                                 [5, 6, 9, 3, 5]], type_)
            t = ndimage.correlate1d(array, [-1.0, 0.0, 1.0], 0)
            t = ndimage.correlate1d(t, [1.0, 2.0, 1.0], 1)
            output = numpy.zeros(array.shape, type_)
            ndimage.sobel(array, 0, output)
            assert_array_almost_equal(t, output) 
開發者ID:Relph1119,項目名稱:GraphicDesignPatternByPython,代碼行數:12,代碼來源:test_ndimage.py

示例8: test_sobel03

# 需要導入模塊: from scipy import ndimage [as 別名]
# 或者: from scipy.ndimage import sobel [as 別名]
def test_sobel03(self):
        for type_ in self.types:
            array = numpy.array([[3, 2, 5, 1, 4],
                                 [5, 8, 3, 7, 1],
                                 [5, 6, 9, 3, 5]], type_)
            t = ndimage.correlate1d(array, [-1.0, 0.0, 1.0], 1)
            t = ndimage.correlate1d(t, [1.0, 2.0, 1.0], 0)
            output = numpy.zeros(array.shape, type_)
            output = ndimage.sobel(array, 1)
            assert_array_almost_equal(t, output) 
開發者ID:Relph1119,項目名稱:GraphicDesignPatternByPython,代碼行數:12,代碼來源:test_ndimage.py

示例9: test_sobel04

# 需要導入模塊: from scipy import ndimage [as 別名]
# 或者: from scipy.ndimage import sobel [as 別名]
def test_sobel04(self):
        for type_ in self.types:
            array = numpy.array([[3, 2, 5, 1, 4],
                                 [5, 8, 3, 7, 1],
                                 [5, 6, 9, 3, 5]], type_)
            t = ndimage.sobel(array, -1)
            output = ndimage.sobel(array, 1)
            assert_array_almost_equal(t, output) 
開發者ID:Relph1119,項目名稱:GraphicDesignPatternByPython,代碼行數:10,代碼來源:test_ndimage.py

示例10: test_multiple_modes

# 需要導入模塊: from scipy import ndimage [as 別名]
# 或者: from scipy.ndimage import sobel [as 別名]
def test_multiple_modes():
    # Test that the filters with multiple mode cababilities for different
    # dimensions give the same result as applying a single mode.
    arr = np.array([[1., 0., 0.],
                    [1., 1., 0.],
                    [0., 0., 0.]])

    mode1 = 'reflect'
    mode2 = ['reflect', 'reflect']

    assert_equal(sndi.gaussian_filter(arr, 1, mode=mode1),
                 sndi.gaussian_filter(arr, 1, mode=mode2))
    assert_equal(sndi.prewitt(arr, mode=mode1),
                 sndi.prewitt(arr, mode=mode2))
    assert_equal(sndi.sobel(arr, mode=mode1),
                 sndi.sobel(arr, mode=mode2))
    assert_equal(sndi.laplace(arr, mode=mode1),
                 sndi.laplace(arr, mode=mode2))
    assert_equal(sndi.gaussian_laplace(arr, 1, mode=mode1),
                 sndi.gaussian_laplace(arr, 1, mode=mode2))
    assert_equal(sndi.maximum_filter(arr, size=5, mode=mode1),
                 sndi.maximum_filter(arr, size=5, mode=mode2))
    assert_equal(sndi.minimum_filter(arr, size=5, mode=mode1),
                 sndi.minimum_filter(arr, size=5, mode=mode2))
    assert_equal(sndi.gaussian_gradient_magnitude(arr, 1, mode=mode1),
                 sndi.gaussian_gradient_magnitude(arr, 1, mode=mode2))
    assert_equal(sndi.uniform_filter(arr, 5, mode=mode1),
                 sndi.uniform_filter(arr, 5, mode=mode2)) 
開發者ID:Relph1119,項目名稱:GraphicDesignPatternByPython,代碼行數:30,代碼來源:test_filters.py

示例11: overlay_edges

# 需要導入模塊: from scipy import ndimage [as 別名]
# 或者: from scipy.ndimage import sobel [as 別名]
def overlay_edges(slice_one, slice_two, sharper=True):
    """
    Makes a composite image with edges from second image overlaid on first.

    It will be in colormapped (RGB format) already.
    """

    if slice_one.shape != slice_two.shape:
        raise ValueError("slices' dimensions do not match: "
                         " {} and {} ".format(slice_one.shape, slice_two.shape))

    # simple filtering to remove noise, while supposedly keeping edges
    slice_two = medfilt2d(slice_two, kernel_size=cfg.median_filter_size)
    # extracting edges
    edges = np.hypot(sobel(slice_two, axis=0, mode='constant'),
                     sobel(slice_two, axis=1, mode='constant'))

    # trying to remove weak edges
    if not sharper: # level of removal
        edges = med_filter(max_filter(min_filter(edges)))
    else:
        edges = min_filter(min_filter(max_filter(min_filter(edges))))
    edges_color_mapped = hot_cmap(edges, alpha=cfg.alpha_edge_overlay_alignment)
    composite = gray_cmap(slice_one, alpha=cfg.alpha_background_slice_alignment)

    composite[edges_color_mapped>0] = edges_color_mapped[edges_color_mapped>0]

    # mask_rgba = np.dstack([edges>0] * 4)
    # composite[mask_rgba] = edges_color_mapped[mask_rgba]

    return composite 
開發者ID:raamana,項目名稱:visualqc,代碼行數:33,代碼來源:image_utils.py

示例12: dwi_overlay_edges

# 需要導入模塊: from scipy import ndimage [as 別名]
# 或者: from scipy.ndimage import sobel [as 別名]
def dwi_overlay_edges(slice_one, slice_two):
    """
    Makes a composite image with edges from second image overlaid on first.

    It will be in colormapped (RGB format) already.
    """

    if slice_one.shape != slice_two.shape:
        raise ValueError("slices' dimensions do not match: "
                         " {} and {} ".format(slice_one.shape, slice_two.shape))

    # simple filtering to remove noise, while supposedly keeping edges
    slice_two = medfilt2d(slice_two, kernel_size=cfg.median_filter_size)
    # extracting edges
    edges = med_filter(np.hypot(sobel(slice_two, axis=0, mode='constant'),
                                sobel(slice_two, axis=1, mode='constant')))

    edges_color_mapped = hot_cmap(edges, alpha=cfg.alpha_edge_overlay_alignment)
    composite = gray_cmap(slice_one, alpha=cfg.alpha_background_slice_alignment)

    composite[edges_color_mapped>0] = edges_color_mapped[edges_color_mapped>0]

    # mask_rgba = np.dstack([edges>0] * 4)
    # composite[mask_rgba] = edges_color_mapped[mask_rgba]

    return composite 
開發者ID:raamana,項目名稱:visualqc,代碼行數:28,代碼來源:image_utils.py

示例13: filter

# 需要導入模塊: from scipy import ndimage [as 別名]
# 或者: from scipy.ndimage import sobel [as 別名]
def filter(self, array, *args, **kwargs):
        shp = array.shape
        array = array.reshape((np.prod(shp[0:-2]),) + shp[-2:])  # reshape to (nch, ny, nx)

        for k, arr in enumerate(np.abs(array)):  # loop over channels
            dx = ndimage.sobel(arr, 0)  # horizontal derivative
            dy = ndimage.sobel(arr, 1)  # vertical derivative
            array[k, ...] = np.hypot(dx, dy)  # magnitude

        array = array.reshape(shp)  # back to original shape
        return array 
開發者ID:birgander2,項目名稱:PyRAT,代碼行數:13,代碼來源:Edgedetect.py

示例14: sobel

# 需要導入模塊: from scipy import ndimage [as 別名]
# 或者: from scipy.ndimage import sobel [as 別名]
def sobel(*args, **kwargs):
    return Sobel(*args, **kwargs).run(**kwargs) 
開發者ID:birgander2,項目名稱:PyRAT,代碼行數:4,代碼來源:Edgedetect.py

示例15: _init_coords

# 需要導入模塊: from scipy import ndimage [as 別名]
# 或者: from scipy.ndimage import sobel [as 別名]
def _init_coords(self):
    logging.info('peaks: starting')

    # Edge detection.
    edges = ndimage.generic_gradient_magnitude(
        self.canvas.image.astype(np.float32),
        ndimage.sobel)

    # Adaptive thresholding.
    sigma = 49.0 / 6.0
    thresh_image = np.zeros(edges.shape, dtype=np.float32)
    ndimage.gaussian_filter(edges, sigma, output=thresh_image, mode='reflect')
    filt_edges = edges > thresh_image

    del edges, thresh_image

    # This prevents a border effect where the large amount of masked area
    # screws up the distance transform below.
    if (self.canvas.restrictor is not None and
        self.canvas.restrictor.mask is not None):
      filt_edges[self.canvas.restrictor.mask] = 1

    logging.info('peaks: filtering done')
    dt = ndimage.distance_transform_edt(1 - filt_edges).astype(np.float32)
    logging.info('peaks: edt done')

    # Use a specifc seed for the noise so that results are reproducible
    # regardless of what happens before the policy is called.
    state = np.random.get_state()
    np.random.seed(42)
    idxs = skimage.feature.peak_local_max(
        dt + np.random.random(dt.shape) * 1e-4,
        indices=True, min_distance=3, threshold_abs=0, threshold_rel=0)
    np.random.set_state(state)

    # After skimage upgrade to 0.13.0 peak_local_max returns peaks in
    # descending order, versus ascending order previously.  Sort ascending to
    # maintain historic behavior.
    idxs = np.array(sorted((z, y, x) for z, y, x in idxs))

    logging.info('peaks: found %d local maxima', idxs.shape[0])
    self.coords = idxs 
開發者ID:google,項目名稱:ffn,代碼行數:44,代碼來源:seed.py


注:本文中的scipy.ndimage.sobel方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。