• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python features.sieve函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中rasterio.features.sieve函数的典型用法代码示例。如果您正苦于以下问题:Python sieve函数的具体用法?Python sieve怎么用?Python sieve使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了sieve函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: test_sieve_mask

def test_sieve_mask():
    """Test proper behavior of mask image, if passed int sieve"""

    with rasterio.drivers():
        shape = (20, 20)
        image = numpy.zeros(shape, dtype=rasterio.ubyte)
        image[5:15, 5:15] = 1
        image[1:3, 1:3] = 2

        # Blank mask has no effect, only areas smaller than size will be
        # removed
        mask = numpy.ones(shape, dtype=rasterio.bool_)
        sieved_image = ftrz.sieve(image, 100, mask=mask)
        truth = numpy.zeros_like(image)
        truth[5:15, 5:15] = 1
        assert numpy.array_equal(sieved_image, truth)

        # Only areas within the overlap of the mask and values will be kept
        mask = numpy.ones(shape, dtype=rasterio.bool_)
        mask[7:10, 7:10] = False
        sieved_image = ftrz.sieve(image, 100, mask=mask)
        truth = numpy.zeros_like(image)
        truth[7:10, 7:10] = 1
        assert numpy.array_equal(sieved_image, truth)

        # mask of other type than rasterio.bool_ should fail
        mask = numpy.zeros(shape, dtype=rasterio.uint8)
        with pytest.raises(ValueError):
            ftrz.sieve(image, 100, mask=mask)
开发者ID:simudream,项目名称:rasterio,代码行数:29,代码来源:test_features_sieve.py


示例2: test_sieve_invalid_mask_dtype

def test_sieve_invalid_mask_dtype(basic_image):
    """A mask that is the wrong dtype should fail."""
    for dtype in ('int8', 'int16', 'int32'):
        with pytest.raises(ValueError):
            sieve(
                basic_image, basic_image.sum(),
                mask=np.ones(basic_image.shape, dtype=dtype)
            )
开发者ID:brendan-ward,项目名称:rasterio,代码行数:8,代码来源:test_features.py


示例3: test_sieve_invalid_mask_shape

def test_sieve_invalid_mask_shape(basic_image):
    """A mask that is the wrong shape should fail."""
    with pytest.raises(ValueError):
        sieve(
            basic_image, basic_image.sum(),
            mask=np.ones(
                (basic_image.shape[0] + 10, basic_image.shape[1] + 10),
                dtype=rasterio.bool_
            )
        )
开发者ID:brendan-ward,项目名称:rasterio,代码行数:10,代码来源:test_features.py


示例4: test_sieve_band

def test_sieve_band(pixelated_image, pixelated_image_file):
    """Sieving a band from a raster file should match sieve of array."""

    truth = sieve(pixelated_image, 9)

    with rasterio.open(pixelated_image_file) as src:
        band = rasterio.band(src, 1)
        assert np.array_equal(truth, sieve(band, 9))

        # Mask band should also work but will be a no-op
        assert np.array_equal(
            pixelated_image,
            sieve(band, 9, mask=band)
        )
开发者ID:brendan-ward,项目名称:rasterio,代码行数:14,代码来源:test_features.py


示例5: test_sieve_out

def test_sieve_out(basic_image):
    """Output array passed in should match the returned array."""
    output = np.zeros_like(basic_image)
    output[1:3, 1:3] = 5
    sieved_image = sieve(basic_image, basic_image.sum(), out=output)
    assert np.array_equal(basic_image, sieved_image)
    assert np.array_equal(output, sieved_image)
开发者ID:brendan-ward,项目名称:rasterio,代码行数:7,代码来源:test_features.py


示例6: test_sieve_large

def test_sieve_large(basic_image):
    """
    Setting the size larger than size of feature should leave us an empty image.
    """

    with rasterio.drivers():
        assert not numpy.any(sieve(basic_image, basic_image.sum() + 1))
开发者ID:aashish24,项目名称:rasterio,代码行数:7,代码来源:test_features.py


