0

我有一个矩阵,我只是想将它分割成相等大小的补丁,同时还保留每个补丁的坐标系(从它们在数据文件中的原始位置开始)。我需要能够对它们进行分段,然后在每个段上索引仍然与原始全局坐标系(不是新创建的坐标系)相关的点:

from pylab import imshow, show
import numpy as np

image = np.random.randint(2, size=(70, 70))

lenX = int(70)
lenY = int(70)

def extract_blocks(a, blocksize):
    M,N = a.shape
    b0, b1 = blocksize
    return a.reshape(M//b0,b0,N//b1,b1).swapaxes(1,2).reshape(-1,b0,b1)

#imshow(extract_blocks(image, (int(lenX/2),int(lenY/2)))[0]) #these coordinates are correct
imshow(extract_blocks(image, (int(lenX/2),int(lenY/2)))[1]) #these coords should be x+35
    #...but instead are the same as above
#imshow(extract_blocks(image, (int(lenX/2),int(lenY/2)))[2]) #etc.
#imshow(extract_blocks(image, (int(lenX/2),int(lenY/2)))[3]) #etc.

show()

非常感谢任何帮助。

4

0 回答 0