使用numpy逐像素计算栅格的像素均值 [英] calculate pixel by pixel mean of the rasters using numpy
本文介绍了使用numpy逐像素计算栅格的像素均值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
由于两个栅格(raster1和raster2)彼此重叠,因此我想通过计算每个重叠像素的均值来制作新的栅格;即,生成的新栅格的计算公式为:
Since the two rasters (raster1 and raster2) overlap each other, I want to make new raster by calculating mean of each overlapped pixels; i.e., The resulting new raster is calculated as:
new = [[mean(1,3), mean(1,3), mean(1,3), mean(1,3), mean(1,3)],[mean(2,4),mean(2,4),mean(2,4),mean(2,4),mean(2,4)]]
import numpy as np
raster1 = np.array([[1,1,1,1,1],[2,2,2,2,2]])
raster2 = np.array([[3,3,3,3,3],[4,4,4,4,4]])
new = np.mean(raster1,raster2,axis=1)
print (new.tolist())
怎么了?
推荐答案
也许我误解了你,但是你想要吗?
Maybe I misunderstood you but do you want?
raster = (raster1 + raster2) / 2
实际上,在这种情况下,您甚至不需要np.mean
,只需使用矩阵运算即可.
Actually in this case you don't even need np.mean
, just use matrix operations.
np.mean
用于处理特定轴上单个矩阵的计算平均值,因此情况有所不同.
np.mean
is used to deal with calculating mean for a single matrix on specific axis, so it is a different situation.
这篇关于使用numpy逐像素计算栅格的像素均值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文