{
  "id": 430444,
  "title": "Window Width and Center",
  "url": "/competitions/rsna-2023-abdominal-trauma-detection/discussion/430444",
  "author_name": "Gunes Evitan",
  "post_date": "2023-08-09T19:03:57.596000",
  "votes": 6,
  "comment_count": 15,
  "views": 0,
  "content": "<p>I just saw that window width and center are 400 and 50 respectively for all slices in train_dicom_tags. I found it hard to believe there can be a single value for those properties in a diverse dataset like this. Should we actually use those values or are they some kind of a placeholder?</p>",
  "messages": [
    {
      "id": 2382459,
      "postDate": "2023-08-09T19:03:57.597Z",
      "content": "<p>I just saw that window width and center are 400 and 50 respectively for all slices in train_dicom_tags. I found it hard to believe there can be a single value for those properties in a diverse dataset like this. Should we actually use those values or are they some kind of a placeholder?</p>",
      "rawMarkdown": "I just saw that window width and center are 400 and 50 respectively for all slices in train_dicom_tags. I found it hard to believe there can be a single value for those properties in a diverse dataset like this. Should we actually use those values or are they some kind of a placeholder?",
      "votes": 5
    },
    {
      "id": 2383602,
      "postDate": "2023-08-10T13:16:05.517Z",
      "content": "<p>400/50 is a common \"window\" for the soft tissue of abdominal scans, and ideally, all scans <em>should</em> use the same windowing values to give human readers consistency across studies. <br>\nUnfortunately, pydicom does not apply windowing or LUT's correctly using this dataset and the resulting images are output with a standard normalization instead of the windowed values. If you use pydicom's <code>apply_windowing()</code> or <code>apply_voi_lut()</code> or <code>apply_modality_lut()</code> functions, you are not getting proper windowing.</p>\n<p>I haven't seen anyone actually export an image using the width and center values from this dataset. I haven't figured out exactly what the problem is yet, but there is a problem.</p>",
      "rawMarkdown": "400/50 is a common \"window\" for the soft tissue of abdominal scans, and ideally, all scans *should* use the same windowing values to give human readers consistency across studies. \nUnfortunately, pydicom does not apply windowing or LUT's correctly using this dataset and the resulting images are output with a standard normalization instead of the windowed values. If you use pydicom's `apply_windowing()` or `apply_voi_lut()` or `apply_modality_lut()` functions, you are not getting proper windowing.\n\nI haven't seen anyone actually export an image using the width and center values from this dataset. I haven't figured out exactly what the problem is yet, but there is a problem.",
      "votes": 3,
      "replies": [
        {
          "id": 2383617,
          "postDate": "2023-08-10T13:22:30.793Z",
          "content": "<p>Yes, even with apply_voi_lut, most CT images are normalized as is and not properly windowed.</p>\n<p>Without windowing, it was almost a bone condition, which may be good for looking for fractures, etc., but it hardly shows the organs damage like hematoma.</p>\n<p>Windowing with np.clip or similar solves this problem, but I wonder.<br>\nWhat could be the problem?<br>\nDoes anyone know?</p>",
          "rawMarkdown": "Yes, even with apply_voi_lut, most CT images are normalized as is and not properly windowed.\n\nWithout windowing, it was almost a bone condition, which may be good for looking for fractures, etc., but it hardly shows the organs damage like hematoma.\n\nWindowing with np.clip or similar solves this problem, but I wonder.\nWhat could be the problem?\nDoes anyone know?",
          "replies": [
            {
              "id": 2383649,
              "postDate": "2023-08-10T13:47:40.563Z",
              "content": "<p>My initial guess is that it has to do with the compression to RLE transfer syntax. Its not normal to see CT scans in RLE. Decompressing to a non-compressed transfer syntax (1.2.840.10008.1.2, or LittleEndianExplicit) fixes the windowing issue on some of the studies, but not all. I'm still investigating the root issue.</p>",
              "rawMarkdown": "My initial guess is that it has to do with the compression to RLE transfer syntax. Its not normal to see CT scans in RLE. Decompressing to a non-compressed transfer syntax (1.2.840.10008.1.2, or LittleEndianExplicit) fixes the windowing issue on some of the studies, but not all. I'm still investigating the root issue."
            }
          ]
        },
        {
          "id": 2384829,
          "postDate": "2023-08-11T05:10:51.110Z",
          "content": "<p>Isn't windowing basically this</p>\n<pre><code>image_min = window_center - window_width // \nimage_max = window_center + window_width // \nimage[image &lt; image_min] = image_min\nimage[image &gt; image_max] = image_max\n</code></pre>\n<p>if so, we don't have to use pydicom. We can do it manually.</p>",
          "rawMarkdown": "Isn't windowing basically this\n```python\nimage_min = window_center - window_width // 2\nimage_max = window_center + window_width // 2\nimage[image < image_min] = image_min\nimage[image > image_max] = image_max\n```\nif so, we don't have to use pydicom. We can do it manually.",
          "replies": [
            {
              "id": 2384843,
              "postDate": "2023-08-11T05:20:46.803Z",
              "content": "<p>You need to use RescaleSlope and RescaleIntercept for CT. I generally use something like this to create an 8 bit LUT. Then iterate over the stored pixels and apply each value.</p>\n<pre><code> pixel_value  (min_pixel, max_pixel):\n    lut_value = pixel_value * slope + intercept\n    voi_value = (((lut_value - center) /  width + ) * )\n</code></pre>",
              "rawMarkdown": "You need to use RescaleSlope and RescaleIntercept for CT. I generally use something like this to create an 8 bit LUT. Then iterate over the stored pixels and apply each value.\n\n```python\nfor pixel_value in range(min_pixel, max_pixel):\n    lut_value = pixel_value * slope + intercept\n    voi_value = (((lut_value - center) /  width + 0.5) * 255.0)\n```",
              "votes": 1
            },
            {
              "id": 2384852,
              "postDate": "2023-08-11T05:26:44.120Z",
              "content": "<p>Yeah I forgot to add that. Thanks for reminding me and actually lots of images have non-zero rescale intercepts. Btw there must be a faster way of doing that like mapping a dictionary of values to a numpy array at once rather than iterating. </p>",
              "rawMarkdown": "Yeah I forgot to add that. Thanks for reminding me and actually lots of images have non-zero rescale intercepts. Btw there must be a faster way of doing that like mapping a dictionary of values to a numpy array at once rather than iterating. "
            },
            {
              "id": 2384881,
              "postDate": "2023-08-11T05:39:56.313Z",
              "content": "<p>Yes, I should be ashamed for posting that iteration code and suggesting an additional loop too! </p>\n<p>Surely there's a pythonic way of doing it. CT LUTs are so small though, it's really not a big issue for me.</p>",
              "rawMarkdown": "Yes, I should be ashamed for posting that iteration code and suggesting an additional loop too! \n\nSurely there's a pythonic way of doing it. CT LUTs are so small though, it's really not a big issue for me.",
              "votes": 1
            }
          ]
        }
      ]
    },
    {
      "id": 2382491,
      "postDate": "2023-08-09T19:28:43.863Z",
      "content": "<p>I think they are just default settings tbh</p>",
      "rawMarkdown": "I think they are just default settings tbh",
      "votes": 1
    },
    {
      "id": 2383251,
      "postDate": "2023-08-10T09:12:17.867Z",
      "content": "<p>This windowing is appropriate for observing soft tissue with contrast-enhanced CT.</p>\n<p>Of course, the conditions may be changed in detail, but most of the time, the radiologist will basically interpret the images with values close to these conditions when looking for abdominal trauma.</p>\n<p>Reference for windowing:<br>\n<a href=\"https://radiopaedia.org/articles/windowing-ct\" target=\"_blank\">https://radiopaedia.org/articles/windowing-ct</a></p>",
      "rawMarkdown": "This windowing is appropriate for observing soft tissue with contrast-enhanced CT.\n\nOf course, the conditions may be changed in detail, but most of the time, the radiologist will basically interpret the images with values close to these conditions when looking for abdominal trauma.\n\nReference for windowing:\nhttps://radiopaedia.org/articles/windowing-ct",
      "votes": 2,
      "replies": [
        {
          "id": 2383296,
          "postDate": "2023-08-10T09:40:37.883Z",
          "content": "<p>Thanks for the answer. If you believe that those window width and center values make sense to detect abdominal trauma maybe we should use windowed image as another channel in our input.</p>",
          "rawMarkdown": "Thanks for the answer. If you believe that those window width and center values make sense to detect abdominal trauma maybe we should use windowed image as another channel in our input.",
          "votes": 1
        }
      ]
    },
    {
      "id": 2393172,
      "postDate": "2023-08-16T07:03:35.350Z",
      "content": "<p>I get slightly worse CV score when I use 400/50 soft tissue window compared to no window with 2D approach.</p>",
      "rawMarkdown": "I get slightly worse CV score when I use 400/50 soft tissue window compared to no window with 2D approach.",
      "replies": [
        {
          "id": 2393573,
          "postDate": "2023-08-16T11:43:06.287Z",
          "content": "<p><a href=\"https://www.kaggle.com/gunesevitan\" target=\"_blank\">@gunesevitan</a>, how are you exporting the images with the 400/50 window? I used DCMTK, but there's not a python version of it that I'm aware of.</p>",
          "rawMarkdown": "@gunesevitan, how are you exporting the images with the 400/50 window? I used DCMTK, but there's not a python version of it that I'm aware of.",
          "replies": [
            {
              "id": 2393589,
              "postDate": "2023-08-16T11:51:33.167Z",
              "content": "<p>What do you mean by exporting? My pipeline is shift bits -&gt; rescale -&gt; window or no window -&gt; normalize -&gt; invert if necessary -&gt; cast to unsigned 8-bit int -&gt; save as png </p>",
              "rawMarkdown": "What do you mean by exporting? My pipeline is shift bits -> rescale -> window or no window -> normalize -> invert if necessary -> cast to unsigned 8-bit int -> save as png "
            },
            {
              "id": 2393595,
              "postDate": "2023-08-16T11:56:52.557Z",
              "content": "<p>That's what I meant by \"export\". You are manually applying windowing to the raw pixels? The reason I ask is, I cannot make PyDICOM apply windowing with any of its functions on this dataset.</p>",
              "rawMarkdown": "That's what I meant by \"export\". You are manually applying windowing to the raw pixels? The reason I ask is, I cannot make PyDICOM apply windowing with any of its functions on this dataset."
            },
            {
              "id": 2393633,
              "postDate": "2023-08-16T12:19:32.263Z",
              "content": "<p>Yes, I'm doing all of those operations manually. I'm using pydicom only for reading.</p>",
              "rawMarkdown": "Yes, I'm doing all of those operations manually. I'm using pydicom only for reading.",
              "votes": 1
            }
          ]
        }
      ]
    }
  ],
  "comments": [
    {
      "id": 2383602,
      "author_name": "David Roberts",
      "author_url": "",
      "post_date": "2023-08-10T13:16:05.517000",
      "content": "<p>400/50 is a common \"window\" for the soft tissue of abdominal scans, and ideally, all scans <em>should</em> use the same windowing values to give human readers consistency across studies. <br>\nUnfortunately, pydicom does not apply windowing or LUT's correctly using this dataset and the resulting images are output with a standard normalization instead of the windowed values. If you use pydicom's <code>apply_windowing()</code> or <code>apply_voi_lut()</code> or <code>apply_modality_lut()</code> functions, you are not getting proper windowing.</p>\n<p>I haven't seen anyone actually export an image using the width and center values from this dataset. I haven't figured out exactly what the problem is yet, but there is a problem.</p>",
      "votes": 3,
      "replies": [
        {
          "id": 2383617,
          "author_name": "YYama",
          "author_url": "",
          "post_date": "2023-08-10T13:22:30.793000",
          "content": "<p>Yes, even with apply_voi_lut, most CT images are normalized as is and not properly windowed.</p>\n<p>Without windowing, it was almost a bone condition, which may be good for looking for fractures, etc., but it hardly shows the organs damage like hematoma.</p>\n<p>Windowing with np.clip or similar solves this problem, but I wonder.<br>\nWhat could be the problem?<br>\nDoes anyone know?</p>",
          "votes": 0,
          "replies": [
            {
              "id": 2383649,
              "author_name": "David Roberts",
              "author_url": "",
              "post_date": "2023-08-10T13:47:40.563000",
              "content": "<p>My initial guess is that it has to do with the compression to RLE transfer syntax. Its not normal to see CT scans in RLE. Decompressing to a non-compressed transfer syntax (1.2.840.10008.1.2, or LittleEndianExplicit) fixes the windowing issue on some of the studies, but not all. I'm still investigating the root issue.</p>",
              "votes": 0,
              "replies": []
            }
          ]
        },
        {
          "id": 2384829,
          "author_name": "Gunes Evitan",
          "author_url": "",
          "post_date": "2023-08-11T05:10:51.110000",
          "content": "<p>Isn't windowing basically this</p>\n<pre><code>image_min = window_center - window_width // \nimage_max = window_center + window_width // \nimage[image &lt; image_min] = image_min\nimage[image &gt; image_max] = image_max\n</code></pre>\n<p>if so, we don't have to use pydicom. We can do it manually.</p>",
          "votes": 0,
          "replies": [
            {
              "id": 2384843,
              "author_name": "David Roberts",
              "author_url": "",
              "post_date": "2023-08-11T05:20:46.803000",
              "content": "<p>You need to use RescaleSlope and RescaleIntercept for CT. I generally use something like this to create an 8 bit LUT. Then iterate over the stored pixels and apply each value.</p>\n<pre><code> pixel_value  (min_pixel, max_pixel):\n    lut_value = pixel_value * slope + intercept\n    voi_value = (((lut_value - center) /  width + ) * )\n</code></pre>",
              "votes": 1,
              "replies": []
            },
            {
              "id": 2384852,
              "author_name": "Gunes Evitan",
              "author_url": "",
              "post_date": "2023-08-11T05:26:44.120000",
              "content": "<p>Yeah I forgot to add that. Thanks for reminding me and actually lots of images have non-zero rescale intercepts. Btw there must be a faster way of doing that like mapping a dictionary of values to a numpy array at once rather than iterating. </p>",
              "votes": 0,
              "replies": []
            },
            {
              "id": 2384881,
              "author_name": "David Roberts",
              "author_url": "",
              "post_date": "2023-08-11T05:39:56.313000",
              "content": "<p>Yes, I should be ashamed for posting that iteration code and suggesting an additional loop too! </p>\n<p>Surely there's a pythonic way of doing it. CT LUTs are so small though, it's really not a big issue for me.</p>",
              "votes": 1,
              "replies": []
            }
          ]
        }
      ]
    },
    {
      "id": 2382491,
      "author_name": "SebastianBarry55",
      "author_url": "",
      "post_date": "2023-08-09T19:28:43.863000",
      "content": "<p>I think they are just default settings tbh</p>",
      "votes": 1,
      "replies": []
    },
    {
      "id": 2383251,
      "author_name": "YYama",
      "author_url": "",
      "post_date": "2023-08-10T09:12:17.867000",
      "content": "<p>This windowing is appropriate for observing soft tissue with contrast-enhanced CT.</p>\n<p>Of course, the conditions may be changed in detail, but most of the time, the radiologist will basically interpret the images with values close to these conditions when looking for abdominal trauma.</p>\n<p>Reference for windowing:<br>\n<a href=\"https://radiopaedia.org/articles/windowing-ct\" target=\"_blank\">https://radiopaedia.org/articles/windowing-ct</a></p>",
      "votes": 2,
      "replies": [
        {
          "id": 2383296,
          "author_name": "Gunes Evitan",
          "author_url": "",
          "post_date": "2023-08-10T09:40:37.883000",
          "content": "<p>Thanks for the answer. If you believe that those window width and center values make sense to detect abdominal trauma maybe we should use windowed image as another channel in our input.</p>",
          "votes": 1,
          "replies": []
        }
      ]
    },
    {
      "id": 2393172,
      "author_name": "Gunes Evitan",
      "author_url": "",
      "post_date": "2023-08-16T07:03:35.350000",
      "content": "<p>I get slightly worse CV score when I use 400/50 soft tissue window compared to no window with 2D approach.</p>",
      "votes": 0,
      "replies": [
        {
          "id": 2393573,
          "author_name": "David Roberts",
          "author_url": "",
          "post_date": "2023-08-16T11:43:06.287000",
          "content": "<p><a href=\"https://www.kaggle.com/gunesevitan\" target=\"_blank\">@gunesevitan</a>, how are you exporting the images with the 400/50 window? I used DCMTK, but there's not a python version of it that I'm aware of.</p>",
          "votes": 0,
          "replies": [
            {
              "id": 2393589,
              "author_name": "Gunes Evitan",
              "author_url": "",
              "post_date": "2023-08-16T11:51:33.167000",
              "content": "<p>What do you mean by exporting? My pipeline is shift bits -&gt; rescale -&gt; window or no window -&gt; normalize -&gt; invert if necessary -&gt; cast to unsigned 8-bit int -&gt; save as png </p>",
              "votes": 0,
              "replies": []
            },
            {
              "id": 2393595,
              "author_name": "David Roberts",
              "author_url": "",
              "post_date": "2023-08-16T11:56:52.557000",
              "content": "<p>That's what I meant by \"export\". You are manually applying windowing to the raw pixels? The reason I ask is, I cannot make PyDICOM apply windowing with any of its functions on this dataset.</p>",
              "votes": 0,
              "replies": []
            },
            {
              "id": 2393633,
              "author_name": "Gunes Evitan",
              "author_url": "",
              "post_date": "2023-08-16T12:19:32.263000",
              "content": "<p>Yes, I'm doing all of those operations manually. I'm using pydicom only for reading.</p>",
              "votes": 1,
              "replies": []
            }
          ]
        }
      ]
    }
  ],
  "raw_markdown_by_id": {
    "2382459": "I just saw that window width and center are 400 and 50 respectively for all slices in train_dicom_tags. I found it hard to believe there can be a single value for those properties in a diverse dataset like this. Should we actually use those values or are they some kind of a placeholder?",
    "2383602": "400/50 is a common \"window\" for the soft tissue of abdominal scans, and ideally, all scans *should* use the same windowing values to give human readers consistency across studies. \nUnfortunately, pydicom does not apply windowing or LUT's correctly using this dataset and the resulting images are output with a standard normalization instead of the windowed values. If you use pydicom's `apply_windowing()` or `apply_voi_lut()` or `apply_modality_lut()` functions, you are not getting proper windowing.\n\nI haven't seen anyone actually export an image using the width and center values from this dataset. I haven't figured out exactly what the problem is yet, but there is a problem.",
    "2382491": "I think they are just default settings tbh",
    "2383251": "This windowing is appropriate for observing soft tissue with contrast-enhanced CT.\n\nOf course, the conditions may be changed in detail, but most of the time, the radiologist will basically interpret the images with values close to these conditions when looking for abdominal trauma.\n\nReference for windowing:\nhttps://radiopaedia.org/articles/windowing-ct",
    "2393172": "I get slightly worse CV score when I use 400/50 soft tissue window compared to no window with 2D approach."
  }
}