0

I am doing a project where i need to find a red laser dot. After changing to HSV color space model and thresholding individual H,S,V components and merging it , i found a laser dot with several noise as well , now i need to subtract all other image components except for the laser dot and the noise with their respective color so that i can process those frame for further processing like template matching to get only the laser dot reducing the noises. Hope you understand the question and Thank You, any similar help is appreciated.

Pankaj
  • 25
  • 1
  • 1
  • 4
  • 1
    You still need to improve the clarity and readability of the question, Pankaj. (And do upper-case those 'i's) – Ébe Isaac Jun 10 '17 at 11:27
  • originalImage.copyTo(newImage, 255-thresholdedImage); This will copy all your thresholded parts to a new image. – Micka Jun 10 '17 at 11:45
  • 1
    @Micka the question is tagged `python-2.7` --- so probably the easiest way using built-in functions would be `masked_src = cv2.bitwise_and(src, src, mask=mask)` – alkasm Jun 11 '17 at 00:21

1 Answers1

0

What you're looking to do is apply a mask to an image. A mask is an image where any positive non-zero value acts as an indicator. What you want to do is use the mask to indicate which pixels in the original image you want.

The easiest way to apply a mask is to use the cv2.bitwise_and() function, with your thresholded image as the mask:

masked_img = cv2.bitwise_and(img, img, mask=thresholded_img)

As an example, if this is my image and this is my mask, then this would be the masked image.

alkasm
  • 22,094
  • 5
  • 78
  • 94
  • @Pankaj If that answered your question could you please select it as the answer? Otherwise let me know if you need me to expand on anything. – alkasm Jun 11 '17 at 02:09
  • thank you sir, Actually i wanted to calculate the HSV value of the laser dot in python , i just asked another question https://stackoverflow.com/questions/44480131/python-opencv-hsv-range-finder-creating-trackbars , , i am getting a lot of troubles, thank you in advance – Pankaj Jun 11 '17 at 03:36
  • Somehow I have just managed to finish a script which does *exactly what you want*: grab it on [GitHub](https://github.com/alkasm/cspaceThresh). – alkasm Jun 11 '17 at 05:33