簡體   English   中英

使用numpy計算像素的像素均值

[英]calculate pixel by pixel mean of the rasters using numpy

由於兩個柵格(raster1和raster2)彼此重疊,因此我想通過計算每個重疊像素的均值來制作新的柵格。 即,生成的新柵格的計算公式為:

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())

怎么了?

也許我誤會了你,但是你想要嗎?

raster = (raster1 + raster2) / 2

實際上,在這種情況下,您甚至不需要np.mean ,只需使用矩陣運算即可。

np.mean用於處理特定軸上單個矩陣的均值計算,因此情況有所不同。

它應該是

new = np.mean([raster1,raster2],axis=1)

帶括號。 其實我猜應該是

new = np.mean([raster1,raster2],axis=0)

np.mean的第一個參數應該是整個數組,請參見例如http://wiki.scipy.org/Numpy_Example_List_With_Doc#mean

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM