1

I would like to darken one image based on the mask of an edge-detected second image.

Image 1: Original (greyscale) image

enter image description here

Image 2: Edge detected (to be used as mask)

enter image description here

Image 3: Failed example showing cv2.subtract processing

enter image description here

In my failed example (Image 3), I subtracted the white pixels (255) from the original image but what I want to do is DARKEN the original image based on a mask of the edge detected image.

In this article: How to fast change image brightness with python + OpenCV?, Bill Gates describes how he converts the image to HSV, splits out then modifies Value, and then finally merges back. This seems like a reasonable approach but I only want to modify the Value where the mask is white i.e. the edge exists.

Ultimately, I am trying to enhance the edge of a low resolution thermal video stream in a similar way to the FLIR One VividIR technology.

I believe that I've made it really far as a complete novice to image processing, OpenCV and Python but after days now of trying just about every function OpenCV offers, I've got myself stuck.

Jean-François Fabre
  • 137,073
  • 23
  • 153
  • 219
David Adams
  • 83
  • 1
  • 1
  • 6
  • Gray scale images only? – AnonSubmitter85 Dec 17 '17 at 02:41
  • @David Could you show us an example image of your thermal video stream use case? That might make it easier to workout a solution. – Ganesh Tata Dec 17 '17 at 07:05
  • Anon No, thermal image has three channels but I know how to split them. Ganesh Happy to share images/video if you're still interested. I'm basically fitting my DJI Mavic Pro drone with a night vision (composite thermal and NIR) capability without the multi-thousand price tag. – David Adams Dec 18 '17 at 08:35

1 Answers1

-1
## get the edge coordinates
pos = np.where(edge >0)
## divide 
img[pos] //=2
Kinght 金
  • 17,681
  • 4
  • 60
  • 74
  • 1
    It may have been brief and, tbh, I don't fully understand why it works, but it certainly works!! Two days ... two days I've been working on doing that and it ends up being two lines of code. You guys are just fantastic! I'm guessing that the numpy function ends up with a boolean array of the same size where each instance of >0 becomes True. Then the 2nd line must carry out a division (such strange syntax, //=2) on the original array only when the second array (the mask) holds a True. Very clever and works perfectly. – David Adams Dec 18 '17 at 08:29
  • @Jean-FrançoisFabre They guys think the answer is too short, and criticize without checking whether it works or not .... – Kinght 金 Aug 19 '18 at 06:02
  • Maybe you could add more context around this code. It seems OP understood you, but not the others. My trick in this case is to provide fake simple data for a standalone code snippet that anyone can paste and see that it works. I also think that you're collateral of now deleted even shorter answer which looks like yours but with some smartass comments added. – Jean-François Fabre Aug 19 '18 at 07:25
  • or maybe they just don't like soccer :) – Jean-François Fabre Aug 19 '18 at 07:27