Programming language: Python
Version language: Python 3.8.8
Libraries: OpenCV 4.5.1, Numpy 1.19.2
The human body is made up of curved surfaces that make the light projected on it not uniform. This circularity creates shadows and adds noise to dermoscopic images, making it difficult to segment the lesion. According to Cavalcanti et al., It is possible to attenuate the shadows present in this type of images by means of a linear regression in 2-D, modeling the variations in lighting and reassigning the values of each pixel.
Taking into account that there are no abrupt changes in the illumination of the image, this variation can be modeled by means of a quadratic function or second degree polynomial. To approximate the coefficients of the polynomial, it is necessary to use the pixels that have more information about the shadows, that is, those found in the corners of the image. Consequently, a set of 20 ร 20 pixels is extracted from each corner and a matrix ๐ is formed containing the union of the four sets (n = 1600 pixels). Then the matrix ๐ is used to approximate the coefficients of the quadratic function ๐ง (๐ฅ, ๐ฆ):
๐ง(๐ฅ,๐ฆ)=๐1x2+๐2y2+๐3๐ฅ๐ฆ+๐4๐ฅ+๐5๐ฆ+๐6
Where the variables ๐ฅ and ๐ฆ correspond to the coordinates of each element of ๐.
As the number of pixels is not large, the method of ordinary least squares (OLS) is used to minimize the function ๐ง (๐ฅ, ๐ฆ), and find the parameters ๐1 โฏ ๐6. This method is not iterative and therefore has less computational requirements. The expression for OLS, in its matrix form, is given by the following equation:
๐ฝ=(๐T๐)-1๐T๐ฆ
Where ๐ฝ is the resulting 6 ร 1 matrix containing the coefficients ๐1 โฏ ๐6, ๐ is an n ร 6 matrix with the terms for each coordinate (๐ฅ, ๐ฆ), and ๐ฆ is an n ร 1 matrix containing the intensity values of each pair (๐ฅ, ๐ฆ).
Once the coefficients have been obtained, ๐ง (๐ฅ, ๐ฆ) is calculated for each pixel of the blue channel of the image, in order to estimate the intensity of local illumination. Finally, the shadows are attenuated by the following expression:
๐ (๐ฅ,๐ฆ)=๐ผ(๐ฅ,๐ฆ)/๐ง(๐ฅ,๐ฆ)
Where ๐ (๐ฅ, ๐ฆ) is the resulting image, ๐ผ (๐ฅ, ๐ฆ) the blue layer of the image and ๐ง (๐ฅ, ๐ฆ) the local illumination intensity obtained.
This algorithm use DullRazor technique. To see the algorithm click [here]
Input image from HAM10000 database.
Developed by engineer Javier Velasquez (2020)