Python:如何将图像分成块。然后加入原始图像

时间:2019-06-14 08:38:31

标签: python image numpy-ndarray

我需要将768 x 1024图像分成16 x 16块。然后,我需要将它们加入原始图像中。我尝试了很多方法,但无法获得原始图像。

我使用这种方法将测试图像(大小= 768 x 1024)分割为16 x 16块,并保存到块列表中。但是如何将它们融入原始图像中呢?

block = []
for x in range(0, test.shape[0],16):
    for y in range(0, test.shape[1],16):
        block.append(test[x:x+16, y:y+16])

1 个答案:

答案 0 :(得分:0)

请尝试一下

test = test.reshape((-1,16,16,3)) #breaking image into 3072 16x16 blocks
test = test.reshape((1024,768,3)) #rejoining 3072 blocks into 1 image