示例7: test_sieve_blank_mask

def test_sieve_blank_mask(basic_image):
    """A blank mask should have no effect."""
    mask = np.ones(basic_image.shape, dtype=rasterio.bool_)
    assert np.array_equal(
        basic_image,
        sieve(basic_image, basic_image.sum(), mask=mask)
    )
开发者ID:brendan-ward,项目名称:rasterio,代码行数:7,代码来源:test_features.py


示例8: test_sieve

def test_sieve():
    """Test sieving a 10x10 feature from an ndarray."""

    image = numpy.zeros((20, 20), dtype=rasterio.ubyte)
    image[5:15, 5:15] = 1

    # An attempt to sieve out features smaller than 100 should not change the
    # image.
    with rasterio.drivers():
        sieved_image = ftrz.sieve(image, 100)
        assert numpy.array_equal(sieved_image, image)

    # Setting the size to 100 should leave us an empty, False image.
    with rasterio.drivers():
        sieved_image = ftrz.sieve(image, 101)
        assert not sieved_image.any()
开发者ID:simudream,项目名称:rasterio,代码行数:16,代码来源:test_features_sieve.py


示例9: test_sieve_large

def test_sieve_large(basic_image):
    """
    Setting the size larger than size of feature should leave us an empty image.
    """

    with Env():
        assert not np.any(sieve(basic_image, basic_image.sum() + 1))
开发者ID:EricAlex,项目名称:rasterio,代码行数:7,代码来源:test_features.py


示例10: test_sieve_connectivity_queen

def test_sieve_connectivity_queen(diagonal_image):
    """ Diagonals are connected, so feature is retained """

    assert np.array_equal(
        diagonal_image,
        sieve(diagonal_image, diagonal_image.sum(), connectivity=8)
    )
开发者ID:EricAlex,项目名称:rasterio,代码行数:7,代码来源:test_features.py


示例11: test_sieve_invalid_out

def test_sieve_invalid_out(basic_image):
    """Output with different dtype or shape should fail."""
    with pytest.raises(ValueError):
        sieve(
            basic_image, basic_image.sum(),
            out=np.zeros(basic_image.shape, dtype=rasterio.int32)
        )

    with pytest.raises(ValueError):
        sieve(
            basic_image, basic_image.sum(),
            out=np.zeros(
                (basic_image.shape[0] + 10, basic_image.shape[1] + 10),
                dtype=rasterio.ubyte
            )
        )
开发者ID:brendan-ward,项目名称:rasterio,代码行数:16,代码来源:test_features.py


示例12: test_sieve_internal_driver_manager

def test_sieve_internal_driver_manager(basic_image, pixelated_image):
    """ Sieve should work without explicitly calling driver manager """

    assert np.array_equal(
        basic_image,
        sieve(pixelated_image, basic_image.sum())
    )
开发者ID:EricAlex,项目名称:rasterio,代码行数:7,代码来源:test_features.py


示例13: test_sieve_unsupported_dtypes

def test_sieve_unsupported_dtypes(basic_image):
    """Unsupported data types should raise exceptions."""
    unsupported_types = (
        ('int8', -127),
        ('uint32', 4294967295),
        ('int64', 20439845334323),
        ('float16', -9343.232),
        ('float32', 1.434532),
        ('float64', -98332.133422114)
    )

    for dtype, test_value in unsupported_types:
        with pytest.raises(ValueError):
            sieve(
                (basic_image).astype(dtype) * test_value,
                basic_image.sum()
            )
开发者ID:brendan-ward,项目名称:rasterio,代码行数:17,代码来源:test_features.py


示例14: test_sieve_connectivity

def test_sieve_connectivity():
    """Test proper behavior of connectivity"""

    image = numpy.zeros((20, 20), dtype=rasterio.ubyte)
    image[5:15:2, 5:15] = 1
    image[6, 4] = 1
    image[8, 15] = 1
    image[10, 4] = 1
    image[12, 15] = 1

    # Diagonals not connected, all become small features that will be removed
    sieved_image = ftrz.sieve(image, 54, connectivity=4)
    assert not sieved_image.any()

    # Diagonals connected, everything is retained
    sieved_image = ftrz.sieve(image, 54, connectivity=8)
    assert numpy.array_equal(sieved_image, image)
