Opencv Or Numpy-- Replace A List Of Pixels In An Image, Efficiently
Hi OpenCV or Numpy Gurus, I've been searching to an answer to this, but I'm surprised to not find it here or elsewhere... I have a black image, and I want to replace a list of pix
Solution 1:
In fact, you can directly use your tuple of coordinates to index your matrix: a simple a[([2, 3], [3, 4])] = 20
gives the exact same result as your for loop here.
Solution 2:
Thanks Paul Panzer and RomualdM...
This seems to do what I want, based on their comments...
coords_list = ([3,5],[55,60],[25,90])
black_image =np.zeros((480,640,3))
I,J = np.transpose(coords_list)
black_image[I,J] = [255,255,255]
cv2.imshow('black_image', black_image)
while (1):
k = cv2.waitKey(0) #press esc to killif (k == 27):
break
cv2.destroyAllWindows()
Post a Comment for "Opencv Or Numpy-- Replace A List Of Pixels In An Image, Efficiently"