{
  "id": 165582,
  "title": "Body Hair Remove with Open-CV",
  "url": "/competitions/siim-isic-melanoma-classification/discussion/165582",
  "author_name": "Vatsal Parsaniya",
  "post_date": "2020-07-10T09:06:37.020000",
  "votes": 53,
  "comment_count": 10,
  "views": 0,
  "content": "<ul>\n<li>There are many images with body hair covering the lesion so, hair remove operation can be useful for model focus on lesion part.</li>\n<li>Method for hair remove using CV2 </li>\n</ul>\n\n<p>```\ndef hair_remove(image):\n    # convert image to grayScale\n    grayScale = cv2.cvtColor(image, cv2.COLOR_RGB2GRAY)</p>\n\n<pre><code># kernel for morphologyEx\nkernel = cv2.getStructuringElement(1,(17,17))\n\n# apply MORPH_BLACKHAT to grayScale image\nblackhat = cv2.morphologyEx(grayScale, cv2.MORPH_BLACKHAT, kernel)\n\n# apply thresholding to blackhat\n_,threshold = cv2.threshold(blackhat,10,255,cv2.THRESH_BINARY)\n\n# inpaint with original image and threshold image\nfinal_image = cv2.inpaint(image,threshold,1,cv2.INPAINT_TELEA)\n\nreturn final_image\n</code></pre>\n\n<p>```</p>\n\n<ul>\n<li>this technique works on black-Hair only (Not white hair)\ncheck notebook <a href=\"https://www.kaggle.com/vatsalparsaniya/melanoma-hair-remove\">here</a></li>\n</ul>\n\n<h2>Example of body hair remove with this method:</h2>\n\n<p><img src=\"https://www.googleapis.com/download/storage/v1/b/kaggle-user-content/o/inbox%2F2907842%2F167afd50ab11911426494c40b0dee656%2F4.png?generation=1594370870226580&amp;alt=media\" alt=\"\">\n<img src=\"https://www.googleapis.com/download/storage/v1/b/kaggle-user-content/o/inbox%2F2907842%2F03b23320df9ea9966efb09c2a60fc305%2F1.png?generation=1594370918408705&amp;alt=media\" alt=\"\">\n<img src=\"https://www.googleapis.com/download/storage/v1/b/kaggle-user-content/o/inbox%2F2907842%2F556392470cd28765aeaff2e4055a831d%2F3.png?generation=1594370944655636&amp;alt=media\" alt=\"\"></p>\n\n<h2>Visualizing all CV2 Operations</h2>\n\n<p><img src=\"https://www.googleapis.com/download/storage/v1/b/kaggle-user-content/o/inbox%2F2907842%2Fb156694a1947ec2798d05bf321883ec3%2Findex.png?generation=1594370566397745&amp;alt=media\" alt=\"\"></p>\n\n<h3>apply this method on data, please share how much it affects to your LB score</h3>\n\n<h3>what do you think?? any suggestions for improvement.</h3>",
  "messages": [
    {
      "id": 922673,
      "postDate": "2020-07-10T09:06:37.020Z",
      "content": "<ul>\n<li>There are many images with body hair covering the lesion so, hair remove operation can be useful for model focus on lesion part.</li>\n<li>Method for hair remove using CV2 </li>\n</ul>\n\n<p>```\ndef hair_remove(image):\n    # convert image to grayScale\n    grayScale = cv2.cvtColor(image, cv2.COLOR_RGB2GRAY)</p>\n\n<pre><code># kernel for morphologyEx\nkernel = cv2.getStructuringElement(1,(17,17))\n\n# apply MORPH_BLACKHAT to grayScale image\nblackhat = cv2.morphologyEx(grayScale, cv2.MORPH_BLACKHAT, kernel)\n\n# apply thresholding to blackhat\n_,threshold = cv2.threshold(blackhat,10,255,cv2.THRESH_BINARY)\n\n# inpaint with original image and threshold image\nfinal_image = cv2.inpaint(image,threshold,1,cv2.INPAINT_TELEA)\n\nreturn final_image\n</code></pre>\n\n<p>```</p>\n\n<ul>\n<li>this technique works on black-Hair only (Not white hair)\ncheck notebook <a href=\"https://www.kaggle.com/vatsalparsaniya/melanoma-hair-remove\">here</a></li>\n</ul>\n\n<h2>Example of body hair remove with this method:</h2>\n\n<p><img src=\"https://www.googleapis.com/download/storage/v1/b/kaggle-user-content/o/inbox%2F2907842%2F167afd50ab11911426494c40b0dee656%2F4.png?generation=1594370870226580&amp;alt=media\" alt=\"\">\n<img src=\"https://www.googleapis.com/download/storage/v1/b/kaggle-user-content/o/inbox%2F2907842%2F03b23320df9ea9966efb09c2a60fc305%2F1.png?generation=1594370918408705&amp;alt=media\" alt=\"\">\n<img src=\"https://www.googleapis.com/download/storage/v1/b/kaggle-user-content/o/inbox%2F2907842%2F556392470cd28765aeaff2e4055a831d%2F3.png?generation=1594370944655636&amp;alt=media\" alt=\"\"></p>\n\n<h2>Visualizing all CV2 Operations</h2>\n\n<p><img src=\"https://www.googleapis.com/download/storage/v1/b/kaggle-user-content/o/inbox%2F2907842%2Fb156694a1947ec2798d05bf321883ec3%2Findex.png?generation=1594370566397745&amp;alt=media\" alt=\"\"></p>\n\n<h3>apply this method on data, please share how much it affects to your LB score</h3>\n\n<h3>what do you think?? any suggestions for improvement.</h3>",
      "rawMarkdown": "* There are many images with body hair covering the lesion so, hair remove operation can be useful for model focus on lesion part.\n*  Method for hair remove using CV2 \n\n```\ndef hair_remove(image):\n    # convert image to grayScale\n    grayScale = cv2.cvtColor(image, cv2.COLOR_RGB2GRAY)\n    \n    # kernel for morphologyEx\n    kernel = cv2.getStructuringElement(1,(17,17))\n    \n    # apply MORPH_BLACKHAT to grayScale image\n    blackhat = cv2.morphologyEx(grayScale, cv2.MORPH_BLACKHAT, kernel)\n    \n    # apply thresholding to blackhat\n    _,threshold = cv2.threshold(blackhat,10,255,cv2.THRESH_BINARY)\n    \n    # inpaint with original image and threshold image\n    final_image = cv2.inpaint(image,threshold,1,cv2.INPAINT_TELEA)\n    \n    return final_image\n```\n\n* this technique works on black-Hair only (Not white hair)\n#### check notebook [here](https://www.kaggle.com/vatsalparsaniya/melanoma-hair-remove) \n## Example of body hair remove with this method:\n![](https://www.googleapis.com/download/storage/v1/b/kaggle-user-content/o/inbox%2F2907842%2F167afd50ab11911426494c40b0dee656%2F4.png?generation=1594370870226580&amp;alt=media)\n![](https://www.googleapis.com/download/storage/v1/b/kaggle-user-content/o/inbox%2F2907842%2F03b23320df9ea9966efb09c2a60fc305%2F1.png?generation=1594370918408705&amp;alt=media)\n![](https://www.googleapis.com/download/storage/v1/b/kaggle-user-content/o/inbox%2F2907842%2F556392470cd28765aeaff2e4055a831d%2F3.png?generation=1594370944655636&amp;alt=media)\n\n## Visualizing all CV2 Operations \n![](https://www.googleapis.com/download/storage/v1/b/kaggle-user-content/o/inbox%2F2907842%2Fb156694a1947ec2798d05bf321883ec3%2Findex.png?generation=1594370566397745&amp;alt=media)\n\n### apply this method on data, please share how much it affects to your LB score\n\n### what do you think?? any suggestions for improvement.\n\n",
      "votes": 53
    },
    {
      "id": 922706,
      "postDate": "2020-07-10T09:30:47.057Z",
      "content": "<p>I used this augmentation. But It's performance is low. I used both in TTA and Without TTA.\nWith Hair :- 0.937\nWithout Hair :- 0.928\nWithout hair and Test data also without hair:- 0.926</p>",
      "rawMarkdown": "I used this augmentation. But It's performance is low. I used both in TTA and Without TTA.\nWith Hair :- 0.937\nWithout Hair :- 0.928\nWithout hair and Test data also without hair:- 0.926",
      "votes": 7
    },
    {
      "id": 930120,
      "postDate": "2020-07-15T08:01:21.350Z",
      "content": "<p>I used hair removal early on but abandoned it as it does not seem to improve over adding of hair.</p>",
      "rawMarkdown": "I used hair removal early on but abandoned it as it does not seem to improve over adding of hair.",
      "votes": 3
    },
    {
      "id": 948482,
      "postDate": "2020-07-28T02:13:32.103Z",
      "content": "<p>Hi, by applying hair removal, my LB score get lower. So, I give up applying such augmentation.</p>",
      "rawMarkdown": "Hi, by applying hair removal, my LB score get lower. So, I give up applying such augmentation.",
      "votes": 1
    },
    {
      "id": 922737,
      "postDate": "2020-07-10T09:58:55.377Z",
      "content": "<p><a href=\"https://www.kaggle.com/c/siim-isic-melanoma-classification/discussion/154859\">Hair removal</a> techniques were already discussed several weeks ago. Thank you for sharing Python code though 👍 </p>\n\n<p>In training data, there are about 100 images with hair out of 584 Malignant.</p>\n\n<p>Please check this thread <a href=\"https://www.kaggle.com/c/siim-isic-melanoma-classification/discussion/159176\">Augmentation technique to add hair</a>, where several participants (Roman, PC Jimmy, Aykhan.py) reported improvement of score.</p>",
      "rawMarkdown": "[Hair removal](https://www.kaggle.com/c/siim-isic-melanoma-classification/discussion/154859) techniques were already discussed several weeks ago. Thank you for sharing Python code though 👍 \n\nIn training data, there are about 100 images with hair out of 584 Malignant.\n\nPlease check this thread [Augmentation technique to add hair](https://www.kaggle.com/c/siim-isic-melanoma-classification/discussion/159176), where several participants (Roman, PC Jimmy, Aykhan.py) reported improvement of score.",
      "votes": 1,
      "replies": [
        {
          "id": 923707,
          "postDate": "2020-07-11T05:01:40.897Z",
          "content": "<p>My hair removal code the same basic - assume we both found the same two year old git.</p>\n\n<p>I used mine with a 0.5 probability and results got worse - about the same change as Gyanendra reported.  As you noted the hair percentage in images is around 20% - when I used with a probability of 0.10 than I did see a gain.  So I think to use with benefit you don't want to over use it.  The real trick would be to use it only on images with hair :)</p>\n\n<p>I think the issue is that the method also will remove some not hair features - features that are likely helpful.  You can see the features that will be removed in the threshold images that Vatsal generated.  There are 4 of the images where stuff other than air is being removed.</p>",
          "rawMarkdown": "My hair removal code the same basic - assume we both found the same two year old git.\n\nI used mine with a 0.5 probability and results got worse - about the same change as Gyanendra reported.  As you noted the hair percentage in images is around 20% - when I used with a probability of 0.10 than I did see a gain.  So I think to use with benefit you don't want to over use it.  The real trick would be to use it only on images with hair :)\n\nI think the issue is that the method also will remove some not hair features - features that are likely helpful.  You can see the features that will be removed in the threshold images that Vatsal generated.  There are 4 of the images where stuff other than air is being removed.",
          "votes": 2
        }
      ]
    },
    {
      "id": 2888101,
      "postDate": "2024-06-24T15:38:20.117Z",
      "content": "<p>oh great dataset</p>",
      "rawMarkdown": "oh great dataset\n"
    },
    {
      "id": 932751,
      "postDate": "2020-07-17T08:54:42.873Z",
      "content": "<p>Thank you for this! I was thinking along this line for a while.</p>\n\n<p>Can you share to what extent this altered the overall performance?</p>",
      "rawMarkdown": "Thank you for this! I was thinking along this line for a while.\n\nCan you share to what extent this altered the overall performance?"
    },
    {
      "id": 929410,
      "postDate": "2020-07-14T16:47:01.213Z",
      "content": "<p>Very nice work!!</p>",
      "rawMarkdown": "Very nice work!!"
    },
    {
      "id": 923628,
      "postDate": "2020-07-11T03:18:15.773Z",
      "rawMarkdown": "",
      "votes": 1,
      "isDeleted": true,
      "replies": [
        {
          "id": 923647,
          "postDate": "2020-07-11T03:56:17.210Z",
          "content": "<p>Yes, threshold give you final mask image with detected hair.</p>",
          "rawMarkdown": "Yes, threshold give you final mask image with detected hair."
        }
      ]
    }
  ],
  "comments": [
    {
      "id": 922706,
      "author_name": "PIkachu",
      "author_url": "",
      "post_date": "2020-07-10T09:30:47.057000",
      "content": "<p>I used this augmentation. But It's performance is low. I used both in TTA and Without TTA.\nWith Hair :- 0.937\nWithout Hair :- 0.928\nWithout hair and Test data also without hair:- 0.926</p>",
      "votes": 7,
      "replies": []
    },
    {
      "id": 930120,
      "author_name": "Signal",
      "author_url": "",
      "post_date": "2020-07-15T08:01:21.350000",
      "content": "<p>I used hair removal early on but abandoned it as it does not seem to improve over adding of hair.</p>",
      "votes": 3,
      "replies": []
    },
    {
      "id": 948482,
      "author_name": "Zhiwei Ren",
      "author_url": "",
      "post_date": "2020-07-28T02:13:32.103000",
      "content": "<p>Hi, by applying hair removal, my LB score get lower. So, I give up applying such augmentation.</p>",
      "votes": 1,
      "replies": []
    },
    {
      "id": 922737,
      "author_name": "Sirish Somanchi",
      "author_url": "",
      "post_date": "2020-07-10T09:58:55.377000",
      "content": "<p><a href=\"https://www.kaggle.com/c/siim-isic-melanoma-classification/discussion/154859\">Hair removal</a> techniques were already discussed several weeks ago. Thank you for sharing Python code though 👍 </p>\n\n<p>In training data, there are about 100 images with hair out of 584 Malignant.</p>\n\n<p>Please check this thread <a href=\"https://www.kaggle.com/c/siim-isic-melanoma-classification/discussion/159176\">Augmentation technique to add hair</a>, where several participants (Roman, PC Jimmy, Aykhan.py) reported improvement of score.</p>",
      "votes": 1,
      "replies": [
        {
          "id": 923707,
          "author_name": "PC Jimmmy",
          "author_url": "",
          "post_date": "2020-07-11T05:01:40.897000",
          "content": "<p>My hair removal code the same basic - assume we both found the same two year old git.</p>\n\n<p>I used mine with a 0.5 probability and results got worse - about the same change as Gyanendra reported.  As you noted the hair percentage in images is around 20% - when I used with a probability of 0.10 than I did see a gain.  So I think to use with benefit you don't want to over use it.  The real trick would be to use it only on images with hair :)</p>\n\n<p>I think the issue is that the method also will remove some not hair features - features that are likely helpful.  You can see the features that will be removed in the threshold images that Vatsal generated.  There are 4 of the images where stuff other than air is being removed.</p>",
          "votes": 2,
          "replies": []
        }
      ]
    },
    {
      "id": 2888101,
      "author_name": "Wizbi_k",
      "author_url": "",
      "post_date": "2024-06-24T15:38:20.117000",
      "content": "<p>oh great dataset</p>",
      "votes": 0,
      "replies": []
    },
    {
      "id": 932751,
      "author_name": "Aditya Baurai",
      "author_url": "",
      "post_date": "2020-07-17T08:54:42.873000",
      "content": "<p>Thank you for this! I was thinking along this line for a while.</p>\n\n<p>Can you share to what extent this altered the overall performance?</p>",
      "votes": 0,
      "replies": []
    },
    {
      "id": 929410,
      "author_name": "Anubhav Sharma",
      "author_url": "",
      "post_date": "2020-07-14T16:47:01.213000",
      "content": "<p>Very nice work!!</p>",
      "votes": 0,
      "replies": []
    },
    {
      "id": 923628,
      "author_name": "",
      "author_url": "",
      "post_date": "2020-07-11T03:18:15.773000",
      "content": "",
      "votes": 1,
      "replies": [
        {
          "id": 923647,
          "author_name": "Vatsal Parsaniya",
          "author_url": "",
          "post_date": "2020-07-11T03:56:17.210000",
          "content": "<p>Yes, threshold give you final mask image with detected hair.</p>",
          "votes": 0,
          "replies": []
        }
      ]
    }
  ],
  "raw_markdown_by_id": {
    "922673": "* There are many images with body hair covering the lesion so, hair remove operation can be useful for model focus on lesion part.\n*  Method for hair remove using CV2 \n\n```\ndef hair_remove(image):\n    # convert image to grayScale\n    grayScale = cv2.cvtColor(image, cv2.COLOR_RGB2GRAY)\n    \n    # kernel for morphologyEx\n    kernel = cv2.getStructuringElement(1,(17,17))\n    \n    # apply MORPH_BLACKHAT to grayScale image\n    blackhat = cv2.morphologyEx(grayScale, cv2.MORPH_BLACKHAT, kernel)\n    \n    # apply thresholding to blackhat\n    _,threshold = cv2.threshold(blackhat,10,255,cv2.THRESH_BINARY)\n    \n    # inpaint with original image and threshold image\n    final_image = cv2.inpaint(image,threshold,1,cv2.INPAINT_TELEA)\n    \n    return final_image\n```\n\n* this technique works on black-Hair only (Not white hair)\n#### check notebook [here](https://www.kaggle.com/vatsalparsaniya/melanoma-hair-remove) \n## Example of body hair remove with this method:\n![](https://www.googleapis.com/download/storage/v1/b/kaggle-user-content/o/inbox%2F2907842%2F167afd50ab11911426494c40b0dee656%2F4.png?generation=1594370870226580&amp;alt=media)\n![](https://www.googleapis.com/download/storage/v1/b/kaggle-user-content/o/inbox%2F2907842%2F03b23320df9ea9966efb09c2a60fc305%2F1.png?generation=1594370918408705&amp;alt=media)\n![](https://www.googleapis.com/download/storage/v1/b/kaggle-user-content/o/inbox%2F2907842%2F556392470cd28765aeaff2e4055a831d%2F3.png?generation=1594370944655636&amp;alt=media)\n\n## Visualizing all CV2 Operations \n![](https://www.googleapis.com/download/storage/v1/b/kaggle-user-content/o/inbox%2F2907842%2Fb156694a1947ec2798d05bf321883ec3%2Findex.png?generation=1594370566397745&amp;alt=media)\n\n### apply this method on data, please share how much it affects to your LB score\n\n### what do you think?? any suggestions for improvement.\n\n",
    "922706": "I used this augmentation. But It's performance is low. I used both in TTA and Without TTA.\nWith Hair :- 0.937\nWithout Hair :- 0.928\nWithout hair and Test data also without hair:- 0.926",
    "930120": "I used hair removal early on but abandoned it as it does not seem to improve over adding of hair.",
    "948482": "Hi, by applying hair removal, my LB score get lower. So, I give up applying such augmentation.",
    "922737": "[Hair removal](https://www.kaggle.com/c/siim-isic-melanoma-classification/discussion/154859) techniques were already discussed several weeks ago. Thank you for sharing Python code though 👍 \n\nIn training data, there are about 100 images with hair out of 584 Malignant.\n\nPlease check this thread [Augmentation technique to add hair](https://www.kaggle.com/c/siim-isic-melanoma-classification/discussion/159176), where several participants (Roman, PC Jimmy, Aykhan.py) reported improvement of score.",
    "2888101": "oh great dataset\n",
    "932751": "Thank you for this! I was thinking along this line for a while.\n\nCan you share to what extent this altered the overall performance?",
    "929410": "Very nice work!!",
    "923628": ""
  }
}