{
  "id": 211855,
  "title": "Doubts With DICOM",
  "url": "/competitions/vinbigdata-chest-xray-abnormalities-detection/discussion/211855",
  "author_name": "Aditya Baurai",
  "post_date": "2021-01-16T14:51:53.851000",
  "votes": 3,
  "comment_count": 6,
  "views": 0,
  "content": "<p>This code has been incredibly praised for working with DICOMS. However, I have a few doubts and would really appreciate if someone could explain them in depth.</p>\n<h6>#</h6>\n<pre><code> def read_xray(path, voi_lut = True, fix_monochrome = True) : \n\ndicom = pydicom.read_file(path)\n# VOI LUT (if available by DICOM device) is used to transform raw DICOM data to \"human-friendly\" view\nif voi_lut == True : \n    data = apply_voi_lut(dicom.pixel_array, dicom)\nelse:\n    data = dicom.pixel_array\n\nif fix_monochrome == True and dicom.PhototmetricInterpretation == \"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<h6>#</h6>\n<p>Code from : <a href=\"https://www.kaggle.com/raddar/convert-dicom-to-np-array-the-correct-way\" target=\"_blank\">raddar's notebook</a></p>\n<p>Following are the doubts : </p>\n<ul>\n<li>Need/significance of VOI LUT? What is it doing and what will happen if I simply read the file using the read_file( ) method of pydicom and skip the VOI LUT condition check.</li>\n<li>What is the need for fix_monochrome? What's its impact? </li>\n</ul>\n<p>Thank you !<br>\nAditya</p>",
  "messages": [
    {
      "id": 1155995,
      "postDate": "2021-01-16T20:33:53.817Z",
      "content": "<p><a href=\"https://www.kaggle.com/fireheart7\" target=\"_blank\">@fireheart7</a> after poking around various sources, my understanding is that it looks like VOI LUT (Value of Interest Lookup Table) fields describe some sort of transformation that is applied to the raw pixel values that you see in the <code>pixel_array</code>. VOI LUTs are used to tweak the image being displayed either for print or display (e.g. tweaking pixel intensities). It's uncertain if the radiologists viewed the image with a VOI LUT applied or not - it appears as if this may be specific to the display modality (e.g. print or display) and technology manufacturer. In other words, there may be some sort of transformation applied to the pixels that change the image contents and may impact visibility of certain elements. You may want to explore both interpretations of the pixel data - with the VOI LUT applied and without - and see how that impacts your overall model.</p>\n<p>References:</p>\n<ul>\n<li><a href=\"http://dicom.nema.org/medical/dicom/current/output/chtml/part03/chapter_A.html#sect_A.1.2.6.3\" target=\"_blank\">A Composite Information Object Definitions (Normative)</a></li>\n<li><a href=\"https://help.accusoft.com/ImageGear/v17.2/Windows/DLL/topic468.html\" target=\"_blank\">Displaying Medical Grayscale Images</a></li>\n<li><a href=\"https://otechimg.com/otpedia/entryDetails.cfm?id=223\" target=\"_blank\">Look Up Table (LUT)</a></li>\n<li><a href=\"https://mevislabdownloads.mevis.de/docs/current/MeVisLab/Standard/Documentation/Publish/ModuleReference/DicomLUT.html\" target=\"_blank\">DicomLUT</a></li>\n</ul>",
      "rawMarkdown": "@fireheart7 after poking around various sources, my understanding is that it looks like VOI LUT (Value of Interest Lookup Table) fields describe some sort of transformation that is applied to the raw pixel values that you see in the `pixel_array`. VOI LUTs are used to tweak the image being displayed either for print or display (e.g. tweaking pixel intensities). It's uncertain if the radiologists viewed the image with a VOI LUT applied or not - it appears as if this may be specific to the display modality (e.g. print or display) and technology manufacturer. In other words, there may be some sort of transformation applied to the pixels that change the image contents and may impact visibility of certain elements. You may want to explore both interpretations of the pixel data - with the VOI LUT applied and without - and see how that impacts your overall model.\n\nReferences:\n\n* [A Composite Information Object Definitions (Normative)](http://dicom.nema.org/medical/dicom/current/output/chtml/part03/chapter_A.html#sect_A.1.2.6.3)\n* [Displaying Medical Grayscale Images](https://help.accusoft.com/ImageGear/v17.2/Windows/DLL/topic468.html)\n* [Look Up Table (LUT)](https://otechimg.com/otpedia/entryDetails.cfm?id=223)\n* [DicomLUT](https://mevislabdownloads.mevis.de/docs/current/MeVisLab/Standard/Documentation/Publish/ModuleReference/DicomLUT.html)",
      "votes": 3,
      "replies": [
        {
          "id": 1159291,
          "postDate": "2021-01-19T07:13:19.400Z",
          "content": "<p>thank you! I also came concluded this only after doing research of my own. </p>",
          "rawMarkdown": "thank you! I also came concluded this only after doing research of my own. ",
          "votes": 1
        }
      ]
    },
    {
      "id": 1155658,
      "postDate": "2021-01-16T14:51:53.853Z",
      "content": "<p>This code has been incredibly praised for working with DICOMS. However, I have a few doubts and would really appreciate if someone could explain them in depth.</p>\n<h6>#</h6>\n<pre><code> def read_xray(path, voi_lut = True, fix_monochrome = True) : \n\ndicom = pydicom.read_file(path)\n# VOI LUT (if available by DICOM device) is used to transform raw DICOM data to \"human-friendly\" view\nif voi_lut == True : \n    data = apply_voi_lut(dicom.pixel_array, dicom)\nelse:\n    data = dicom.pixel_array\n\nif fix_monochrome == True and dicom.PhototmetricInterpretation == \"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<h6>#</h6>\n<p>Code from : <a href=\"https://www.kaggle.com/raddar/convert-dicom-to-np-array-the-correct-way\" target=\"_blank\">raddar's notebook</a></p>\n<p>Following are the doubts : </p>\n<ul>\n<li>Need/significance of VOI LUT? What is it doing and what will happen if I simply read the file using the read_file( ) method of pydicom and skip the VOI LUT condition check.</li>\n<li>What is the need for fix_monochrome? What's its impact? </li>\n</ul>\n<p>Thank you !<br>\nAditya</p>",
      "rawMarkdown": "This code has been incredibly praised for working with DICOMS. However, I have a few doubts and would really appreciate if someone could explain them in depth.\n\n#########################################################################\n\n     def read_xray(path, voi_lut = True, fix_monochrome = True) : \n\n    dicom = pydicom.read_file(path)\n    # VOI LUT (if available by DICOM device) is used to transform raw DICOM data to \"human-friendly\" view\n    if voi_lut == True : \n        data = apply_voi_lut(dicom.pixel_array, dicom)\n    else:\n        data = dicom.pixel_array\n    \n    if fix_monochrome == True and dicom.PhototmetricInterpretation == \"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#########################################################################\nCode from : [raddar's notebook](https://www.kaggle.com/raddar/convert-dicom-to-np-array-the-correct-way)\n\nFollowing are the doubts : \n- Need/significance of VOI LUT? What is it doing and what will happen if I simply read the file using the read_file( ) method of pydicom and skip the VOI LUT condition check.\n- What is the need for fix_monochrome? What's its impact? \n\nThank you !\nAditya",
      "votes": 3
    },
    {
      "id": 1155852,
      "postDate": "2021-01-16T18:00:08.537Z",
      "content": "<p>I don't know about VOI LUT, but regarding fix_monochrome, we use that since .dcm images contains many shades of grey and black in it. Hence, to bring down it to the same level (normalize), we do this. It helps in getting better insights from the medical images :)</p>",
      "rawMarkdown": "I don't know about VOI LUT, but regarding fix_monochrome, we use that since .dcm images contains many shades of grey and black in it. Hence, to bring down it to the same level (normalize), we do this. It helps in getting better insights from the medical images :)",
      "votes": 1,
      "replies": [
        {
          "id": 1159292,
          "postDate": "2021-01-19T07:13:56.273Z",
          "content": "<p>This is indeed helpful! Thank you for this</p>",
          "rawMarkdown": "This is indeed helpful! Thank you for this"
        }
      ]
    },
    {
      "id": 1157539,
      "postDate": "2021-01-18T02:04:59.017Z",
      "content": "<p>After a few frustrating hours trying to figure out why some image were inverted and how to remedy them, I discovered that fix_monochrome is needed because the MONOCHROME2 images have intensities inverted vs MONOCHROME1. One goes from 0=air to XXXX=bone, while the other goes from 0=bone to XXXX=air.</p>\n<p>Hence why the operation <code>data = np.amax(data) - data</code> is needed.</p>",
      "rawMarkdown": "After a few frustrating hours trying to figure out why some image were inverted and how to remedy them, I discovered that fix_monochrome is needed because the MONOCHROME2 images have intensities inverted vs MONOCHROME1. One goes from 0=air to XXXX=bone, while the other goes from 0=bone to XXXX=air.\n\nHence why the operation `data = np.amax(data) - data` is needed.",
      "replies": [
        {
          "id": 1159295,
          "postDate": "2021-01-19T07:14:37.413Z",
          "content": "<p>Understood. Thank you for bringing light to this!</p>",
          "rawMarkdown": "Understood. Thank you for bringing light to this!"
        }
      ]
    }
  ],
  "comments": [
    {
      "id": 1155995,
      "author_name": "Craig Thomas",
      "author_url": "",
      "post_date": "2021-01-16T20:33:53.817000",
      "content": "<p><a href=\"https://www.kaggle.com/fireheart7\" target=\"_blank\">@fireheart7</a> after poking around various sources, my understanding is that it looks like VOI LUT (Value of Interest Lookup Table) fields describe some sort of transformation that is applied to the raw pixel values that you see in the <code>pixel_array</code>. VOI LUTs are used to tweak the image being displayed either for print or display (e.g. tweaking pixel intensities). It's uncertain if the radiologists viewed the image with a VOI LUT applied or not - it appears as if this may be specific to the display modality (e.g. print or display) and technology manufacturer. In other words, there may be some sort of transformation applied to the pixels that change the image contents and may impact visibility of certain elements. You may want to explore both interpretations of the pixel data - with the VOI LUT applied and without - and see how that impacts your overall model.</p>\n<p>References:</p>\n<ul>\n<li><a href=\"http://dicom.nema.org/medical/dicom/current/output/chtml/part03/chapter_A.html#sect_A.1.2.6.3\" target=\"_blank\">A Composite Information Object Definitions (Normative)</a></li>\n<li><a href=\"https://help.accusoft.com/ImageGear/v17.2/Windows/DLL/topic468.html\" target=\"_blank\">Displaying Medical Grayscale Images</a></li>\n<li><a href=\"https://otechimg.com/otpedia/entryDetails.cfm?id=223\" target=\"_blank\">Look Up Table (LUT)</a></li>\n<li><a href=\"https://mevislabdownloads.mevis.de/docs/current/MeVisLab/Standard/Documentation/Publish/ModuleReference/DicomLUT.html\" target=\"_blank\">DicomLUT</a></li>\n</ul>",
      "votes": 3,
      "replies": [
        {
          "id": 1159291,
          "author_name": "Aditya Baurai",
          "author_url": "",
          "post_date": "2021-01-19T07:13:19.400000",
          "content": "<p>thank you! I also came concluded this only after doing research of my own. </p>",
          "votes": 1,
          "replies": []
        }
      ]
    },
    {
      "id": 1155852,
      "author_name": "Manish Sharma",
      "author_url": "",
      "post_date": "2021-01-16T18:00:08.537000",
      "content": "<p>I don't know about VOI LUT, but regarding fix_monochrome, we use that since .dcm images contains many shades of grey and black in it. Hence, to bring down it to the same level (normalize), we do this. It helps in getting better insights from the medical images :)</p>",
      "votes": 1,
      "replies": [
        {
          "id": 1159292,
          "author_name": "Aditya Baurai",
          "author_url": "",
          "post_date": "2021-01-19T07:13:56.273000",
          "content": "<p>This is indeed helpful! Thank you for this</p>",
          "votes": 0,
          "replies": []
        }
      ]
    },
    {
      "id": 1157539,
      "author_name": "matthew choo",
      "author_url": "",
      "post_date": "2021-01-18T02:04:59.017000",
      "content": "<p>After a few frustrating hours trying to figure out why some image were inverted and how to remedy them, I discovered that fix_monochrome is needed because the MONOCHROME2 images have intensities inverted vs MONOCHROME1. One goes from 0=air to XXXX=bone, while the other goes from 0=bone to XXXX=air.</p>\n<p>Hence why the operation <code>data = np.amax(data) - data</code> is needed.</p>",
      "votes": 0,
      "replies": [
        {
          "id": 1159295,
          "author_name": "Aditya Baurai",
          "author_url": "",
          "post_date": "2021-01-19T07:14:37.413000",
          "content": "<p>Understood. Thank you for bringing light to this!</p>",
          "votes": 0,
          "replies": []
        }
      ]
    }
  ],
  "raw_markdown_by_id": {
    "1155995": "@fireheart7 after poking around various sources, my understanding is that it looks like VOI LUT (Value of Interest Lookup Table) fields describe some sort of transformation that is applied to the raw pixel values that you see in the `pixel_array`. VOI LUTs are used to tweak the image being displayed either for print or display (e.g. tweaking pixel intensities). It's uncertain if the radiologists viewed the image with a VOI LUT applied or not - it appears as if this may be specific to the display modality (e.g. print or display) and technology manufacturer. In other words, there may be some sort of transformation applied to the pixels that change the image contents and may impact visibility of certain elements. You may want to explore both interpretations of the pixel data - with the VOI LUT applied and without - and see how that impacts your overall model.\n\nReferences:\n\n* [A Composite Information Object Definitions (Normative)](http://dicom.nema.org/medical/dicom/current/output/chtml/part03/chapter_A.html#sect_A.1.2.6.3)\n* [Displaying Medical Grayscale Images](https://help.accusoft.com/ImageGear/v17.2/Windows/DLL/topic468.html)\n* [Look Up Table (LUT)](https://otechimg.com/otpedia/entryDetails.cfm?id=223)\n* [DicomLUT](https://mevislabdownloads.mevis.de/docs/current/MeVisLab/Standard/Documentation/Publish/ModuleReference/DicomLUT.html)",
    "1155658": "This code has been incredibly praised for working with DICOMS. However, I have a few doubts and would really appreciate if someone could explain them in depth.\n\n#########################################################################\n\n     def read_xray(path, voi_lut = True, fix_monochrome = True) : \n\n    dicom = pydicom.read_file(path)\n    # VOI LUT (if available by DICOM device) is used to transform raw DICOM data to \"human-friendly\" view\n    if voi_lut == True : \n        data = apply_voi_lut(dicom.pixel_array, dicom)\n    else:\n        data = dicom.pixel_array\n    \n    if fix_monochrome == True and dicom.PhototmetricInterpretation == \"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#########################################################################\nCode from : [raddar's notebook](https://www.kaggle.com/raddar/convert-dicom-to-np-array-the-correct-way)\n\nFollowing are the doubts : \n- Need/significance of VOI LUT? What is it doing and what will happen if I simply read the file using the read_file( ) method of pydicom and skip the VOI LUT condition check.\n- What is the need for fix_monochrome? What's its impact? \n\nThank you !\nAditya",
    "1155852": "I don't know about VOI LUT, but regarding fix_monochrome, we use that since .dcm images contains many shades of grey and black in it. Hence, to bring down it to the same level (normalize), we do this. It helps in getting better insights from the medical images :)",
    "1157539": "After a few frustrating hours trying to figure out why some image were inverted and how to remedy them, I discovered that fix_monochrome is needed because the MONOCHROME2 images have intensities inverted vs MONOCHROME1. One goes from 0=air to XXXX=bone, while the other goes from 0=bone to XXXX=air.\n\nHence why the operation `data = np.amax(data) - data` is needed."
  }
}