用numpy求2×2块平均,详细的过程参见链接:https://www.cnblogs.com/rrttp/p/8028421.html

博主给一份简介的代码:

    bayer = np.array([[1,2,3,4],[5,7,8,6]])
    sz = np.shape(bayer)
    b = bayer.reshape(sz[0]//2,2,sz[1]//2,2)
    a = b.mean(axis=(1,3))

附录:

2×2块平均求法分解

In [340]: x
Out[340]: 
array([[  0.,   1.,   2.,   3.,   4.,   5.],
       [  6.,   7.,   8.,   9.,  10.,  11.],
       [ 12.,  13.,  14.,  15.,  16.,  17.],
       [ 18.,  19.,  20.,  21.,  22.,  23.]])

In [341]: y = x.reshape(2,2,3,2)

In [342]: y[0,:,0,:]
Out[342]: 
array([[ 0.,  1.],
       [ 6.,  7.]])

In [343]: y[1,:,2,:]
Out[343]: 
array([[ 16.,  17.],
       [ 22.,  23.]])

In [344]: y.mean(axis=(1,3))
Out[344]: 
array([[  3.5,   5.5,   7.5],
       [ 15.5,  17.5,  19.5]])

 

 

 

发表评论

邮箱地址不会被公开。 必填项已用*标注