forked from sunnyshah2894/DigitalHairRemoval
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDigitalHairRemoval.py
42 lines (32 loc) · 1.45 KB
/
DigitalHairRemoval.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# -*- coding: utf-8 -*-
"""
Following are the DHR tasks followed in this example code:
-- Applying Morphological Black-Hat transformation
-- Creating the mask for InPainting task
-- Applying inpainting algorithm on the image
"""
import cv2
src = cv2.imread("C:\\SkinHairRemovalPython\\inputImages\\sample1.jpg")
print( src.shape )
cv2.imshow("original Image" , src )
# Convert the original image to grayscale
grayScale = cv2.cvtColor( src, cv2.COLOR_RGB2GRAY )
cv2.imshow("GrayScale",grayScale)
cv2.imwrite('grayScale_sample1.jpg', grayScale, [int(cv2.IMWRITE_JPEG_QUALITY), 90])
# Kernel for the morphological filtering
kernel = cv2.getStructuringElement(1,(17,17))
# Perform the blackHat filtering on the grayscale image to find the
# hair countours
blackhat = cv2.morphologyEx(grayScale, cv2.MORPH_BLACKHAT, kernel)
cv2.imshow("BlackHat",blackhat)
cv2.imwrite('blackhat_sample1.jpg', blackhat, [int(cv2.IMWRITE_JPEG_QUALITY), 90])
# intensify the hair countours in preparation for the inpainting
# algorithm
ret,thresh2 = cv2.threshold(blackhat,10,255,cv2.THRESH_BINARY)
print( thresh2.shape )
cv2.imshow("Thresholded Mask",thresh2)
cv2.imwrite('thresholded_sample1.jpg', thresh2, [int(cv2.IMWRITE_JPEG_QUALITY), 90])
# inpaint the original image depending on the mask
dst = cv2.inpaint(src,thresh2,1,cv2.INPAINT_TELEA)
cv2.imshow("InPaint",dst)
cv2.imwrite('C:\\SkinHairRemovalPython\\InPainted_sample1.jpg', dst, [int(cv2.IMWRITE_JPEG_QUALITY), 90])