将图像的numpy数组转换为块

时间:2018-02-21 02:33:50

标签: python numpy

我有一个numpy数组的图像。我想用python将这个图像转换成8 * 8块。我该怎么做?

2 个答案:

答案 0 :(得分:1)

请提供您的阵列结构。

你可以使用img_arrary.reshape(8,8),工作总元素必须是64

答案 1 :(得分:0)

重塑,然后交换:

async function main() {
    for (x = 0; x < 5; x++) {
        console.log('start of my script');
        let tab = await chromeTabsCreateAsync({ url: "about:blank", active: false });
        console.log('Tab created: ' + tab.id);
        console.log('end of my script');
    }
}

检查结果:

import numpy as np

img = np.random.randint(0, 255, size=(128, 256, 3)).astype(np.uint8)

blocks = img.reshape(img.shape[0]//8, 8, img.shape[1]//8, 8, 3).swapaxes(1, 2)
print(blocks.shape)
相关问题