{
  "id": 177285,
  "title": "Not understanding DICOM",
  "url": "/competitions/osic-pulmonary-fibrosis-progression/discussion/177285",
  "author_name": "Aditya Baurai",
  "post_date": "2020-08-25T11:33:06.045000",
  "votes": 14,
  "comment_count": 15,
  "views": 0,
  "content": "<p>Hello folks!</p>\n<p>I have a couple of questions regarding DICOM image format, as it's new for me.</p>\n<ol>\n<li><p>In the reading part, what's the purpose of writing image.pixel_array ?? What does it do? Is it something similar to .flatten() function applied on a 3-D image tensor using Numpy?</p></li>\n<li><p>I found image mean using np.mean(image) and it appeared to be negative. Do I need to rescale the values of DICOM too, if they go negative.</p></li>\n</ol>\n<p>Can anyone kindly refer me to some good dicom resources, as nothing much is explained in theor documentation. It's just a lot of code….</p>\n<p>Thank You<br>\n~ Aditya Baurai </p>\n<hr>\n<p><strong>UPDATED Query II</strong></p>\n<p><strong>At one point while going through many kernels processing dicoms</strong> ;</p>\n<p>many folks have written this</p>\n<p><strong>image[image == 2000] = 0</strong> ~~ Setting air to zero when intercept = -1024 and slope = -1</p>\n<p>However, I found online that HU are obtained :</p>\n<p>HU = image voxel value * slope + intercept</p>\n<p><strong>How is that statement written then? image[image == 2000] = 0 ; why 2000? What's the basis of this conversion</strong>?</p>\n<hr>",
  "messages": [
    {
      "id": 984937,
      "postDate": "2020-08-25T11:33:06.047Z",
      "content": "<p>Hello folks!</p>\n<p>I have a couple of questions regarding DICOM image format, as it's new for me.</p>\n<ol>\n<li><p>In the reading part, what's the purpose of writing image.pixel_array ?? What does it do? Is it something similar to .flatten() function applied on a 3-D image tensor using Numpy?</p></li>\n<li><p>I found image mean using np.mean(image) and it appeared to be negative. Do I need to rescale the values of DICOM too, if they go negative.</p></li>\n</ol>\n<p>Can anyone kindly refer me to some good dicom resources, as nothing much is explained in theor documentation. It's just a lot of code….</p>\n<p>Thank You<br>\n~ Aditya Baurai </p>\n<hr>\n<p><strong>UPDATED Query II</strong></p>\n<p><strong>At one point while going through many kernels processing dicoms</strong> ;</p>\n<p>many folks have written this</p>\n<p><strong>image[image == 2000] = 0</strong> ~~ Setting air to zero when intercept = -1024 and slope = -1</p>\n<p>However, I found online that HU are obtained :</p>\n<p>HU = image voxel value * slope + intercept</p>\n<p><strong>How is that statement written then? image[image == 2000] = 0 ; why 2000? What's the basis of this conversion</strong>?</p>\n<hr>",
      "rawMarkdown": "Hello folks!\n\nI have a couple of questions regarding DICOM image format, as it's new for me.\n\n1. In the reading part, what's the purpose of writing image.pixel_array ?? What does it do? Is it something similar to .flatten() function applied on a 3-D image tensor using Numpy?\n\n2. I found image mean using np.mean(image) and it appeared to be negative. Do I need to rescale the values of DICOM too, if they go negative.\n\nCan anyone kindly refer me to some good dicom resources, as nothing much is explained in theor documentation. It's just a lot of code....\n\nThank You\n~ Aditya Baurai \n\n\n*************************************\n**UPDATED Query II**\n\n**At one point while going through many kernels processing dicoms** ;\n\nmany folks have written this\n\n**image[image == 2000] = 0** ~~ Setting air to zero when intercept = -1024 and slope = -1\n\nHowever, I found online that HU are obtained :\n\nHU = image voxel value * slope + intercept\n\n**How is that statement written then? image[image == 2000] = 0 ; why 2000? What's the basis of this conversion**?\n\n************************************************",
      "votes": 13
    },
    {
      "id": 986745,
      "postDate": "2020-08-26T18:34:01.567Z",
      "content": "<p>Hi <a href=\"https://www.kaggle.com/fireheart7\" target=\"_blank\">@fireheart7</a> , </p>\n<p>given a patient there are several slices of a 3D-scan each given as a dicom file. Within this file you can find the pixel_array that holds raw values of radiodensity. This quantity describes how much x-rays are absorbed and for this reason attenuated by an object or tissue. As the spectral composition of these x-rays can differ from scanner to scanner (patient to patient) you need to rescale these raw values to hounsfield units. </p>\n<p>For this rescaling you can fine the attributes Rescale Intercept and Slope in a dicom file. After that the value of air is -1000 and the value of water 0. Lungs have values close to -500. You can find a list here as well: <a href=\"https://en.wikipedia.org/wiki/Hounsfield_scale\" target=\"_blank\">https://en.wikipedia.org/wiki/Hounsfield_scale</a></p>\n<p>There are further important attributes in the dicom file like pixelspacing and slice thickness that can tell you how much physical distance is covered by a single slice scan. </p>\n<p>I'm working on a tutorial that perhaps helps you to understand dicom files better and to generate a preprocessed dataset out of it: <a href=\"https://www.kaggle.com/allunia/pulmonary-fibrosis-dicom-preprocessing\" target=\"_blank\">https://www.kaggle.com/allunia/pulmonary-fibrosis-dicom-preprocessing</a></p>\n<p>Take a look at it if you like. ;-) </p>\n<p>I can also recommend to take a look at old competitions that used dicom. The last I played with it was this one that also has several notebooks that show how to deal with dicom files: <a href=\"https://www.kaggle.com/c/rsna-intracranial-hemorrhage-detection/notebooks\" target=\"_blank\">https://www.kaggle.com/c/rsna-intracranial-hemorrhage-detection/notebooks</a></p>\n<p>I hope my answer was helpful. :-)</p>",
      "rawMarkdown": "Hi @fireheart7 , \n\ngiven a patient there are several slices of a 3D-scan each given as a dicom file. Within this file you can find the pixel_array that holds raw values of radiodensity. This quantity describes how much x-rays are absorbed and for this reason attenuated by an object or tissue. As the spectral composition of these x-rays can differ from scanner to scanner (patient to patient) you need to rescale these raw values to hounsfield units. \n\nFor this rescaling you can fine the attributes Rescale Intercept and Slope in a dicom file. After that the value of air is -1000 and the value of water 0. Lungs have values close to -500. You can find a list here as well: https://en.wikipedia.org/wiki/Hounsfield_scale\n\nThere are further important attributes in the dicom file like pixelspacing and slice thickness that can tell you how much physical distance is covered by a single slice scan. \n\nI'm working on a tutorial that perhaps helps you to understand dicom files better and to generate a preprocessed dataset out of it: https://www.kaggle.com/allunia/pulmonary-fibrosis-dicom-preprocessing\n\nTake a look at it if you like. ;-) \n\nI can also recommend to take a look at old competitions that used dicom. The last I played with it was this one that also has several notebooks that show how to deal with dicom files: https://www.kaggle.com/c/rsna-intracranial-hemorrhage-detection/notebooks\n\nI hope my answer was helpful. :-)",
      "votes": 11,
      "replies": [
        {
          "id": 987371,
          "postDate": "2020-08-27T07:49:35.050Z",
          "content": "<p>Thank you so much <a href=\"https://www.kaggle.com/allunia\" target=\"_blank\">@allunia</a> !! This is very insightful ~~</p>",
          "rawMarkdown": "Thank you so much @allunia !! This is very insightful ~~",
          "votes": 1
        },
        {
          "id": 987372,
          "postDate": "2020-08-27T07:51:24.160Z",
          "rawMarkdown": "",
          "isDeleted": true
        },
        {
          "id": 989964,
          "postDate": "2020-08-29T08:38:58.073Z",
          "content": "<p>At one point while going through many kernels processing dicoms ; </p>\n<p>many folks have written this</p>\n<p>image[image == 2000] = 0 ~~ Setting air to zero when intercept = -1024 and slope = -1</p>\n<p>However, I found online that HU are obtained :</p>\n<p>HU = image voxel value * slope + intercept</p>\n<p>How is that statement written then? image[image == 2000] = 0 ; why 2000? What's the basis of this conversion?</p>",
          "rawMarkdown": "At one point while going through many kernels processing dicoms ; \n\nmany folks have written this\n\nimage[image == 2000] = 0 ~~ Setting air to zero when intercept = -1024 and slope = -1\n\nHowever, I found online that HU are obtained :\n\nHU = image voxel value * slope + intercept\n\nHow is that statement written then? image[image == 2000] = 0 ; why 2000? What's the basis of this conversion?",
          "votes": 1
        },
        {
          "id": 990096,
          "postDate": "2020-08-29T10:38:02.600Z",
          "content": "<p>First it's actually image[image == -2000] = 0. The value -2000 is not a magic value. It's the value of the padding pixel (a.k.a PixelPaddingValue dicom tag). \"The PPV is used mostly to fill in the corners of round images\"</p>",
          "rawMarkdown": "First it's actually image[image == -2000] = 0. The value -2000 is not a magic value. It's the value of the padding pixel (a.k.a PixelPaddingValue dicom tag). \"The PPV is used mostly to fill in the corners of round images\"",
          "votes": 2
        },
        {
          "id": 990700,
          "postDate": "2020-08-29T19:34:36.407Z",
          "content": "<p><a href=\"https://www.kaggle.com/fireheart7\" target=\"_blank\">@fireheart7</a> </p>\n<p>The -2000 is often the default value for regions that are \"out of boundary\". If the scanner-tube is cylindrical, then you will find a circle inside the slice image. Outside of the circle means outside of the scanner tube and the values of that region are often set to the default -2000. </p>\n<p>By manually setting them to air with image[image == -2000]=0 in the raw values you remove this kind of default-background to air which is the background inside the tubes in most of the remaining cases. It's not the value of water as after rescaling it becomes -1000 in hounsfield values which is related to air.</p>\n<p>BUT - in this competition be careful. There are out-of-boundary regions (outside scanner-tube) that have been set to a default value of water in hounsfield units! Consequently you will still find circular boundaries after preprocessing with image[image == -2000]=0 as those cases can't be solved with image[image == -2000]=0.</p>",
          "rawMarkdown": "@fireheart7 \n\nThe -2000 is often the default value for regions that are \"out of boundary\". If the scanner-tube is cylindrical, then you will find a circle inside the slice image. Outside of the circle means outside of the scanner tube and the values of that region are often set to the default -2000. \n\nBy manually setting them to air with image[image == -2000]=0 in the raw values you remove this kind of default-background to air which is the background inside the tubes in most of the remaining cases. It's not the value of water as after rescaling it becomes -1000 in hounsfield values which is related to air.\n\nBUT - in this competition be careful. There are out-of-boundary regions (outside scanner-tube) that have been set to a default value of water in hounsfield units! Consequently you will still find circular boundaries after preprocessing with image[image == -2000]=0 as those cases can't be solved with image[image == -2000]=0."
        }
      ]
    },
    {
      "id": 984983,
      "postDate": "2020-08-25T12:18:09.103Z",
      "content": "<p>Pixel array is how a DICOM Image is stored.<br>\nTo properly display a CT scan, you need to convert pixel intensity in image to Hounsfield Unit. In short HU indicates the density of matters located in a pixel.</p>\n<h1><img src=\"https://www.googleapis.com/download/storage/v1/b/kaggle-forum-message-attachments/o/inbox%2F3436753%2F46a09614f44aad54c74f540be93e94c2%2Funnamed.png?generation=1598357280192076&amp;alt=media\" alt=\"\"></h1>\n<p><code>\nhu_image = ds.pixel_array.astype(np.float64) * ds.RescaleSlope + ds.RescaleIntercept  \n</code></p>\n<p>Basically it's a linear transformation. You can read more about it here: <br>\n<a href=\"https://blog.kitware.com/dicom-rescale-intercept-rescale-slope-and-itk/\" target=\"_blank\">https://blog.kitware.com/dicom-rescale-intercept-rescale-slope-and-itk/</a></p>",
      "rawMarkdown": "Pixel array is how a DICOM Image is stored.\nTo properly display a CT scan, you need to convert pixel intensity in image to Hounsfield Unit. In short HU indicates the density of matters located in a pixel.\n#![](https://www.googleapis.com/download/storage/v1/b/kaggle-forum-message-attachments/o/inbox%2F3436753%2F46a09614f44aad54c74f540be93e94c2%2Funnamed.png?generation=1598357280192076&alt=media) \n`\nhu_image = ds.pixel_array.astype(np.float64) * ds.RescaleSlope + ds.RescaleIntercept  \n`\n\nBasically it's a linear transformation. You can read more about it here: \nhttps://blog.kitware.com/dicom-rescale-intercept-rescale-slope-and-itk/",
      "votes": 7,
      "replies": [
        {
          "id": 987378,
          "postDate": "2020-08-27T07:55:26.460Z",
          "content": "<p>Thank you sm!! Really helpful. I love this about the Kaggle community. The things you can learn far exceeds any course material!</p>",
          "rawMarkdown": "Thank you sm!! Really helpful. I love this about the Kaggle community. The things you can learn far exceeds any course material!",
          "votes": 4
        },
        {
          "id": 990151,
          "postDate": "2020-08-29T11:20:04.317Z",
          "content": "<p>Thanks! Very helpful</p>",
          "rawMarkdown": "Thanks! Very helpful"
        },
        {
          "id": 991980,
          "postDate": "2020-08-30T19:16:28.843Z",
          "content": "<p>Thanks, looks like so important insight! </p>",
          "rawMarkdown": "Thanks, looks like so important insight! "
        }
      ]
    },
    {
      "id": 985353,
      "postDate": "2020-08-25T17:15:20.453Z",
      "content": "<p>Hi Aditya,</p>\n<p>Pixel_array is to access to the image scan from dicom file, it return matrix of values of grey scale of colors, we can access to different parts by calling them like DICOM.\"Name of component\".</p>\n<p>What ido for rescale images is : cv2.resize((dicom.pixel_array - dicom.RescaleIntercept) / (dicom.RescaleSlope * 1000), (512, 512)), it seems work.</p>\n<p>regards.</p>",
      "rawMarkdown": "Hi Aditya,\n\nPixel_array is to access to the image scan from dicom file, it return matrix of values of grey scale of colors, we can access to different parts by calling them like DICOM.\"Name of component\".\n\nWhat ido for rescale images is : cv2.resize((dicom.pixel_array - dicom.RescaleIntercept) / (dicom.RescaleSlope * 1000), (512, 512)), it seems work.\n\nregards.",
      "votes": 1,
      "replies": [
        {
          "id": 987383,
          "postDate": "2020-08-27T07:56:29.603Z",
          "content": "<p>Thank you for the answer and all the best!</p>\n<p>~~Aditya</p>",
          "rawMarkdown": "Thank you for the answer and all the best!\n\n~~Aditya",
          "votes": 1
        },
        {
          "id": 1031781,
          "postDate": "2020-09-29T17:26:37.710Z",
          "content": "<p><a href=\"https://www.kaggle.com/servietsky\" target=\"_blank\">@servietsky</a>  <br>\nwhat is difference between </p>\n<pre><code>hu_image = ds.pixel_array.astype(np.float64) * ds.RescaleSlope + ds.RescaleIntercept\nand\n</code></pre>\n<pre><code> cv2.resize((dicom.pixel_array - dicom.RescaleIntercept) / (dicom.RescaleSlope * 1000), (512, 512))\n</code></pre>\n<p>why do we chose 1000 here ?</p>",
          "rawMarkdown": "@servietsky  \nwhat is difference between \n```\nhu_image = ds.pixel_array.astype(np.float64) * ds.RescaleSlope + ds.RescaleIntercept\nand\n```\n```\n cv2.resize((dicom.pixel_array - dicom.RescaleIntercept) / (dicom.RescaleSlope * 1000), (512, 512))\n\n```\nwhy do we chose 1000 here ?"
        }
      ]
    },
    {
      "id": 985258,
      "postDate": "2020-08-25T15:29:46.970Z",
      "content": "<p><a href=\"https://www.kaggle.com/fireheart7\" target=\"_blank\">@fireheart7</a>  Here is good link to get image from dcm and information about dcm format.<br>\nFAST.AI have wonderful package of medical imaging to fetch information.</p>\n<ul>\n<li><a href=\"https://asvcode.github.io/MedicalImaging/medical_imaging/dicom/fastai/2020/04/28/Medical-Imaging-Using-Fastai.html\" target=\"_blank\">https://asvcode.github.io/MedicalImaging/medical_imaging/dicom/fastai/2020/04/28/Medical-Imaging-Using-Fastai.html</a></li>\n<li>I created NB to get pixel , fixing issues and then saving as JPG format .<br>\nIt use lung windowing to get image pixels . Windowing is like kind of view to extract information from images.<br>\n           - <a href=\"https://www.kaggle.com/rajnishe/rc-osic-dcm-to-tif-n-jpg-conversion\" target=\"_blank\">https://www.kaggle.com/rajnishe/rc-osic-dcm-to-tif-n-jpg-conversion</a><br>\nHope you will find useful.</li>\n</ul>",
      "rawMarkdown": "\n@fireheart7  Here is good link to get image from dcm and information about dcm format.\nFAST.AI have wonderful package of medical imaging to fetch information.\n\n- https://asvcode.github.io/MedicalImaging/medical_imaging/dicom/fastai/2020/04/28/Medical-Imaging-Using-Fastai.html\n\n\n- I created NB to get pixel , fixing issues and then saving as JPG format .\nIt use lung windowing to get image pixels . Windowing is like kind of view to extract information from images.\n\n                - https://www.kaggle.com/rajnishe/rc-osic-dcm-to-tif-n-jpg-conversion\n\nHope you will find useful.",
      "votes": 1,
      "replies": [
        {
          "id": 987380,
          "postDate": "2020-08-27T07:55:51.807Z",
          "content": "<p>Thank you Mr. Chauhan for the links!</p>",
          "rawMarkdown": "Thank you Mr. Chauhan for the links!"
        }
      ]
    }
  ],
  "comments": [
    {
      "id": 986745,
      "author_name": "Laura Fink",
      "author_url": "",
      "post_date": "2020-08-26T18:34:01.567000",
      "content": "<p>Hi <a href=\"https://www.kaggle.com/fireheart7\" target=\"_blank\">@fireheart7</a> , </p>\n<p>given a patient there are several slices of a 3D-scan each given as a dicom file. Within this file you can find the pixel_array that holds raw values of radiodensity. This quantity describes how much x-rays are absorbed and for this reason attenuated by an object or tissue. As the spectral composition of these x-rays can differ from scanner to scanner (patient to patient) you need to rescale these raw values to hounsfield units. </p>\n<p>For this rescaling you can fine the attributes Rescale Intercept and Slope in a dicom file. After that the value of air is -1000 and the value of water 0. Lungs have values close to -500. You can find a list here as well: <a href=\"https://en.wikipedia.org/wiki/Hounsfield_scale\" target=\"_blank\">https://en.wikipedia.org/wiki/Hounsfield_scale</a></p>\n<p>There are further important attributes in the dicom file like pixelspacing and slice thickness that can tell you how much physical distance is covered by a single slice scan. </p>\n<p>I'm working on a tutorial that perhaps helps you to understand dicom files better and to generate a preprocessed dataset out of it: <a href=\"https://www.kaggle.com/allunia/pulmonary-fibrosis-dicom-preprocessing\" target=\"_blank\">https://www.kaggle.com/allunia/pulmonary-fibrosis-dicom-preprocessing</a></p>\n<p>Take a look at it if you like. ;-) </p>\n<p>I can also recommend to take a look at old competitions that used dicom. The last I played with it was this one that also has several notebooks that show how to deal with dicom files: <a href=\"https://www.kaggle.com/c/rsna-intracranial-hemorrhage-detection/notebooks\" target=\"_blank\">https://www.kaggle.com/c/rsna-intracranial-hemorrhage-detection/notebooks</a></p>\n<p>I hope my answer was helpful. :-)</p>",
      "votes": 11,
      "replies": [
        {
          "id": 987371,
          "author_name": "Aditya Baurai",
          "author_url": "",
          "post_date": "2020-08-27T07:49:35.050000",
          "content": "<p>Thank you so much <a href=\"https://www.kaggle.com/allunia\" target=\"_blank\">@allunia</a> !! This is very insightful ~~</p>",
          "votes": 1,
          "replies": []
        },
        {
          "id": 987372,
          "author_name": "",
          "author_url": "",
          "post_date": "2020-08-27T07:51:24.160000",
          "content": "",
          "votes": 0,
          "replies": []
        },
        {
          "id": 989964,
          "author_name": "Aditya Baurai",
          "author_url": "",
          "post_date": "2020-08-29T08:38:58.073000",
          "content": "<p>At one point while going through many kernels processing dicoms ; </p>\n<p>many folks have written this</p>\n<p>image[image == 2000] = 0 ~~ Setting air to zero when intercept = -1024 and slope = -1</p>\n<p>However, I found online that HU are obtained :</p>\n<p>HU = image voxel value * slope + intercept</p>\n<p>How is that statement written then? image[image == 2000] = 0 ; why 2000? What's the basis of this conversion?</p>",
          "votes": 1,
          "replies": []
        },
        {
          "id": 990096,
          "author_name": "Quan",
          "author_url": "",
          "post_date": "2020-08-29T10:38:02.600000",
          "content": "<p>First it's actually image[image == -2000] = 0. The value -2000 is not a magic value. It's the value of the padding pixel (a.k.a PixelPaddingValue dicom tag). \"The PPV is used mostly to fill in the corners of round images\"</p>",
          "votes": 2,
          "replies": []
        },
        {
          "id": 990700,
          "author_name": "Laura Fink",
          "author_url": "",
          "post_date": "2020-08-29T19:34:36.407000",
          "content": "<p><a href=\"https://www.kaggle.com/fireheart7\" target=\"_blank\">@fireheart7</a> </p>\n<p>The -2000 is often the default value for regions that are \"out of boundary\". If the scanner-tube is cylindrical, then you will find a circle inside the slice image. Outside of the circle means outside of the scanner tube and the values of that region are often set to the default -2000. </p>\n<p>By manually setting them to air with image[image == -2000]=0 in the raw values you remove this kind of default-background to air which is the background inside the tubes in most of the remaining cases. It's not the value of water as after rescaling it becomes -1000 in hounsfield values which is related to air.</p>\n<p>BUT - in this competition be careful. There are out-of-boundary regions (outside scanner-tube) that have been set to a default value of water in hounsfield units! Consequently you will still find circular boundaries after preprocessing with image[image == -2000]=0 as those cases can't be solved with image[image == -2000]=0.</p>",
          "votes": 0,
          "replies": []
        }
      ]
    },
    {
      "id": 984983,
      "author_name": "Quan",
      "author_url": "",
      "post_date": "2020-08-25T12:18:09.103000",
      "content": "<p>Pixel array is how a DICOM Image is stored.<br>\nTo properly display a CT scan, you need to convert pixel intensity in image to Hounsfield Unit. In short HU indicates the density of matters located in a pixel.</p>\n<h1><img src=\"https://www.googleapis.com/download/storage/v1/b/kaggle-forum-message-attachments/o/inbox%2F3436753%2F46a09614f44aad54c74f540be93e94c2%2Funnamed.png?generation=1598357280192076&amp;alt=media\" alt=\"\"></h1>\n<p><code>\nhu_image = ds.pixel_array.astype(np.float64) * ds.RescaleSlope + ds.RescaleIntercept  \n</code></p>\n<p>Basically it's a linear transformation. You can read more about it here: <br>\n<a href=\"https://blog.kitware.com/dicom-rescale-intercept-rescale-slope-and-itk/\" target=\"_blank\">https://blog.kitware.com/dicom-rescale-intercept-rescale-slope-and-itk/</a></p>",
      "votes": 7,
      "replies": [
        {
          "id": 987378,
          "author_name": "Aditya Baurai",
          "author_url": "",
          "post_date": "2020-08-27T07:55:26.460000",
          "content": "<p>Thank you sm!! Really helpful. I love this about the Kaggle community. The things you can learn far exceeds any course material!</p>",
          "votes": 4,
          "replies": []
        },
        {
          "id": 990151,
          "author_name": "Geoff",
          "author_url": "",
          "post_date": "2020-08-29T11:20:04.317000",
          "content": "<p>Thanks! Very helpful</p>",
          "votes": 0,
          "replies": []
        },
        {
          "id": 991980,
          "author_name": "Dmitrij Kozachuk",
          "author_url": "",
          "post_date": "2020-08-30T19:16:28.843000",
          "content": "<p>Thanks, looks like so important insight! </p>",
          "votes": 0,
          "replies": []
        }
      ]
    },
    {
      "id": 985353,
      "author_name": "Mehdi GASMI",
      "author_url": "",
      "post_date": "2020-08-25T17:15:20.453000",
      "content": "<p>Hi Aditya,</p>\n<p>Pixel_array is to access to the image scan from dicom file, it return matrix of values of grey scale of colors, we can access to different parts by calling them like DICOM.\"Name of component\".</p>\n<p>What ido for rescale images is : cv2.resize((dicom.pixel_array - dicom.RescaleIntercept) / (dicom.RescaleSlope * 1000), (512, 512)), it seems work.</p>\n<p>regards.</p>",
      "votes": 1,
      "replies": [
        {
          "id": 987383,
          "author_name": "Aditya Baurai",
          "author_url": "",
          "post_date": "2020-08-27T07:56:29.603000",
          "content": "<p>Thank you for the answer and all the best!</p>\n<p>~~Aditya</p>",
          "votes": 1,
          "replies": []
        },
        {
          "id": 1031781,
          "author_name": "Jaideep",
          "author_url": "",
          "post_date": "2020-09-29T17:26:37.710000",
          "content": "<p><a href=\"https://www.kaggle.com/servietsky\" target=\"_blank\">@servietsky</a>  <br>\nwhat is difference between </p>\n<pre><code>hu_image = ds.pixel_array.astype(np.float64) * ds.RescaleSlope + ds.RescaleIntercept\nand\n</code></pre>\n<pre><code> cv2.resize((dicom.pixel_array - dicom.RescaleIntercept) / (dicom.RescaleSlope * 1000), (512, 512))\n</code></pre>\n<p>why do we chose 1000 here ?</p>",
          "votes": 0,
          "replies": []
        }
      ]
    },
    {
      "id": 985258,
      "author_name": "Rajnish Chauhan",
      "author_url": "",
      "post_date": "2020-08-25T15:29:46.970000",
      "content": "<p><a href=\"https://www.kaggle.com/fireheart7\" target=\"_blank\">@fireheart7</a>  Here is good link to get image from dcm and information about dcm format.<br>\nFAST.AI have wonderful package of medical imaging to fetch information.</p>\n<ul>\n<li><a href=\"https://asvcode.github.io/MedicalImaging/medical_imaging/dicom/fastai/2020/04/28/Medical-Imaging-Using-Fastai.html\" target=\"_blank\">https://asvcode.github.io/MedicalImaging/medical_imaging/dicom/fastai/2020/04/28/Medical-Imaging-Using-Fastai.html</a></li>\n<li>I created NB to get pixel , fixing issues and then saving as JPG format .<br>\nIt use lung windowing to get image pixels . Windowing is like kind of view to extract information from images.<br>\n           - <a href=\"https://www.kaggle.com/rajnishe/rc-osic-dcm-to-tif-n-jpg-conversion\" target=\"_blank\">https://www.kaggle.com/rajnishe/rc-osic-dcm-to-tif-n-jpg-conversion</a><br>\nHope you will find useful.</li>\n</ul>",
      "votes": 1,
      "replies": [
        {
          "id": 987380,
          "author_name": "Aditya Baurai",
          "author_url": "",
          "post_date": "2020-08-27T07:55:51.807000",
          "content": "<p>Thank you Mr. Chauhan for the links!</p>",
          "votes": 0,
          "replies": []
        }
      ]
    }
  ],
  "raw_markdown_by_id": {
    "984937": "Hello folks!\n\nI have a couple of questions regarding DICOM image format, as it's new for me.\n\n1. In the reading part, what's the purpose of writing image.pixel_array ?? What does it do? Is it something similar to .flatten() function applied on a 3-D image tensor using Numpy?\n\n2. I found image mean using np.mean(image) and it appeared to be negative. Do I need to rescale the values of DICOM too, if they go negative.\n\nCan anyone kindly refer me to some good dicom resources, as nothing much is explained in theor documentation. It's just a lot of code....\n\nThank You\n~ Aditya Baurai \n\n\n*************************************\n**UPDATED Query II**\n\n**At one point while going through many kernels processing dicoms** ;\n\nmany folks have written this\n\n**image[image == 2000] = 0** ~~ Setting air to zero when intercept = -1024 and slope = -1\n\nHowever, I found online that HU are obtained :\n\nHU = image voxel value * slope + intercept\n\n**How is that statement written then? image[image == 2000] = 0 ; why 2000? What's the basis of this conversion**?\n\n************************************************",
    "986745": "Hi @fireheart7 , \n\ngiven a patient there are several slices of a 3D-scan each given as a dicom file. Within this file you can find the pixel_array that holds raw values of radiodensity. This quantity describes how much x-rays are absorbed and for this reason attenuated by an object or tissue. As the spectral composition of these x-rays can differ from scanner to scanner (patient to patient) you need to rescale these raw values to hounsfield units. \n\nFor this rescaling you can fine the attributes Rescale Intercept and Slope in a dicom file. After that the value of air is -1000 and the value of water 0. Lungs have values close to -500. You can find a list here as well: https://en.wikipedia.org/wiki/Hounsfield_scale\n\nThere are further important attributes in the dicom file like pixelspacing and slice thickness that can tell you how much physical distance is covered by a single slice scan. \n\nI'm working on a tutorial that perhaps helps you to understand dicom files better and to generate a preprocessed dataset out of it: https://www.kaggle.com/allunia/pulmonary-fibrosis-dicom-preprocessing\n\nTake a look at it if you like. ;-) \n\nI can also recommend to take a look at old competitions that used dicom. The last I played with it was this one that also has several notebooks that show how to deal with dicom files: https://www.kaggle.com/c/rsna-intracranial-hemorrhage-detection/notebooks\n\nI hope my answer was helpful. :-)",
    "984983": "Pixel array is how a DICOM Image is stored.\nTo properly display a CT scan, you need to convert pixel intensity in image to Hounsfield Unit. In short HU indicates the density of matters located in a pixel.\n#![](https://www.googleapis.com/download/storage/v1/b/kaggle-forum-message-attachments/o/inbox%2F3436753%2F46a09614f44aad54c74f540be93e94c2%2Funnamed.png?generation=1598357280192076&alt=media) \n`\nhu_image = ds.pixel_array.astype(np.float64) * ds.RescaleSlope + ds.RescaleIntercept  \n`\n\nBasically it's a linear transformation. You can read more about it here: \nhttps://blog.kitware.com/dicom-rescale-intercept-rescale-slope-and-itk/",
    "985353": "Hi Aditya,\n\nPixel_array is to access to the image scan from dicom file, it return matrix of values of grey scale of colors, we can access to different parts by calling them like DICOM.\"Name of component\".\n\nWhat ido for rescale images is : cv2.resize((dicom.pixel_array - dicom.RescaleIntercept) / (dicom.RescaleSlope * 1000), (512, 512)), it seems work.\n\nregards.",
    "985258": "\n@fireheart7  Here is good link to get image from dcm and information about dcm format.\nFAST.AI have wonderful package of medical imaging to fetch information.\n\n- https://asvcode.github.io/MedicalImaging/medical_imaging/dicom/fastai/2020/04/28/Medical-Imaging-Using-Fastai.html\n\n\n- I created NB to get pixel , fixing issues and then saving as JPG format .\nIt use lung windowing to get image pixels . Windowing is like kind of view to extract information from images.\n\n                - https://www.kaggle.com/rajnishe/rc-osic-dcm-to-tif-n-jpg-conversion\n\nHope you will find useful."
  }
}