title: Extract pixel coordinates and paste on new image python
body: <p><a href="https://i.stack.imgur.com/oOHc6.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/oOHc6.png" alt="Image"></a></p>
  
  <p>This code is <strong>returning pixels coordinates</strong> which have <strong>red color</strong> now i want to extract and paste those pixels on new image. how do i paste pixel coordinates? Please ask if question is not clear.</p>
  
  <pre><code>import cv2
  import numpy as np
  filename = "oOHc6.png"
  img = cv2.imread(filename, 1)
  hsv=cv2.cvtColor(img, cv2.COLOR_BGR2HSV)
  hsv_lower=np.uint8([0, 200, 210])
  hsv_upper=np.uint8([180, 250, 250])
  mask= cv2.inRange(hsv, hsv_lower, hsv_upper)
  
  #display mask
  res = cv2.bitwise_and(img,img,mask = mask)
  res_gray = cv2.cvtColor(res, cv2.COLOR_BGR2GRAY)
  ys,xs = np.where(res_gray&gt;0)
  pts = [(x,y) for x,y in zip(xs,ys)]
  
  empty = np.zeros_like(img)
  mask_c = cv2.cvtColor(mask, cv2.COLOR_GRAY2BGR)
  imaskc = mask_c&gt;0
  
  empty[imaskc] = img[imaskc]
  #empty.save('C:/Python27/cclabel/images/NewImage'+'.png','png')
  cv2.imwrite("new.png", empty)
  </code></pre>