【发布时间】:2018-10-17 15:09:04
【问题描述】:
我正在处理皮肤斑点的识别。为此,我处理了许多具有不同噪声的图像。这些噪音之一是毛发,因为我的图像在污渍(ROI)区域上有毛发。如何减少或去除这些类型的图像噪声?
下面的代码会减少毛发所在的区域,但不会去除感兴趣区域(ROI)上方的毛发。
import numpy as np
import cv2
IMD = 'IMD436'
# Read the image and perfrom an OTSU threshold
img = cv2.imread(IMD+'.bmp')
gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
ret, thresh = cv2.threshold(gray,0,255,cv2.THRESH_BINARY_INV+cv2.THRESH_OTSU)
# Remove hair with opening
kernel = np.ones((2,2),np.uint8)
opening = cv2.morphologyEx(thresh,cv2.MORPH_OPEN,kernel, iterations = 2)
# Combine surrounding noise with ROI
kernel = np.ones((6,6),np.uint8)
dilate = cv2.dilate(opening,kernel,iterations=3)
# Blur the image for smoother ROI
blur = cv2.blur(dilate,(15,15))
# Perform another OTSU threshold and search for biggest contour
ret, thresh = cv2.threshold(blur,0,255,cv2.THRESH_BINARY+cv2.THRESH_OTSU)
contours, hierarchy = cv2.findContours(thresh,cv2.RETR_TREE,cv2.CHAIN_APPROX_NONE)
cnt = max(contours, key=cv2.contourArea)
# Create a new mask for the result image
h, w = img.shape[:2]
mask = np.zeros((h, w), np.uint8)
# Draw the contour on the new mask and perform the bitwise operation
cv2.drawContours(mask, [cnt],-1, 255, -1)
res = cv2.bitwise_and(img, img, mask=mask)
# Display the result
cv2.imwrite(IMD+'.png', res)
cv2.imshow('img', res)
cv2.waitKey(0)
cv2.destroyAllWindows()
如何去除我感兴趣区域顶部的毛发?
【问题讨论】:
-
你希望通过去除头发来达到什么目的?它不会透露有关皮肤斑点的新信息。仅仅是因为光学还是有其他原因?
-
您使用的图片与this other user 相同——他今天删除了一个问同样问题的问题。也许你们是不同的人一起工作,那很好。但如果你是同一个人,你应该知道创建多个帐户是违反 TOS 的。
-
这是我对那个已删除问题的建议:“有很多关于此的论文(“数字剃须”,我记得几年前看过一篇)以及您之前的问题。我建议您搜索科学文献而不是在这里问。你可能会从科学文献中得到更好的答案,因为你不太可能在这里找到像写这些论文的人那样彻底研究这个话题的人。我想重申这一点。这是一个有几个好的解决方案的话题,不要试图重新发明轮子!!!
-
@Cris 我们是不同的人一起工作。我正在研究文献,但由于我是处理的新手,我在实施解决方案时遇到了困难。所以我是来寻求帮助的。
-
我建议您尝试实施其中一种解决方案,并带着您遇到的具体问题来到这里。这些类型的问题更容易回答。当然,我可以阅读其中一些论文,并为您实施其中一种方法,但我没有几天的空闲时间来免费这样做。我相信这是有道理的,不是吗?您将在这里得到的任何答案都将是次优的即兴解决方案。或者,您也许可以找到其中一篇论文的源代码,并且您可以随时尝试询问作者是否愿意分享。
标签: python image opencv image-processing