How to remove noises and rows of image with presence of hairs?

4

I'm working with hair removal on skin images. Searching the literature, the means to achieve my goal, is by applying some techniques of segmentation and noise removal in images. Which I'm applying to. An example image I work for is this:

ApplyingtheGaussianDiferenceoftheimageIhavetheoutput:

importcv2importnumpyasnp#readtheinputfileimg=cv2.imread('014.bmp')#runa5x5gaussianblurthena3x3gaussianblrblur5=cv2.GaussianBlur(img,(5,5),0)blur3=cv2.GaussianBlur(img,(3,3),0)DoGim=blur5-blur3cv2.imwrite('014-DoG.jpg',DoGim)

ThenIusethemorphologicaloperator:cv2.morphologyExtoremovethenoisesfromtheimage,leavingonlythehairs,sothatlater,Icanapplyamasktoremovethosehairs.However,theoutputforboth%of%and%of%donotmeettheexpecitative.

importnumpyasnpimportmatplotlib.pyplotaspltimportcv2pic=cv2.imread('014DoG.jpg')img2gray=cv2.cvtColor(pic,cv2.COLOR_RGB2GRAY)#Removehairwithopeningkernel=np.ones((5,5),np.uint8)opening=cv2.morphologyEx(img2gray,cv2.MORPH_OPEN,kernel)plt.imshow(opening,cmap='gray')plt.show()

Open:

Close:

Can anyone help me remove these noises and get rid of hairs?

    
asked by anonymous 11.11.2018 / 00:55

1 answer

2

If you are already using morphological operations, why not directly use a closure to eliminate hairs?

You will need to know more or less the average thickness of them for structuring element generation, or you can leave this value configurable on your system. Anyway, I suggest using a cross rather than a rectangle as it eliminates the hairs while maintaining a greater connection of "isthmuses" between the pints (in the posterior result of the thresholding).

By the way, I'm assuming your interest is to detect the areas of the spots, so it also includes a simple example of thresholding. I'm using the average gray scale value (127), but you may need to fine-tune it depending on your images.

Here is the code (I read your own disk image, called test.png here in my example):

import numpy as np
import matplotlib.pyplot as plt
import cv2

pic = cv2.imread('teste.png')
img2gray = cv2.cvtColor(pic, cv2.COLOR_RGB2GRAY)

# Remove hair with closing and blur
kernel = cv2.getStructuringElement(cv2.MORPH_CROSS,(10,10))
closing = cv2.morphologyEx(img2gray, cv2.MORPH_CLOSE, kernel)
closing = cv2.GaussianBlur(closing, (5, 5), 0)

# Thresholding for the skin patches
_,threshold = cv2.threshold(closing, 127, 255, cv2.THRESH_BINARY)

fig = plt.figure('Deteção de Pintas')

plt.subplot(131)
plt.title('Imagem original')
plt.imshow(img2gray, cmap='gray')

plt.subplot(132)
plt.title('Resultado do Fechamento')
plt.imshow(closing, cmap='gray')

plt.subplot(133)
plt.title('Resultado da Limiarização')
plt.imshow(threshold, cmap='gray')

plt.show()

And the result:

PS:Ifthethresholdresultisnotgoodenough(eventobeusedasamask),youcantryadifferentapproachwithKMays: link Use 3 (or 4) clusters, for example, and throw away only the brightest grouping pixels, keeping the original pixels of the other two clusters darker.

    
19.11.2018 / 22:48