{
  "id": 341187,
  "title": "Problem reading dicom files",
  "url": "/competitions/rsna-2022-cervical-spine-fracture-detection/discussion/341187",
  "author_name": "Bartek Sadlej",
  "post_date": "2022-08-01T17:24:12.439000",
  "votes": 3,
  "comment_count": 4,
  "views": 0,
  "content": "<p>I came across a problem while reading dicom images.<br>\nI use this code from <a href=\"https://www.kaggle.com/code/raddar/convert-dicom-to-np-array-the-correct-way\" target=\"_blank\">https://www.kaggle.com/code/raddar/convert-dicom-to-np-array-the-correct-way</a></p>\n<p>`def read_xray(path, voi_lut = True, fix_monochrome = True):<br>\n    dicom = pydicom.dcmread(path)</p>\n<pre><code># VOI LUT (if available by DICOM device) is used to transform raw DICOM data to \"human-friendly\" view\nif voi_lut:\n    data = apply_voi_lut(dicom.pixel_array, dicom)\nelse:\n    data = dicom.pixel_array\n\n# depending on this value, X-ray may look inverted - fix that:\nif fix_monochrome and dicom.PhotometricInterpretation == \"MONOCHROME1\":\n    data = np.amax(data) - data\n\ndata = data - np.min(data)\ndata = data / np.max(data)\ndata = (data * 255).astype(np.uint8)\n\nreturn data`\n</code></pre>\n<p>and I get this error</p>\n<p><code>The following handlers are available to decode the pixel data however they are missing required dependencies: GDCM (req. GDCM), pylibjpeg (req. )</code></p>\n<p>I tried many solutions found in google and could not solve it.<br>\nFor example<br>\n<code>!pip install -U gdcm\n !pip install -U pylibjpeg[all]</code><br>\nTried to install gdcm, pylibjpeg[all].<br>\nSome of them throw different errors but also related to those libraries.<br>\nThanks for help.</p>",
  "messages": [
    {
      "id": 1880603,
      "postDate": "2022-08-01T21:10:37.683Z",
      "content": "<p>Add this dataset to your notebook: <a href=\"https://www.kaggle.com/datasets/ipythonx/for-pydicom\" target=\"_blank\">https://www.kaggle.com/datasets/ipythonx/for-pydicom</a></p>\n<p>Add this to your notebook (before importing pydicom): <code>!pip install -qU ../input/for-pydicom/python_gdcm-3.0.14-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl ../input/for-pydicom/pylibjpeg-1.4.0-py3-none-any.whl --find-links frozen_packages --no-index</code></p>\n<p>It will be necessary to do it this way because your notebook cannot be connected to the internet when you make a submission, so these libraries need to be installed from a Kaggle Dataset.</p>",
      "rawMarkdown": "Add this dataset to your notebook: https://www.kaggle.com/datasets/ipythonx/for-pydicom\n\nAdd this to your notebook (before importing pydicom): `!pip install -qU ../input/for-pydicom/python_gdcm-3.0.14-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl ../input/for-pydicom/pylibjpeg-1.4.0-py3-none-any.whl --find-links frozen_packages --no-index`\n\nIt will be necessary to do it this way because your notebook cannot be connected to the internet when you make a submission, so these libraries need to be installed from a Kaggle Dataset.",
      "votes": 6,
      "replies": [
        {
          "id": 1881047,
          "postDate": "2022-08-02T07:59:23.700Z",
          "content": "<p>Thanks a lot! It solved my problem.</p>",
          "rawMarkdown": "Thanks a lot! It solved my problem.",
          "votes": 1
        },
        {
          "id": 1895186,
          "postDate": "2022-08-12T02:30:56.143Z",
          "content": "<p>I tried this but still get the error:<br>\n<code>The following handlers are available to decode the pixel data however they are missing required dependencies: pylibjpeg (req. ), GDCM (req. )</code><br>\nI did not import the modules, as that was not needed when running locally.  </p>",
          "rawMarkdown": "I tried this but still get the error:\n```The following handlers are available to decode the pixel data however they are missing required dependencies: pylibjpeg (req. ), GDCM (req. )```\nI did not import the modules, as that was not needed when running locally.  ",
          "votes": 1
        }
      ]
    },
    {
      "id": 1880396,
      "postDate": "2022-08-01T17:24:12.440Z",
      "content": "<p>I came across a problem while reading dicom images.<br>\nI use this code from <a href=\"https://www.kaggle.com/code/raddar/convert-dicom-to-np-array-the-correct-way\" target=\"_blank\">https://www.kaggle.com/code/raddar/convert-dicom-to-np-array-the-correct-way</a></p>\n<p>`def read_xray(path, voi_lut = True, fix_monochrome = True):<br>\n    dicom = pydicom.dcmread(path)</p>\n<pre><code># VOI LUT (if available by DICOM device) is used to transform raw DICOM data to \"human-friendly\" view\nif voi_lut:\n    data = apply_voi_lut(dicom.pixel_array, dicom)\nelse:\n    data = dicom.pixel_array\n\n# depending on this value, X-ray may look inverted - fix that:\nif fix_monochrome and dicom.PhotometricInterpretation == \"MONOCHROME1\":\n    data = np.amax(data) - data\n\ndata = data - np.min(data)\ndata = data / np.max(data)\ndata = (data * 255).astype(np.uint8)\n\nreturn data`\n</code></pre>\n<p>and I get this error</p>\n<p><code>The following handlers are available to decode the pixel data however they are missing required dependencies: GDCM (req. GDCM), pylibjpeg (req. )</code></p>\n<p>I tried many solutions found in google and could not solve it.<br>\nFor example<br>\n<code>!pip install -U gdcm\n !pip install -U pylibjpeg[all]</code><br>\nTried to install gdcm, pylibjpeg[all].<br>\nSome of them throw different errors but also related to those libraries.<br>\nThanks for help.</p>",
      "rawMarkdown": "I came across a problem while reading dicom images.\nI use this code from https://www.kaggle.com/code/raddar/convert-dicom-to-np-array-the-correct-way\n\n`def read_xray(path, voi_lut = True, fix_monochrome = True):\n    dicom = pydicom.dcmread(path)\n    \n    # VOI LUT (if available by DICOM device) is used to transform raw DICOM data to \"human-friendly\" view\n    if voi_lut:\n        data = apply_voi_lut(dicom.pixel_array, dicom)\n    else:\n        data = dicom.pixel_array\n               \n    # depending on this value, X-ray may look inverted - fix that:\n    if fix_monochrome and dicom.PhotometricInterpretation == \"MONOCHROME1\":\n        data = np.amax(data) - data\n        \n    data = data - np.min(data)\n    data = data / np.max(data)\n    data = (data * 255).astype(np.uint8)\n        \n    return data`\n\nand I get this error\n\n`The following handlers are available to decode the pixel data however they are missing required dependencies: GDCM (req. GDCM), pylibjpeg (req. )`\n\nI tried many solutions found in google and could not solve it.\nFor example\n` !pip install -U gdcm\n !pip install -U pylibjpeg[all]`\nTried to install gdcm, pylibjpeg[all].\nSome of them throw different errors but also related to those libraries.\nThanks for help.",
      "votes": 3
    },
    {
      "id": 1885567,
      "postDate": "2022-08-05T09:00:20.610Z",
      "content": "<p>I sugesst you can use <em>SimpleITK</em>, for some dic files maybe you will get <em>GDCM read error</em>, so I choose <em>SimpleITK</em>. If you also get this error, I post the SimpleITK code in this notebook <a href=\"https://www.kaggle.com/code/handsomeevy/data-pre-processing-for-rsna\" target=\"_blank\">data pre-processing for RSNA</a>. I hope it can help you.</p>",
      "rawMarkdown": "I sugesst you can use *SimpleITK*, for some dic files maybe you will get *GDCM read error*, so I choose *SimpleITK*. If you also get this error, I post the SimpleITK code in this notebook [data pre-processing for RSNA](https://www.kaggle.com/code/handsomeevy/data-pre-processing-for-rsna). I hope it can help you."
    }
  ],
  "comments": [
    {
      "id": 1880603,
      "author_name": "Branden Murray",
      "author_url": "",
      "post_date": "2022-08-01T21:10:37.683000",
      "content": "<p>Add this dataset to your notebook: <a href=\"https://www.kaggle.com/datasets/ipythonx/for-pydicom\" target=\"_blank\">https://www.kaggle.com/datasets/ipythonx/for-pydicom</a></p>\n<p>Add this to your notebook (before importing pydicom): <code>!pip install -qU ../input/for-pydicom/python_gdcm-3.0.14-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl ../input/for-pydicom/pylibjpeg-1.4.0-py3-none-any.whl --find-links frozen_packages --no-index</code></p>\n<p>It will be necessary to do it this way because your notebook cannot be connected to the internet when you make a submission, so these libraries need to be installed from a Kaggle Dataset.</p>",
      "votes": 6,
      "replies": [
        {
          "id": 1881047,
          "author_name": "Bartek Sadlej",
          "author_url": "",
          "post_date": "2022-08-02T07:59:23.700000",
          "content": "<p>Thanks a lot! It solved my problem.</p>",
          "votes": 1,
          "replies": []
        },
        {
          "id": 1895186,
          "author_name": "SolverWorld",
          "author_url": "",
          "post_date": "2022-08-12T02:30:56.143000",
          "content": "<p>I tried this but still get the error:<br>\n<code>The following handlers are available to decode the pixel data however they are missing required dependencies: pylibjpeg (req. ), GDCM (req. )</code><br>\nI did not import the modules, as that was not needed when running locally.  </p>",
          "votes": 1,
          "replies": []
        }
      ]
    },
    {
      "id": 1885567,
      "author_name": "柯慕灵",
      "author_url": "",
      "post_date": "2022-08-05T09:00:20.610000",
      "content": "<p>I sugesst you can use <em>SimpleITK</em>, for some dic files maybe you will get <em>GDCM read error</em>, so I choose <em>SimpleITK</em>. If you also get this error, I post the SimpleITK code in this notebook <a href=\"https://www.kaggle.com/code/handsomeevy/data-pre-processing-for-rsna\" target=\"_blank\">data pre-processing for RSNA</a>. I hope it can help you.</p>",
      "votes": 0,
      "replies": []
    }
  ],
  "raw_markdown_by_id": {
    "1880603": "Add this dataset to your notebook: https://www.kaggle.com/datasets/ipythonx/for-pydicom\n\nAdd this to your notebook (before importing pydicom): `!pip install -qU ../input/for-pydicom/python_gdcm-3.0.14-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl ../input/for-pydicom/pylibjpeg-1.4.0-py3-none-any.whl --find-links frozen_packages --no-index`\n\nIt will be necessary to do it this way because your notebook cannot be connected to the internet when you make a submission, so these libraries need to be installed from a Kaggle Dataset.",
    "1880396": "I came across a problem while reading dicom images.\nI use this code from https://www.kaggle.com/code/raddar/convert-dicom-to-np-array-the-correct-way\n\n`def read_xray(path, voi_lut = True, fix_monochrome = True):\n    dicom = pydicom.dcmread(path)\n    \n    # VOI LUT (if available by DICOM device) is used to transform raw DICOM data to \"human-friendly\" view\n    if voi_lut:\n        data = apply_voi_lut(dicom.pixel_array, dicom)\n    else:\n        data = dicom.pixel_array\n               \n    # depending on this value, X-ray may look inverted - fix that:\n    if fix_monochrome and dicom.PhotometricInterpretation == \"MONOCHROME1\":\n        data = np.amax(data) - data\n        \n    data = data - np.min(data)\n    data = data / np.max(data)\n    data = (data * 255).astype(np.uint8)\n        \n    return data`\n\nand I get this error\n\n`The following handlers are available to decode the pixel data however they are missing required dependencies: GDCM (req. GDCM), pylibjpeg (req. )`\n\nI tried many solutions found in google and could not solve it.\nFor example\n` !pip install -U gdcm\n !pip install -U pylibjpeg[all]`\nTried to install gdcm, pylibjpeg[all].\nSome of them throw different errors but also related to those libraries.\nThanks for help.",
    "1885567": "I sugesst you can use *SimpleITK*, for some dic files maybe you will get *GDCM read error*, so I choose *SimpleITK*. If you also get this error, I post the SimpleITK code in this notebook [data pre-processing for RSNA](https://www.kaggle.com/code/handsomeevy/data-pre-processing-for-rsna). I hope it can help you."
  }
}