为了账号安全,请及时绑定邮箱和手机立即绑定

如何使用opencv从皮肤图像中去除毛发?

如何使用opencv从皮肤图像中去除毛发?

慕哥9229398 2021-07-16 19:15:48
我正在研究皮肤斑点的识别。为此,我使用了许多具有不同噪声的图像。这些噪音之一是毛发,因为我在染色区域 (ROI) 上有毛发的图像。如何减少或消除这些类型的图像噪声?下面的代码减少了毛发所在的区域,但不会去除感兴趣区域(ROI)上方的毛发。import numpy as npimport cv2IMD = 'IMD436'# Read the image and perfrom an OTSU thresholdimg = 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 openingkernel = np.ones((2,2),np.uint8)opening = cv2.morphologyEx(thresh,cv2.MORPH_OPEN,kernel, iterations = 2)# Combine surrounding noise with ROIkernel = np.ones((6,6),np.uint8)dilate = cv2.dilate(opening,kernel,iterations=3)# Blur the image for smoother ROIblur = cv2.blur(dilate,(15,15))# Perform another OTSU threshold and search for biggest contourret, 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 imageh, w = img.shape[:2]mask = np.zeros((h, w), np.uint8)# Draw the contour on the new mask and perform the bitwise operationcv2.drawContours(mask, [cnt],-1, 255, -1)res = cv2.bitwise_and(img, img, mask=mask)# Display the resultcv2.imwrite(IMD+'.png', res)cv2.imshow('img', res)cv2.waitKey(0)cv2.destroyAllWindows()出口:如何去除感兴趣区域顶部的毛发?使用的图像:
查看完整描述

2 回答

  • 2 回答
  • 0 关注
  • 825 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号