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.