当前位置: 首页>>代码示例>>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;未经允许,请勿转载。