Skip to content

Commit 92cc4f5

Browse files
committed
Initial Commit 15/03/2021
1 parent 4da5a10 commit 92cc4f5

10 files changed

+92
-1
lines changed

ISIC_0031023.jpg

394 KB
Loading

README.md

+48-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,48 @@
1-
# Dullrazor-algorithm
1+
# Dullrazor-algorithm 💻🧬
2+
3+
<img src="screenshots/screenshot_0.png" alt="homepage"><br>
4+
<hr>
5+
6+
### Requirements
7+
8+
<p>Programming language: <i>Python</i><br>
9+
Version language: <i>Python 3.8.8</i><br>
10+
Libraries: <i>OpenCV 4.5.1</i><br>
11+
</p>
12+
<hr>
13+
14+
<p style="text-align:justify;">Most images of skin lesions have unwanted elements, such as shadows and hairs, which can make it difficult to segment the lesion and introduce erroneous information on its characteristics. Therefore, it is necessary to apply some artificial vision techniques to eliminate any noise component.</p>
15+
16+
<p style="text-align:justify;">Body hair is one of the factors that can affect lesion segmentation. For the detection and removal of hairs, a pre-processing technique called DullRazor is used, which consists of applying a series of morphological operations to the image in order to generate a mask that contains the hairs. The steps to apply the DullRazor algorithm are:</p>
17+
18+
<ol>
19+
<li>Convert the original image to grayscale.</li>
20+
<li>Closing to the grayscale image, using a linear or cross-shaped kernel.</li>
21+
<li>Calculate the difference between the resulting image and the original.</li>
22+
<li>Apply binary thresholding to obtain a mask with the hairs in the image.</li>
23+
<li>Replace the pixels in common between the mask and the original image, with pixels from the latter.</li>
24+
</ol>
25+
<p>For steps 2 and 3 of the DullRazor algorithm, the advanced morphological operation blackhat from the OpenCV library was used. On the other hand, the cv2.inpaint command from the same library was used in the last step of the algorithm.</p>
26+
<hr>
27+
28+
## SCREENSHOTS
29+
30+
### Input image
31+
<img src="screenshots/screenshot_1.png" alt="Input image"><br>
32+
33+
### Cropped image
34+
<img src="screenshots/screenshot_2.png" alt="Cropped image"><br>
35+
36+
### Gray scale image
37+
<img src="screenshots/screenshot_3.png" alt="Gray scale image"><br>
38+
39+
### Black hat filter
40+
<img src="screenshots/screenshot_4.png" alt="Black hat filter"><br>
41+
42+
### Binary Thresholding (MASK)
43+
<img src="screenshots/screenshot_5.png" alt="Binary Thresholding"><br>
44+
45+
### Replace pixels of the mask (Output image)
46+
<img src="screenshots/screenshot_6.png" alt="Output image"><br>
47+
48+
<p><i>Developed by engineer Javier Velasquez (2020)</i></p>

dullrazor.py

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# -*- coding: utf-8 -*-
2+
"""
3+
Created on Tue Feb 18 11:42:26 2020
4+
5+
@author: Javier Velasquez P.
6+
"""
7+
import cv2
8+
9+
#IMAGE ACQUISITION
10+
11+
#Input image
12+
path='ISIC_0031023.jpg'
13+
#Read image
14+
image=cv2.imread(path,cv2.IMREAD_COLOR)
15+
#Image cropping
16+
img=image[30:410,30:560]
17+
18+
#DULL RAZOR (REMOVE HAIR)
19+
20+
#Gray scale
21+
grayScale = cv2.cvtColor(img, cv2.COLOR_RGB2GRAY )
22+
#Black hat filter
23+
kernel = cv2.getStructuringElement(1,(9,9))
24+
blackhat = cv2.morphologyEx(grayScale, cv2.MORPH_BLACKHAT, kernel)
25+
#Gaussian filter
26+
bhg= cv2.GaussianBlur(blackhat,(3,3),cv2.BORDER_DEFAULT)
27+
#Binary thresholding (MASK)
28+
ret,mask = cv2.threshold(bhg,10,255,cv2.THRESH_BINARY)
29+
#Replace pixels of the mask
30+
dst = cv2.inpaint(img,mask,6,cv2.INPAINT_TELEA)
31+
32+
#Display images
33+
cv2.imshow("Original image",image)
34+
cv2.imshow("Cropped image",img)
35+
cv2.imshow("Gray Scale image",grayScale)
36+
cv2.imshow("Blackhat",blackhat)
37+
cv2.imshow("Binary mask",mask)
38+
cv2.imshow("Clean image",dst)
39+
40+
cv2.waitKey()
41+
cv2.destroyAllWindows()
42+
43+
44+

screenshots/screenshot_0.png

586 KB
Loading

screenshots/screenshot_1.png

566 KB
Loading

screenshots/screenshot_2.png

428 KB
Loading

screenshots/screenshot_3.png

235 KB
Loading

screenshots/screenshot_4.png

220 KB
Loading

screenshots/screenshot_5.png

34.7 KB
Loading

screenshots/screenshot_6.png

318 KB
Loading

0 commit comments

Comments
 (0)