如何使用rasterio将栅格图像总结在一起?
我有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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论