Reputation: 37
I am trying to replace pixels less than value 50 in one image (src1) with pixels from another image (src2). The code i am trying is as below. The problem is it is taking lot of time. Can anyone guide me in using optimized way to do this
src1 = cv2.imread('')
src2 = cv2.imread('')
rows, cols, ch = src1.shape
result = src1.copy()
for i in (xrange(rows)):
for j in (xrange(cols)):
k = src1[i,j]
if (k.all() < 50):
result[i,j] = src2[i,j]
cv2.imwrite('',result)
Upvotes: 2
Views: 1714
Reputation: 826
You can use numpy for this.
src1 = cv2.imread('')
src2 = cv2.imread('')
r,c = np.where(src1<50)
src1[(r,c)] = src2[(r,c)]
Upvotes: 5