我有一個尺寸爲(227,227,3)的RGB圖像和一個尺寸爲(227,227)的灰度圖像。現在我想用灰度圖像替換圖像的RGB平面。下面我有代碼。現在,代碼問題是imgNew
即使我沒有改變它的價值和imgR,imgG,imgB
錯誤圖像越來越重寫。python代碼問題,爲什麼變量被覆蓋?
#this is my rgb image
imgNew = imresize(img[480/2 - 160 + r[l, 0]:480/2 + 160 + r[l, 0], 640/2 - 160 + r[m, 1]:640/2 + 160 + r[m, 1], :],(227,227))
# this is grascale
imgDNew = imresize(imgx[480/2 - 160 + r[l, 0]:480/2 + 160 + r[l, 0], 640/2 - 160 + r[m, 1]:640/2 + 160 + r[m, 1]],(227,227))
# if I plot the images here both are fine.
# Now replacing the planes one by one.
imgR[:,:,0] = imgDNew
imgR[:,:,1] = imgNew[:,:,1]
imgR[:,:,2] = imgNew[:,:,2]
imgG[:,:,1] = imgDNew
imgG[:,:,2] = imgNew[:,:,2]
imgG[:,:,0] = imgNew[:,:,0]
imgB = imgNew
imgB[:,:,2] = imgDNew
imgB[:,:,0] = imgNew[:,:,0]
imgB[:,:,1] = imgNew[:,:,1]
#Now if I plot the images my original image is changed (imgNew) and imgR,imgG,imgB images are wrong.
我不明白什麼是錯?
http://stackoverflow.com/questions/2612802/how-to-clone-or-copy-a-list –