Human face dermabrasion principle

Face dermabrasion is the most basic face beauty effect. It is mainly divided into freckle removal, acne removal, fade dark circles and other steps. Through the previous study, I believe we can see at a glance what we need to recognize the face skin effect.

Because after grinding skin, the impurity of the face basically did not have, also can say lost detail. So you definitely need to use the filtering function. The process of filtering is to input each pixel value of the image into the filter to get a smooth image.

And we commonly used filtering have mean filtering, Gaussian filtering and bilateral filtering three kinds, which filter to choose?

First of all, the mean filtering will replace the original pixel value with the average value of the surrounding pixels, which will definitely cause the image to be too fuzzy, so it is excluded. Secondly, the principle of Gaussian filter is similar to that of mean filter, except that the template coefficient of Gaussian filter decreases with the increase of the distance from the template center. Although the blur degree of the image can be weakened, the edge information of the image will be lost.

So, there’s only one filter left, which is the bilateral filter. Because it combines the superposition effect of high-pass filter and A-truncated mean filter at the same time, it can ensure that the image is not very fuzzy, and also can retain the image edge information.

And the steps of the human face dermabrasion principle is divided into the following three steps:

  1. Image filtering
  2. Image fusion
  3. Image sharpening

Because, regardless of the above three types of filtering, will lead to a certain degree of blur (just relative to who is better), so the image needs to be fused and sharpen operation. In this way, some details of the image can be preserved to enhance the sense of reality of the image.

Where, the function used for image fusion is the cv2.addweighted () image weighting function. The original image is fused with the double-pass filtered image.

Finally, image sharpening operates using the PIL library, using its imageenhance.sharpness () function to automatically adjust the Sharpness and contrast of the image.

To achieve face dermabrasion effect

Now that we’ve fully understood how facial dermabrasion works. Next, let’s directly achieve the face of the skin effect, specific code as shown below:

# Face dermabrasion
def facial_dermabrasion_effect(fileName) :
    img = cv2.imread(fileName)
    blur_img = cv2.bilateralFilter(img, 31.75.75)
    # Image fusion
    result_img = cv2.addWeighted(img, 0.3, blur_img, 0.7.0)
    cv2.imwrite("58_1.jpg", result_img)

    image = Image.open("58_1.jpg")
    # Sharpness adjustment
    enh_img = ImageEnhance.Sharpness(image)
    image_sharped = enh_img.enhance(1.5)
    Contrast adjustment
    con_img = ImageEnhance.Contrast(image_sharped)
    image_con = con_img.enhance(1.15)
    image_con.save("58_2.jpg")

    img1 = cv2.imread("58.jpg")
    img2 = cv2.imread("58_2.jpg")
    cv2.imshow("1", img1)
    cv2.imshow("2", img2)
    cv2.waitKey()
    cv2.destroyAllWindows()


if __name__ == "__main__":
    facial_dermabrasion_effect("58.jpg")
Copy the code

After running, the effect is as follows:

The parameters of this code can be adjusted, not a constant, interested readers can adjust their own parameters to try the effect, of course, face skin just looks smooth skin. The following combination of whitening effect, you can achieve the kind of beauty of the camera.