Blurring skin in image

Hello,
I am building a Javascript library which takes an image as an input, the output image will have all the human skin blurred like below.

I have got this script in python, which is working perfectly (example below) and I am converting it to JS using Opencv.js. The issue is I am not able to replicate the following line of code in Javascript.

out[global_mask>0] = blur[global_mask>0]

Here,
out: original image
global_mask: black and white image where all the skin is white and other parts are black
blur: blurred copy of the original image.

Can someone please guide me on this, I have tried creating an ROI on the original image and tried placing the black and white image over it. In my mind the path to achieve this is

  1. Make all the black pixels in the black and white image transparent
  2. Replace the white pixels in the black and white image with the pixels of blurred image at same position.
  3. Place the new image over the original image.

Screenshot 2021-09-27 at 3.43.49 PM

that code looks quite specific to python, but you could try:

  • get a skin mask (sounds like you already have that)
  • blur (a copy of) the whole image
  • use copyTo() (and using that mask) to overlay the blurred skin regions
1 Like

I currently have image mask

Screenshot 2021-09-27 at 4.57.20 PM

and the blurred image

Screenshot 2021-09-27 at 4.59.34 PM

I’ll use copyto method, thank you @berak

It worked @berak, Now I’ll just place this over the original image.
Thank you.
Screenshot 2021-09-27 at 5.13.27 PM

1 Like

related

@berak @crackwitz can you guide on this please