首页 > 解决方案 > 从图像方法中脱毛

问题描述

我试图去除头发 reom 一组皮肤图像

这是加载图像的代码

DIRECTORY = r'/gdrive/MyDrive/Train4'
CATEGORIES = ["h","m","v","s","a","Unknown"]

data = []
labels = []

for category in CATEGORIES:
    path = os.path.join(DIRECTORY,category)  
    label= CATEGORIES.index(category)
    for img in os.listdir(path):
        img_path = os.path.join(path, img)
        image = load_img(img_path, target_size=(1024,1024))
        final_image = removing_hair(image)
        image = cv2.resize(final_image,(224,224))
        image = img_to_array(image)
        image = preprocess_input(image)


        data.append(image)
        labels.append(label)

这是脱毛的方法

def removing_hair(image):
    # convert image to grayScale
    grayScale = cv2.cvtColor(image, cv2.COLOR_RGB2GRAY)
    
    # kernel for morphologyEx
    kernel = cv2.getStructuringElement(1,(17,17))
    
    # apply MORPH_BLACKHAT to grayScale image
    blackhat = cv2.morphologyEx(grayScale, cv2.MORPH_BLACKHAT, kernel)
    
    # apply thresholding to blackhat
    _,threshold = cv2.threshold(blackhat,10,255,cv2.THRESH_BINARY)
    
    # inpaint with original image and threshold image
    final_image = cv2.inpaint(image,threshold,1,cv2.INPAINT_TELEA)
    
    return final_image

但我不断收到这个错误,我无法解决它

TypeError                                 Traceback (most recent call last)
<ipython-input-16-6f8ff4af67a7> in <module>()
     12         img_path = os.path.join(path, img)
     13         image = load_img(img_path, target_size=(1024,1024))
---> 14         final_image = removing_hair(image)
     15         image = cv2.resize(final_image,(224,224))
     16         image = img_to_array(image)

<ipython-input-15-46bfec188a32> in removing_hair(image)
      1 def removing_hair(image):
      2     # convert image to grayScale
----> 3     grayScale = cv2.cvtColor(image, cv2.COLOR_RGB2GRAY)
      4 
      5     # kernel for morphologyEx

TypeError: Expected Ptr<cv::UMat> for argument '%s'

有什么问题,我该如何解决

标签: pythonimage

解决方案


推荐阅读