如何使用rasterio将栅格图像总结在一起?

发布于 2025-02-04 13:25:24 字数 1297 浏览 4 评论 0原文

我有100多个栅格图像,其程度完全相同。它们由0或1的值组成。我想拥有1个单个图像,其中该像素的所有值汇总在一起。

我已经以某种方式完成了此操作,但是它在水和陆触摸的地方产生了不必要的/无法解释的边缘。除了水更明亮,但尤其是触摸水的块的大小使我感到困惑。可以以不同的方式解决或做到这一点,以免发生这种情况吗?

我的代码:

def Summing(images_to_sum):
    """
    Creates one image out of all images in given list.
    """
    path_out = r"C:\Documents\UFV.jp2"
    images_used = 2

    def Summ(path_1, path_2):
        """
        Sums up the two images from given paths.
        """
        with rio.open(path_1) as src_1:
            array_1 = src_1.read()
            profile = src_1.profile

            with rio.open(path_2) as src_2:
                array_2 = src_2.read()

                # Sum the two
                result = array_1 + array_2

        with rio.open(path_out, 'w', **profile) as dst:
            dst.write(result)

    # Creating first image, so others can be added
    Summ(images_to_sum[0], images_to_sum[1])
    images_to_sum.pop(0)
    images_to_sum.pop(0)

    # Adding all the other images for this granule
    for image in images_to_sum:
        Summ(path_out, image)
        images_used += 1

这是结果的一部分。如您所见,土地边缘有一些大块。

I have 100+ raster images with the exact same extent. They consist of values which are either 0 or 1. I would like to have 1 single image with all values for that pixel summed together.

I have done it in a certain way, but it creates unwanted/unexplainable edges at the places where water and land touch. I except water to be somewhat brighter but especially the size of the blocks touching the water confuses me. Can this be solved or be done in a different way so this doesn't happen?

My code:

def Summing(images_to_sum):
    """
    Creates one image out of all images in given list.
    """
    path_out = r"C:\Documents\UFV.jp2"
    images_used = 2

    def Summ(path_1, path_2):
        """
        Sums up the two images from given paths.
        """
        with rio.open(path_1) as src_1:
            array_1 = src_1.read()
            profile = src_1.profile

            with rio.open(path_2) as src_2:
                array_2 = src_2.read()

                # Sum the two
                result = array_1 + array_2

        with rio.open(path_out, 'w', **profile) as dst:
            dst.write(result)

    # Creating first image, so others can be added
    Summ(images_to_sum[0], images_to_sum[1])
    images_to_sum.pop(0)
    images_to_sum.pop(0)

    # Adding all the other images for this granule
    for image in images_to_sum:
        Summ(path_out, image)
        images_used += 1

This is a part of the result. As you can see there are some big blocks at the edges of the land.
enter image description here

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文