{
  "id": 183161,
  "title": "Publicly Available Lung Segmentation Model",
  "url": "/competitions/rsna-str-pulmonary-embolism-detection/discussion/183161",
  "author_name": "Ian Pan",
  "post_date": "2020-09-15T18:43:30.549000",
  "votes": 7,
  "comment_count": 4,
  "views": 0,
  "content": "<p>I see some non-deep learning approaches for lung segmentation being used. In the presence of significant lung pathology, these will probably fail. </p>\n<p>I have found <a href=\"https://github.com/JoHof/lungmask\" target=\"_blank\">https://github.com/JoHof/lungmask</a> to work very well and wanted to share it with all of you, in case you want to incorporate lung segmentation into your solution.</p>",
  "messages": [
    {
      "id": 1011907,
      "postDate": "2020-09-15T18:43:30.550Z",
      "content": "<p>I see some non-deep learning approaches for lung segmentation being used. In the presence of significant lung pathology, these will probably fail. </p>\n<p>I have found <a href=\"https://github.com/JoHof/lungmask\" target=\"_blank\">https://github.com/JoHof/lungmask</a> to work very well and wanted to share it with all of you, in case you want to incorporate lung segmentation into your solution.</p>",
      "rawMarkdown": "I see some non-deep learning approaches for lung segmentation being used. In the presence of significant lung pathology, these will probably fail. \n\nI have found [https://github.com/JoHof/lungmask](https://github.com/JoHof/lungmask) to work very well and wanted to share it with all of you, in case you want to incorporate lung segmentation into your solution.",
      "votes": 6
    },
    {
      "id": 1013005,
      "postDate": "2020-09-16T13:04:08.190Z",
      "content": "<p>Hi guys, I also public my CT lung segmentation model here. It was trained on several public datasets. Although it might can't have similar performance as the public repo in topic, but it has much faster inference time.<br>\n<a href=\"https://www.kaggle.com/xiejialun/lung-ct-scan-segmentation-model/comments\" target=\"_blank\">https://www.kaggle.com/xiejialun/lung-ct-scan-segmentation-model/comments</a></p>",
      "rawMarkdown": "Hi guys, I also public my CT lung segmentation model here. It was trained on several public datasets. Although it might can't have similar performance as the public repo in topic, but it has much faster inference time.\nhttps://www.kaggle.com/xiejialun/lung-ct-scan-segmentation-model/comments",
      "votes": 1
    },
    {
      "id": 1012013,
      "postDate": "2020-09-15T21:04:18.027Z",
      "content": "<p>Hi <a href=\"https://www.kaggle.com/vaillant\" target=\"_blank\">@vaillant</a>, I am in the process to implement that segmentation approach. It uses SimpleITK library and It seems this dataset has an issue with it. When a <code>dicom</code> file it throws this error but I could not know how to fix it. </p>\n<p>============================<br>\nUpdate: </p>\n<p><a href=\"https://www.kaggle.com/smerllo/deep-learning-approach-for-lung-segmentation-unet\" target=\"_blank\">kernel</a> worked - Credit to ipan </p>\n<p>====================================</p>\n<pre><code>from lungmask import mask\nimport SimpleITK as sitk\nimg = sitk.ReadImage(example)\n</code></pre>\n<pre><code>---------------------------------------------------------------------------\nRuntimeError                              Traceback (most recent call last)\n&lt;ipython-input-10-b63d2459c2bf&gt; in &lt;module&gt;\n      1 from lungmask import mask\n      2 import SimpleITK as sitk\n----&gt; 3 img = sitk.ReadImage(example)\n\n/opt/conda/lib/python3.7/site-packages/SimpleITK/SimpleITK.py in ReadImage(*args)\n   8874 \n   8875     \"\"\"\n-&gt; 8876     return _SimpleITK.ReadImage(*args)\n   8877 class ImageViewer(_object):\n   8878     \"\"\"\n\nRuntimeError: Exception thrown in SimpleITK ReadImage: /tmp/SimpleITK/Code/IO/src/sitkImageReaderBase.cxx:107:\nsitk::ERROR: Unable to determine ImageIO reader for \"../input/rsna-str-pulmonary-embolism-detection/train/1de539a67a3b/01acced4b6ab/1c561d99f444.dcm\"\n</code></pre>\n<p>I would appreciate some help on that!</p>",
      "rawMarkdown": "Hi @vaillant, I am in the process to implement that segmentation approach. It uses SimpleITK library and It seems this dataset has an issue with it. When a `dicom` file it throws this error but I could not know how to fix it. \n\n============================\nUpdate: \n\n [kernel](https://www.kaggle.com/smerllo/deep-learning-approach-for-lung-segmentation-unet) worked - Credit to ipan \n\n====================================\n\n```\n\nfrom lungmask import mask\nimport SimpleITK as sitk\nimg = sitk.ReadImage(example)\n\n\n```\n```\n---------------------------------------------------------------------------\nRuntimeError                              Traceback (most recent call last)\n<ipython-input-10-b63d2459c2bf> in <module>\n      1 from lungmask import mask\n      2 import SimpleITK as sitk\n----> 3 img = sitk.ReadImage(example)\n\n/opt/conda/lib/python3.7/site-packages/SimpleITK/SimpleITK.py in ReadImage(*args)\n   8874 \n   8875     \"\"\"\n-> 8876     return _SimpleITK.ReadImage(*args)\n   8877 class ImageViewer(_object):\n   8878     \"\"\"\n\nRuntimeError: Exception thrown in SimpleITK ReadImage: /tmp/SimpleITK/Code/IO/src/sitkImageReaderBase.cxx:107:\nsitk::ERROR: Unable to determine ImageIO reader for \"../input/rsna-str-pulmonary-embolism-detection/train/1de539a67a3b/01acced4b6ab/1c561d99f444.dcm\"\n```\n\nI would appreciate some help on that!",
      "replies": [
        {
          "id": 1012049,
          "postDate": "2020-09-15T21:48:53.537Z",
          "content": "<p>You can use this function:</p>\n<pre><code>import SimpleITK as sitk\nfrom lungmask import mask as lungmask_mask\n\ndef get_lung_mask(f): \n    series_IDs = sitk.ImageSeriesReader.GetGDCMSeriesIDs(f)\n    sorted_file_names = sitk.ImageSeriesReader.GetGDCMSeriesFileNames(f, series_IDs[0])\n    series_reader = sitk.ImageSeriesReader()\n    series_reader.SetFileNames(sorted_file_names)\n    series_reader.MetaDataDictionaryArrayUpdateOn()\n    series_reader.LoadPrivateTagsOn()\n    image = series_reader.Execute()\n    segmentation = (lungmask_mask.apply(image) &gt; 0).astype('uint8')\n    return segmentation, image, sorted_file_names\n</code></pre>\n<p><code>f</code> is the path to the folder containing the individual DICOM files. </p>",
          "rawMarkdown": "You can use this function:\n```\nimport SimpleITK as sitk\nfrom lungmask import mask as lungmask_mask\n\ndef get_lung_mask(f): \n    series_IDs = sitk.ImageSeriesReader.GetGDCMSeriesIDs(f)\n    sorted_file_names = sitk.ImageSeriesReader.GetGDCMSeriesFileNames(f, series_IDs[0])\n    series_reader = sitk.ImageSeriesReader()\n    series_reader.SetFileNames(sorted_file_names)\n    series_reader.MetaDataDictionaryArrayUpdateOn()\n    series_reader.LoadPrivateTagsOn()\n    image = series_reader.Execute()\n    segmentation = (lungmask_mask.apply(image) > 0).astype('uint8')\n    return segmentation, image, sorted_file_names\n```\n`f` is the path to the folder containing the individual DICOM files. ",
          "votes": 1
        },
        {
          "id": 1012126,
          "postDate": "2020-09-16T00:03:12.327Z",
          "rawMarkdown": "",
          "isDeleted": true
        }
      ]
    }
  ],
  "comments": [
    {
      "id": 1013005,
      "author_name": "Tsai29",
      "author_url": "",
      "post_date": "2020-09-16T13:04:08.190000",
      "content": "<p>Hi guys, I also public my CT lung segmentation model here. It was trained on several public datasets. Although it might can't have similar performance as the public repo in topic, but it has much faster inference time.<br>\n<a href=\"https://www.kaggle.com/xiejialun/lung-ct-scan-segmentation-model/comments\" target=\"_blank\">https://www.kaggle.com/xiejialun/lung-ct-scan-segmentation-model/comments</a></p>",
      "votes": 1,
      "replies": []
    },
    {
      "id": 1012013,
      "author_name": "sm_erlo",
      "author_url": "",
      "post_date": "2020-09-15T21:04:18.027000",
      "content": "<p>Hi <a href=\"https://www.kaggle.com/vaillant\" target=\"_blank\">@vaillant</a>, I am in the process to implement that segmentation approach. It uses SimpleITK library and It seems this dataset has an issue with it. When a <code>dicom</code> file it throws this error but I could not know how to fix it. </p>\n<p>============================<br>\nUpdate: </p>\n<p><a href=\"https://www.kaggle.com/smerllo/deep-learning-approach-for-lung-segmentation-unet\" target=\"_blank\">kernel</a> worked - Credit to ipan </p>\n<p>====================================</p>\n<pre><code>from lungmask import mask\nimport SimpleITK as sitk\nimg = sitk.ReadImage(example)\n</code></pre>\n<pre><code>---------------------------------------------------------------------------\nRuntimeError                              Traceback (most recent call last)\n&lt;ipython-input-10-b63d2459c2bf&gt; in &lt;module&gt;\n      1 from lungmask import mask\n      2 import SimpleITK as sitk\n----&gt; 3 img = sitk.ReadImage(example)\n\n/opt/conda/lib/python3.7/site-packages/SimpleITK/SimpleITK.py in ReadImage(*args)\n   8874 \n   8875     \"\"\"\n-&gt; 8876     return _SimpleITK.ReadImage(*args)\n   8877 class ImageViewer(_object):\n   8878     \"\"\"\n\nRuntimeError: Exception thrown in SimpleITK ReadImage: /tmp/SimpleITK/Code/IO/src/sitkImageReaderBase.cxx:107:\nsitk::ERROR: Unable to determine ImageIO reader for \"../input/rsna-str-pulmonary-embolism-detection/train/1de539a67a3b/01acced4b6ab/1c561d99f444.dcm\"\n</code></pre>\n<p>I would appreciate some help on that!</p>",
      "votes": 0,
      "replies": [
        {
          "id": 1012049,
          "author_name": "Ian Pan",
          "author_url": "",
          "post_date": "2020-09-15T21:48:53.537000",
          "content": "<p>You can use this function:</p>\n<pre><code>import SimpleITK as sitk\nfrom lungmask import mask as lungmask_mask\n\ndef get_lung_mask(f): \n    series_IDs = sitk.ImageSeriesReader.GetGDCMSeriesIDs(f)\n    sorted_file_names = sitk.ImageSeriesReader.GetGDCMSeriesFileNames(f, series_IDs[0])\n    series_reader = sitk.ImageSeriesReader()\n    series_reader.SetFileNames(sorted_file_names)\n    series_reader.MetaDataDictionaryArrayUpdateOn()\n    series_reader.LoadPrivateTagsOn()\n    image = series_reader.Execute()\n    segmentation = (lungmask_mask.apply(image) &gt; 0).astype('uint8')\n    return segmentation, image, sorted_file_names\n</code></pre>\n<p><code>f</code> is the path to the folder containing the individual DICOM files. </p>",
          "votes": 1,
          "replies": []
        },
        {
          "id": 1012126,
          "author_name": "",
          "author_url": "",
          "post_date": "2020-09-16T00:03:12.327000",
          "content": "",
          "votes": 0,
          "replies": []
        }
      ]
    }
  ],
  "raw_markdown_by_id": {
    "1011907": "I see some non-deep learning approaches for lung segmentation being used. In the presence of significant lung pathology, these will probably fail. \n\nI have found [https://github.com/JoHof/lungmask](https://github.com/JoHof/lungmask) to work very well and wanted to share it with all of you, in case you want to incorporate lung segmentation into your solution.",
    "1013005": "Hi guys, I also public my CT lung segmentation model here. It was trained on several public datasets. Although it might can't have similar performance as the public repo in topic, but it has much faster inference time.\nhttps://www.kaggle.com/xiejialun/lung-ct-scan-segmentation-model/comments",
    "1012013": "Hi @vaillant, I am in the process to implement that segmentation approach. It uses SimpleITK library and It seems this dataset has an issue with it. When a `dicom` file it throws this error but I could not know how to fix it. \n\n============================\nUpdate: \n\n [kernel](https://www.kaggle.com/smerllo/deep-learning-approach-for-lung-segmentation-unet) worked - Credit to ipan \n\n====================================\n\n```\n\nfrom lungmask import mask\nimport SimpleITK as sitk\nimg = sitk.ReadImage(example)\n\n\n```\n```\n---------------------------------------------------------------------------\nRuntimeError                              Traceback (most recent call last)\n<ipython-input-10-b63d2459c2bf> in <module>\n      1 from lungmask import mask\n      2 import SimpleITK as sitk\n----> 3 img = sitk.ReadImage(example)\n\n/opt/conda/lib/python3.7/site-packages/SimpleITK/SimpleITK.py in ReadImage(*args)\n   8874 \n   8875     \"\"\"\n-> 8876     return _SimpleITK.ReadImage(*args)\n   8877 class ImageViewer(_object):\n   8878     \"\"\"\n\nRuntimeError: Exception thrown in SimpleITK ReadImage: /tmp/SimpleITK/Code/IO/src/sitkImageReaderBase.cxx:107:\nsitk::ERROR: Unable to determine ImageIO reader for \"../input/rsna-str-pulmonary-embolism-detection/train/1de539a67a3b/01acced4b6ab/1c561d99f444.dcm\"\n```\n\nI would appreciate some help on that!"
  }
}