Median combining fits images in python

喜欢而已 提交于 2019-12-03 12:54:32

The easiest way to do this is:

  • Stack the 2d arrays to form a 3d array
  • Compute the median using numpy.median passing axis=0 to compute along the dimension of stacking.

You're essentially computing an element-wise median. Here's a simple example of what I would do:

>>> import numpy
>>> a = numpy.array([[1,2,3],[4,5,6]])
>>> b = numpy.array([[3,4,5],[6,7,8]])
>>> c = numpy.array([[9,10,11],[12,1,2]])
>>> d = numpy.array([a,b,c])
>>> d
array([[[ 1,  2,  3],
        [ 4,  5,  6]],

       [[ 3,  4,  5],
        [ 6,  7,  8]],

       [[ 9, 10, 11],
        [12,  1,  2]]])
>>> d.shape
(3, 2, 3)

>>> numpy.median(d, axis=0)
array([[ 3.,  4.,  5.],
       [ 6.,  5.,  6.]])
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!