开发者ID:simudream,项目名称:rasterio,代码行数:17,代码来源:test_features_sieve.py


示例15: test_sieve

def test_sieve():
    """Test sieving a 10x10 feature from an ndarray."""
    image = numpy.zeros((20, 20), dtype=rasterio.ubyte)
    image[5:15,5:15] = 127
    # There should be some True pixels.
    assert image.any()
    # An attempt to sieve out features smaller than 100 should not change the
    # image.
    with rasterio.drivers():
        sieved_image = ftrz.sieve(image, 100)
        assert (
            list(map(list, numpy.where(sieved_image==127))) == 
            list(map(list, numpy.where(image==127))))
    # Setting the size to 100 should leave us an empty, False image.
    with rasterio.drivers():
        sieved_image = ftrz.sieve(image, 101)
        assert not sieved_image.any()
开发者ID:AsgerPetersen,项目名称:rasterio,代码行数:17,代码来源:test_features_sieve.py


示例16: test_sieve_out

def test_sieve_out(basic_image):
    """ Output array passed in should match the returned array """

    with rasterio.drivers():
        output = numpy.zeros_like(basic_image)
        output[1:3, 1:3] = 5
        sieved_image = sieve(basic_image, basic_image.sum(), out=output)
        assert numpy.array_equal(basic_image, sieved_image)
        assert numpy.array_equal(output, sieved_image)
开发者ID:aashish24,项目名称:rasterio,代码行数:9,代码来源:test_features.py


示例17: test_sieve_blank_mask

def test_sieve_blank_mask(basic_image):
    """ A blank mask should have no effect """

    mask = numpy.ones(basic_image.shape, dtype=rasterio.bool_)
    with rasterio.drivers():
        assert numpy.array_equal(
            basic_image,
            sieve(basic_image, basic_image.sum(), mask=mask)
        )
开发者ID:aashish24,项目名称:rasterio,代码行数:9,代码来源:test_features.py


示例18: test_sieve_output

def test_sieve_output():
    """Test proper behavior of output image, if passed into sieve"""

    with rasterio.drivers():
        shape = (20, 20)
        image = numpy.zeros(shape, dtype=rasterio.ubyte)
        image[5:15, 5:15] = 1

        # Output should match returned array
        output = numpy.zeros_like(image)
        output[1:3, 1:3] = 5
        sieved_image = ftrz.sieve(image, 100, output=output)
        assert numpy.array_equal(output, sieved_image)

        # Output of different dtype should fail
        output = numpy.zeros(shape, dtype=rasterio.int32)
        with pytest.raises(ValueError):
            ftrz.sieve(image, 100, output)
开发者ID:simudream,项目名称:rasterio,代码行数:18,代码来源:test_features_sieve.py


示例19: test_sieve_small

def test_sieve_small(basic_image, pixelated_image):
    """
    Setting the size smaller than or equal to the size of the feature in the
    image should not change the image.
    """
    assert np.array_equal(
        basic_image,
        sieve(pixelated_image, basic_image.sum())
    )
开发者ID:brendan-ward,项目名称:rasterio,代码行数:9,代码来源:test_features.py


示例20: test_sieve_small

def test_sieve_small(basic_image, pixelated_image):
    """
    Setting the size smaller than or equal to the size of the feature in the
    image should not change the image.
    """

    with rasterio.drivers():
        assert numpy.array_equal(
            basic_image,
            sieve(pixelated_image, basic_image.sum())
        )
开发者ID:aashish24,项目名称:rasterio,代码行数:11,代码来源:test_features.py



注:本文中的rasterio.features.sieve函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python transform.guard_transform函数代码示例发布时间:2022-05-26
下一篇:
Python features.shapes函数代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap