├── ISIC_0031023.jpg ├── README.md ├── dullrazor.py └── screenshots ├── screenshot_0.png ├── screenshot_1.png ├── screenshot_2.png ├── screenshot_3.png ├── screenshot_4.png ├── screenshot_5.png └── screenshot_6.png /ISIC_0031023.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BlueDokk/Dullrazor-algorithm/8d4530182b8b3b0fc413bee84850f34d90aa4027/ISIC_0031023.jpg -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Dullrazor algorithm 💻🧬 2 | 3 | homepage
4 |
5 | 6 | ### Minimum requirements 7 | 8 |

Programming language: Python
9 | Version language: Python 3.8.8
10 | Libraries: OpenCV 4.5.1
11 |

12 |
13 | 14 |

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.

15 | 16 |

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:

17 | 18 |
    19 |
  1. Convert the original image to grayscale.
  2. 20 |
  3. Closing to the grayscale image, using a linear or cross-shaped kernel.
  4. 21 |
  5. Calculate the difference between the resulting image and the original.
  6. 22 |
  7. Apply binary thresholding to obtain a mask with the hairs in the image.
  8. 23 |
  9. Replace the pixels in common between the mask and the original image, with pixels from the latter.
  10. 24 |
25 |

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.

26 |
27 | 28 | ## SCREENSHOTS 29 | 30 |

Input image from HAM10000 database.

31 | 32 | ### Input image 33 | Input image
34 | 35 | ### Cropped image 36 | Cropped image
37 | 38 | ### Gray scale image 39 | Gray scale image
40 | 41 | ### Black hat filter 42 | Black hat filter
43 | 44 | ### Binary Thresholding (Mask) 45 | Binary Thresholding
46 | 47 | ### Replace pixels of the mask (Output image) 48 | Output image
49 | 50 |

Developed by engineer Javier Velasquez (2020)

51 | -------------------------------------------------------------------------------- /dullrazor.py: -------------------------------------------------------------------------------- 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: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BlueDokk/Dullrazor-algorithm/8d4530182b8b3b0fc413bee84850f34d90aa4027/screenshots/screenshot_0.png -------------------------------------------------------------------------------- /screenshots/screenshot_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BlueDokk/Dullrazor-algorithm/8d4530182b8b3b0fc413bee84850f34d90aa4027/screenshots/screenshot_1.png -------------------------------------------------------------------------------- /screenshots/screenshot_2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BlueDokk/Dullrazor-algorithm/8d4530182b8b3b0fc413bee84850f34d90aa4027/screenshots/screenshot_2.png -------------------------------------------------------------------------------- /screenshots/screenshot_3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BlueDokk/Dullrazor-algorithm/8d4530182b8b3b0fc413bee84850f34d90aa4027/screenshots/screenshot_3.png -------------------------------------------------------------------------------- /screenshots/screenshot_4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BlueDokk/Dullrazor-algorithm/8d4530182b8b3b0fc413bee84850f34d90aa4027/screenshots/screenshot_4.png -------------------------------------------------------------------------------- /screenshots/screenshot_5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BlueDokk/Dullrazor-algorithm/8d4530182b8b3b0fc413bee84850f34d90aa4027/screenshots/screenshot_5.png -------------------------------------------------------------------------------- /screenshots/screenshot_6.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BlueDokk/Dullrazor-algorithm/8d4530182b8b3b0fc413bee84850f34d90aa4027/screenshots/screenshot_6.png --------------------------------------------------------------------------------