将24x24图像复制到28x28的零阵列中

时间:2015-06-04 12:07:06

标签: python opencv numpy

您好我想要复制28x28矩阵的随机部分,然后使用生成的24x24矩阵插入28x28矩阵         image = image.reshape(28,28)

    getx = random.randint(0,4)
    gety = random.randint(0,4)

    # get a 24 x 24 tile from a random location in img
    blank_image = np.zeros((28,28), np.uint8)

    tile= image[gety:gety+24,getx:getx+24]
    cv2.imshow("the 24x24 Image",tile)

tile是24x24 ROI按计划工作

    blank_image[gety:gety+24,getx:getx+24] = tile
我的示例中的

blank_image没有使用tile

中的值进行更新

感谢您的帮助

1 个答案:

答案 0 :(得分:0)

如果您收到错误,可能是因为您的np数组维度不同。如果您的图像是RGB图像,则空白图像应定义为:

blank_image = np.zeros((28,28,3), uint8)