2015-06-04 27 views
1

嗨我想複製一個28x28矩陣的隨機部分,然後使用生成的24x24矩陣插入到一個28x28矩陣 image = image.reshape(28,28)複製一個24x24圖像到一個28x28陣列的零

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) 

塊是24×24的ROI工作按計劃

blank_image[gety:gety+24,getx:getx+24] = tile 

blank_image在我的例子沒有得到與值來自片更新

感謝提前幫助

+0

[更新墊的子矩陣中的OpenCV]的可能重複(http://stackoverflow.com/questions/11664097/updating-一個-子矩陣-的-MAT-在-OpenCV的) –

回答

0

如果您收到錯誤,可能是因爲您的np陣列尺寸不同。如果圖像是RGB圖像,那麼你的空白圖像應該被定義爲:

blank_image = np.zeros((28,28,3), uint8) 
相關問題