我有一个原始图像数据的2D数组,存储为RGGB。从每组4(2x2)个RGGB簇(16个传感器像素)中,我需要取出1个RGGB簇以形成新图像,总共4个图像,每个图像的分辨率为原始图像的1/4
例如,给定此二维阵列:
a = np.arange(1,65).reshape(8,8)
[[ 1 2 3 4 5 6 7 8]
[ 9 10 11 12 13 14 15 16]
[17 18 19 20 21 22 23 24]
[25 26 27 28 29 30 31 32]
[33 34 35 36 37 38 39 40]
[41 42 43 44 45 46 47 48]
[49 50 51 52 53 54 55 56]
[57 58 59 60 61 62 63 64]]
我需要提取这4个阵列:
[[ 1 2 5 6]
[ 9 10 13 14]
[33 34 37 38]
[41 42 45 46]]
[[ 3 4 7 8]
[11 12 15 16]
[35 36 39 40]
[43 44 47 48]]
[[17 18 21 22]
[25 26 29 30]
[49 50 53 54]
[57 58 61 62]]
[[19 20 23 24]
[27 28 31 32]
[51 52 55 56]
[59 60 63 64]]
我认为一定有一些聪明、高效的方法可以做到这一点,但我还没有想到任何使用内置切片器的方法
我开始将主阵列分成两个阵列,每个阵列由两个元素组成,我认为我可以以某种方式将它们重新组合在一起,但我被卡住了
sliced = a.reshape(-1,2)[::2]
sliced2 = a.reshape(-1,2)[1::2]
你走的方向很好
现在再次重塑
然后再切片
最后去塑造
4x4
完整工作代码
结果:
相关问题 更多 >
编程相关推荐