Home > OS >  How can I blur a mask and smooth its edges?
How can I blur a mask and smooth its edges?

Time:04-16

I want to change the color of the cheeks of this photo. I got a mask with sharp edges How can I blur a mask and smooth its edges? image mask

CodePudding user response:

# import the necessary packages
import argparse
import cv2
# construct the argument parser and parse the arguments
ap = argparse.ArgumentParser()
ap.add_argument("-i", "--image", type=str, default="pca8e.png",
    help="path to input image")
args = vars(ap.parse_args())
# load the image, display it to our screen, and initialize a list of
# kernel sizes (so we can evaluate the relationship between kernel
# size and amount of blurring)
image = cv2.imread(args["image"])
cv2.imshow("Original", image)
kernelSizes = [(41,41)]
# loop over the kernel sizes
for (kX, kY) in kernelSizes:
    # apply a "Gaussian" blur to the image
    blurred = cv2.GaussianBlur(image, (kX, kY), 0)
    cv2.imshow("Gaussian ({}, {})".format(kX, kY), blurred)
    cv2.waitKey(0)

Try this code to blur the mask image. But I don't know how you're going to use it with your image.

CodePudding user response:

The skimage library has a lot of image processing functions that might be helpful. I would try the gaussian filter: https://scikit-image.org/docs/dev/api/skimage.filters.html#skimage.filters.gaussian

  • Related