{
  "id": 357454,
  "title": "windowing (CT  Contrast Amplification)",
  "url": "/competitions/rsna-2022-cervical-spine-fracture-detection/discussion/357454",
  "author_name": "aeeeeeep",
  "post_date": "2022-10-04T11:42:18.592000",
  "votes": 2,
  "comment_count": 0,
  "views": 0,
  "content": "<h2>Description</h2>\n<p>CT winding is an image processing task for CT scans that helps to highlight key tissue structures, making the images easier to analyze by modifying the HU (Hounsfield Units) parameters.</p>\n<p><img src=\"https://aeeeeeep.top/image/CT-Windowing医学CT图像增强/0.png\"></p>\n<h2>Hounsfield Unit (HU)</h2>\n<p>The Hounsfield scale is a quantitative measure of resistivity, named after Godfrey Newbold Hounsfield, the inventor of X-ray computed tomography. Heinz units are commonly used in X-ray computed tomography, so they are also called CT numbers.</p>\n<p>The HU value is related to the composition and properties of the tissue and therefore represents the density of various tissues, the higher the HU value, the denser the material and vice versa.</p>\n<p>Here are some values for each organization on the HU scale</p>\n<p><img src=\"https://aeeeeeep.top/image/CT-Windowing医学CT图像增强/1.png\"></p>\n<h2>Window Width &amp; Window Level</h2>\n<h3>Window Width (WW)</h3>\n<p>is a measure of the range of HU values contained in the CT image, any HU value below the lower WW value will be displayed in black in the scan, while HU values above the upper WW value will be displayed in white.</p>\n<p>As WW increases, a larger density change will be required to change the shade of gray representing a certain HU unit. This results in a loss of contrast, as more structures will look similar (albeit with different densities) as the HU value increases.</p>\n<p>As the WW decreases, smaller density changes will result in color changes on the CT image, resulting in structures with similar densities being assigned to different grayscales, which will increase contrast.</p>\n<p><img src=\"https://aeeeeeep.top/image/CT-Windowing医学CT图像增强/3.png\"></p>\n<h3>Window Level (WL)</h3>\n<p>WL represents the HU value at the center or midpoint of the window, the lower the WL you set for the image, the brighter the entire image will become.</p>\n<p>As WL is lowered, a lower HU value can represent tissue as white, which will allow more white to pass through, resulting in a brighter image. Therefore, WL affects the brightness of the image.</p>\n<p><img src=\"https://aeeeeeep.top/image/CT-Windowing医学CT图像增强/4.png\"></p>\n<h3>WW &amp; WL Calculation</h3>\n<p>Grayscale upper limit: WL + (WW / 2)<br>\nGrayscale lower limit: WL - (WW / 2)</p>\n<p><img src=\"https://aeeeeeep.top/image/CT-Windowing医学CT图像增强/2.png\"></p>\n<h3>WW &amp; WL Example</h3>\n<p>In CT image viewing software, there are usually various standard WL and WW.</p>\n<table>\n<thead>\n<tr>\n<th>Tissue</th>\n<th>WW</th>\n<th>WL</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td>Bone</td>\n<td>2000</td>\n<td>500</td>\n</tr>\n<tr>\n<td>Lung</td>\n<td>1600</td>\n<td>-600</td>\n</tr>\n<tr>\n<td>Coelio</td>\n<td>400</td>\n<td>40</td>\n</tr>\n<tr>\n<td>Brain</td>\n<td>70</td>\n<td>30</td>\n</tr>\n<tr>\n<td>Soft Tissue</td>\n<td>350</td>\n<td>50</td>\n</tr>\n<tr>\n<td>Liver</td>\n<td>160</td>\n<td>60</td>\n</tr>\n<tr>\n<td>Mediastinum (chest cavity)</td>\n<td>500</td>\n<td>50</td>\n</tr>\n<tr>\n<td>Stroke (low-density brain imaging)</td>\n<td>30</td>\n<td>30</td>\n</tr>\n<tr>\n<td>CTA</td>\n<td>600</td>\n<td>170</td>\n</tr>\n</tbody>\n</table>\n<h3>WW &amp; WL  Choice</h3>\n<ol>\n<li>Select according to the distribution range of the HU value (for CT image) of the required part. If the CT is enhanced, the HU value will be slightly different. You can observe the histogram and customize WW and WL.</li>\n</ol>\n<pre><code>def transform_ctdata(self, windowWidth, windowLevel, normal=False):\n        minWindow = float(windowLevel) - 0.5*float(windowWidth)\n        newimg = (self.image - minWindow) / float(windowWidth)\n        newimg[newimg &lt; 0] = 0\n        newimg[newimg &gt; 1] = 1\n        if not normal:\n            newimg = (newimg * 255).astype('uint8')\n        return newimg\n</code></pre>\n<ol>\n<li>According to the statistics of the image, such as the image mean as the center of the window, the variance of $\\pm \\delta$ as WW</li>\n</ol>\n<pre><code>import SimpleITK as sitk\nimport torchvision as tv\n\nclass StatisticalNormalization(object):\n    \"\"\"\n    Normalize an image by mapping intensity with intensity distribution\n    \"\"\"\n\n    def __init__(self, sigma):\n        self.name = 'StatisticalNormalization'\n        assert isinstance(sigma, float)\n        self.sigma = sigma\n\n    def __call__(self, sample):\n        image, label = sample['image'], sample['label']\n        statisticsFilter = sitk.StatisticsImageFilter()\n        statisticsFilter.Execute(image)\n\n        intensityWindowingFilter = v.IntensityWindowingImageFilter()\n        intensityWindowingFilter.SetOutputMaximum(255)\n        intensityWindowingFilter.SetOutputMinimum(0)\n        intensityWindowingFilter.SetWindowMaximum(\n            statisticsFilter.GetMean() + self.sigma * statisticsFilter.GetSigma())\n        intensityWindowingFilter.SetWindowMinimum(\n            statisticsFilter.GetMean() - self.sigma * statisticsFilter.GetSigma())\n\n        image = intensityWindowingFilter.Execute(image)\n\n        return {'image': image, 'label': label}\n</code></pre>\n<h2>Reference</h2>\n<p><a href=\"https://en.wikipedia.org/wiki/Hounsfield_scale\" target=\"_blank\">https://en.wikipedia.org/wiki/Hounsfield_scale</a></p>\n<p><a href=\"https://www.stepwards.com/?page_id=21646\" target=\"_blank\">https://www.stepwards.com/?page_id=21646</a></p>\n<p><a href=\"https://myctregistryreview.com/courses/my-ct-registry-review-demo/lessons/ct-physics/\" target=\"_blank\">https://myctregistryreview.com/courses/my-ct-registry-review-demo/lessons/ct-physics/</a></p>",
  "messages": [
    {
      "id": 1970963,
      "postDate": "2022-10-04T11:42:18.593Z",
      "content": "<h2>Description</h2>\n<p>CT winding is an image processing task for CT scans that helps to highlight key tissue structures, making the images easier to analyze by modifying the HU (Hounsfield Units) parameters.</p>\n<p><img src=\"https://aeeeeeep.top/image/CT-Windowing医学CT图像增强/0.png\"></p>\n<h2>Hounsfield Unit (HU)</h2>\n<p>The Hounsfield scale is a quantitative measure of resistivity, named after Godfrey Newbold Hounsfield, the inventor of X-ray computed tomography. Heinz units are commonly used in X-ray computed tomography, so they are also called CT numbers.</p>\n<p>The HU value is related to the composition and properties of the tissue and therefore represents the density of various tissues, the higher the HU value, the denser the material and vice versa.</p>\n<p>Here are some values for each organization on the HU scale</p>\n<p><img src=\"https://aeeeeeep.top/image/CT-Windowing医学CT图像增强/1.png\"></p>\n<h2>Window Width &amp; Window Level</h2>\n<h3>Window Width (WW)</h3>\n<p>is a measure of the range of HU values contained in the CT image, any HU value below the lower WW value will be displayed in black in the scan, while HU values above the upper WW value will be displayed in white.</p>\n<p>As WW increases, a larger density change will be required to change the shade of gray representing a certain HU unit. This results in a loss of contrast, as more structures will look similar (albeit with different densities) as the HU value increases.</p>\n<p>As the WW decreases, smaller density changes will result in color changes on the CT image, resulting in structures with similar densities being assigned to different grayscales, which will increase contrast.</p>\n<p><img src=\"https://aeeeeeep.top/image/CT-Windowing医学CT图像增强/3.png\"></p>\n<h3>Window Level (WL)</h3>\n<p>WL represents the HU value at the center or midpoint of the window, the lower the WL you set for the image, the brighter the entire image will become.</p>\n<p>As WL is lowered, a lower HU value can represent tissue as white, which will allow more white to pass through, resulting in a brighter image. Therefore, WL affects the brightness of the image.</p>\n<p><img src=\"https://aeeeeeep.top/image/CT-Windowing医学CT图像增强/4.png\"></p>\n<h3>WW &amp; WL Calculation</h3>\n<p>Grayscale upper limit: WL + (WW / 2)<br>\nGrayscale lower limit: WL - (WW / 2)</p>\n<p><img src=\"https://aeeeeeep.top/image/CT-Windowing医学CT图像增强/2.png\"></p>\n<h3>WW &amp; WL Example</h3>\n<p>In CT image viewing software, there are usually various standard WL and WW.</p>\n<table>\n<thead>\n<tr>\n<th>Tissue</th>\n<th>WW</th>\n<th>WL</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td>Bone</td>\n<td>2000</td>\n<td>500</td>\n</tr>\n<tr>\n<td>Lung</td>\n<td>1600</td>\n<td>-600</td>\n</tr>\n<tr>\n<td>Coelio</td>\n<td>400</td>\n<td>40</td>\n</tr>\n<tr>\n<td>Brain</td>\n<td>70</td>\n<td>30</td>\n</tr>\n<tr>\n<td>Soft Tissue</td>\n<td>350</td>\n<td>50</td>\n</tr>\n<tr>\n<td>Liver</td>\n<td>160</td>\n<td>60</td>\n</tr>\n<tr>\n<td>Mediastinum (chest cavity)</td>\n<td>500</td>\n<td>50</td>\n</tr>\n<tr>\n<td>Stroke (low-density brain imaging)</td>\n<td>30</td>\n<td>30</td>\n</tr>\n<tr>\n<td>CTA</td>\n<td>600</td>\n<td>170</td>\n</tr>\n</tbody>\n</table>\n<h3>WW &amp; WL  Choice</h3>\n<ol>\n<li>Select according to the distribution range of the HU value (for CT image) of the required part. If the CT is enhanced, the HU value will be slightly different. You can observe the histogram and customize WW and WL.</li>\n</ol>\n<pre><code>def transform_ctdata(self, windowWidth, windowLevel, normal=False):\n        minWindow = float(windowLevel) - 0.5*float(windowWidth)\n        newimg = (self.image - minWindow) / float(windowWidth)\n        newimg[newimg &lt; 0] = 0\n        newimg[newimg &gt; 1] = 1\n        if not normal:\n            newimg = (newimg * 255).astype('uint8')\n        return newimg\n</code></pre>\n<ol>\n<li>According to the statistics of the image, such as the image mean as the center of the window, the variance of $\\pm \\delta$ as WW</li>\n</ol>\n<pre><code>import SimpleITK as sitk\nimport torchvision as tv\n\nclass StatisticalNormalization(object):\n    \"\"\"\n    Normalize an image by mapping intensity with intensity distribution\n    \"\"\"\n\n    def __init__(self, sigma):\n        self.name = 'StatisticalNormalization'\n        assert isinstance(sigma, float)\n        self.sigma = sigma\n\n    def __call__(self, sample):\n        image, label = sample['image'], sample['label']\n        statisticsFilter = sitk.StatisticsImageFilter()\n        statisticsFilter.Execute(image)\n\n        intensityWindowingFilter = v.IntensityWindowingImageFilter()\n        intensityWindowingFilter.SetOutputMaximum(255)\n        intensityWindowingFilter.SetOutputMinimum(0)\n        intensityWindowingFilter.SetWindowMaximum(\n            statisticsFilter.GetMean() + self.sigma * statisticsFilter.GetSigma())\n        intensityWindowingFilter.SetWindowMinimum(\n            statisticsFilter.GetMean() - self.sigma * statisticsFilter.GetSigma())\n\n        image = intensityWindowingFilter.Execute(image)\n\n        return {'image': image, 'label': label}\n</code></pre>\n<h2>Reference</h2>\n<p><a href=\"https://en.wikipedia.org/wiki/Hounsfield_scale\" target=\"_blank\">https://en.wikipedia.org/wiki/Hounsfield_scale</a></p>\n<p><a href=\"https://www.stepwards.com/?page_id=21646\" target=\"_blank\">https://www.stepwards.com/?page_id=21646</a></p>\n<p><a href=\"https://myctregistryreview.com/courses/my-ct-registry-review-demo/lessons/ct-physics/\" target=\"_blank\">https://myctregistryreview.com/courses/my-ct-registry-review-demo/lessons/ct-physics/</a></p>",
      "rawMarkdown": "## Description\n\nCT winding is an image processing task for CT scans that helps to highlight key tissue structures, making the images easier to analyze by modifying the HU (Hounsfield Units) parameters.\n\n<img src=\"https://aeeeeeep.top/image/CT-Windowing医学CT图像增强/0.png\" style=\"zoom:50%;\" />\n\n## Hounsfield Unit (HU)\n\nThe Hounsfield scale is a quantitative measure of resistivity, named after Godfrey Newbold Hounsfield, the inventor of X-ray computed tomography. Heinz units are commonly used in X-ray computed tomography, so they are also called CT numbers.\n\nThe HU value is related to the composition and properties of the tissue and therefore represents the density of various tissues, the higher the HU value, the denser the material and vice versa.\n\nHere are some values for each organization on the HU scale\n\n<img src=\"https://aeeeeeep.top/image/CT-Windowing医学CT图像增强/1.png\" style=\"zoom:80%;\" />\n\n## Window Width & Window Level\n\n### Window Width (WW)\n\nis a measure of the range of HU values contained in the CT image, any HU value below the lower WW value will be displayed in black in the scan, while HU values above the upper WW value will be displayed in white.\n\nAs WW increases, a larger density change will be required to change the shade of gray representing a certain HU unit. This results in a loss of contrast, as more structures will look similar (albeit with different densities) as the HU value increases.\n\nAs the WW decreases, smaller density changes will result in color changes on the CT image, resulting in structures with similar densities being assigned to different grayscales, which will increase contrast.\n\n<img src=\"https://aeeeeeep.top/image/CT-Windowing医学CT图像增强/3.png\" style=\"zoom: 67%;\" />\n\n### Window Level (WL)\n\nWL represents the HU value at the center or midpoint of the window, the lower the WL you set for the image, the brighter the entire image will become.\n\nAs WL is lowered, a lower HU value can represent tissue as white, which will allow more white to pass through, resulting in a brighter image. Therefore, WL affects the brightness of the image.\n\n<img src=\"https://aeeeeeep.top/image/CT-Windowing医学CT图像增强/4.png\" style=\"zoom:67%;\" />\n\n### WW & WL Calculation\n\nGrayscale upper limit: WL + (WW / 2)\nGrayscale lower limit: WL - (WW / 2)\n\n<img src=\"https://aeeeeeep.top/image/CT-Windowing医学CT图像增强/2.png\" style=\"zoom:80%;\" />\n\n### WW & WL Example\n\nIn CT image viewing software, there are usually various standard WL and WW.\n\n| Tissue                             | WW   | WL   |\n| ---------------------------------- | ---- | ---- |\n| Bone                               | 2000 | 500  |\n| Lung                               | 1600 | -600 |\n| Coelio                             | 400  | 40   |\n| Brain                              | 70   | 30   |\n| Soft Tissue                        | 350  | 50   |\n| Liver                              | 160  | 60   |\n| Mediastinum (chest cavity)         | 500  | 50   |\n| Stroke (low-density brain imaging) | 30   | 30   |\n| CTA                                | 600  | 170  |\n\n### WW & WL  Choice\n\n1. Select according to the distribution range of the HU value (for CT image) of the required part. If the CT is enhanced, the HU value will be slightly different. You can observe the histogram and customize WW and WL.\n\n```python\ndef transform_ctdata(self, windowWidth, windowLevel, normal=False):\n        minWindow = float(windowLevel) - 0.5*float(windowWidth)\n        newimg = (self.image - minWindow) / float(windowWidth)\n        newimg[newimg < 0] = 0\n        newimg[newimg > 1] = 1\n        if not normal:\n            newimg = (newimg * 255).astype('uint8')\n        return newimg\n```\n\n2. According to the statistics of the image, such as the image mean as the center of the window, the variance of $\\pm \\delta$ as WW\n\n```python\nimport SimpleITK as sitk\nimport torchvision as tv\n\nclass StatisticalNormalization(object):\n    \"\"\"\n    Normalize an image by mapping intensity with intensity distribution\n    \"\"\"\n\n    def __init__(self, sigma):\n        self.name = 'StatisticalNormalization'\n        assert isinstance(sigma, float)\n        self.sigma = sigma\n\n    def __call__(self, sample):\n        image, label = sample['image'], sample['label']\n        statisticsFilter = sitk.StatisticsImageFilter()\n        statisticsFilter.Execute(image)\n\n        intensityWindowingFilter = v.IntensityWindowingImageFilter()\n        intensityWindowingFilter.SetOutputMaximum(255)\n        intensityWindowingFilter.SetOutputMinimum(0)\n        intensityWindowingFilter.SetWindowMaximum(\n            statisticsFilter.GetMean() + self.sigma * statisticsFilter.GetSigma())\n        intensityWindowingFilter.SetWindowMinimum(\n            statisticsFilter.GetMean() - self.sigma * statisticsFilter.GetSigma())\n\n        image = intensityWindowingFilter.Execute(image)\n\n        return {'image': image, 'label': label}\n```\n\n## Reference\n\nhttps://en.wikipedia.org/wiki/Hounsfield_scale\n\nhttps://www.stepwards.com/?page_id=21646\n\nhttps://myctregistryreview.com/courses/my-ct-registry-review-demo/lessons/ct-physics/\n",
      "votes": 2
    }
  ],
  "comments": [],
  "raw_markdown_by_id": {
    "1970963": "## Description\n\nCT winding is an image processing task for CT scans that helps to highlight key tissue structures, making the images easier to analyze by modifying the HU (Hounsfield Units) parameters.\n\n<img src=\"https://aeeeeeep.top/image/CT-Windowing医学CT图像增强/0.png\" style=\"zoom:50%;\" />\n\n## Hounsfield Unit (HU)\n\nThe Hounsfield scale is a quantitative measure of resistivity, named after Godfrey Newbold Hounsfield, the inventor of X-ray computed tomography. Heinz units are commonly used in X-ray computed tomography, so they are also called CT numbers.\n\nThe HU value is related to the composition and properties of the tissue and therefore represents the density of various tissues, the higher the HU value, the denser the material and vice versa.\n\nHere are some values for each organization on the HU scale\n\n<img src=\"https://aeeeeeep.top/image/CT-Windowing医学CT图像增强/1.png\" style=\"zoom:80%;\" />\n\n## Window Width & Window Level\n\n### Window Width (WW)\n\nis a measure of the range of HU values contained in the CT image, any HU value below the lower WW value will be displayed in black in the scan, while HU values above the upper WW value will be displayed in white.\n\nAs WW increases, a larger density change will be required to change the shade of gray representing a certain HU unit. This results in a loss of contrast, as more structures will look similar (albeit with different densities) as the HU value increases.\n\nAs the WW decreases, smaller density changes will result in color changes on the CT image, resulting in structures with similar densities being assigned to different grayscales, which will increase contrast.\n\n<img src=\"https://aeeeeeep.top/image/CT-Windowing医学CT图像增强/3.png\" style=\"zoom: 67%;\" />\n\n### Window Level (WL)\n\nWL represents the HU value at the center or midpoint of the window, the lower the WL you set for the image, the brighter the entire image will become.\n\nAs WL is lowered, a lower HU value can represent tissue as white, which will allow more white to pass through, resulting in a brighter image. Therefore, WL affects the brightness of the image.\n\n<img src=\"https://aeeeeeep.top/image/CT-Windowing医学CT图像增强/4.png\" style=\"zoom:67%;\" />\n\n### WW & WL Calculation\n\nGrayscale upper limit: WL + (WW / 2)\nGrayscale lower limit: WL - (WW / 2)\n\n<img src=\"https://aeeeeeep.top/image/CT-Windowing医学CT图像增强/2.png\" style=\"zoom:80%;\" />\n\n### WW & WL Example\n\nIn CT image viewing software, there are usually various standard WL and WW.\n\n| Tissue                             | WW   | WL   |\n| ---------------------------------- | ---- | ---- |\n| Bone                               | 2000 | 500  |\n| Lung                               | 1600 | -600 |\n| Coelio                             | 400  | 40   |\n| Brain                              | 70   | 30   |\n| Soft Tissue                        | 350  | 50   |\n| Liver                              | 160  | 60   |\n| Mediastinum (chest cavity)         | 500  | 50   |\n| Stroke (low-density brain imaging) | 30   | 30   |\n| CTA                                | 600  | 170  |\n\n### WW & WL  Choice\n\n1. Select according to the distribution range of the HU value (for CT image) of the required part. If the CT is enhanced, the HU value will be slightly different. You can observe the histogram and customize WW and WL.\n\n```python\ndef transform_ctdata(self, windowWidth, windowLevel, normal=False):\n        minWindow = float(windowLevel) - 0.5*float(windowWidth)\n        newimg = (self.image - minWindow) / float(windowWidth)\n        newimg[newimg < 0] = 0\n        newimg[newimg > 1] = 1\n        if not normal:\n            newimg = (newimg * 255).astype('uint8')\n        return newimg\n```\n\n2. According to the statistics of the image, such as the image mean as the center of the window, the variance of $\\pm \\delta$ as WW\n\n```python\nimport SimpleITK as sitk\nimport torchvision as tv\n\nclass StatisticalNormalization(object):\n    \"\"\"\n    Normalize an image by mapping intensity with intensity distribution\n    \"\"\"\n\n    def __init__(self, sigma):\n        self.name = 'StatisticalNormalization'\n        assert isinstance(sigma, float)\n        self.sigma = sigma\n\n    def __call__(self, sample):\n        image, label = sample['image'], sample['label']\n        statisticsFilter = sitk.StatisticsImageFilter()\n        statisticsFilter.Execute(image)\n\n        intensityWindowingFilter = v.IntensityWindowingImageFilter()\n        intensityWindowingFilter.SetOutputMaximum(255)\n        intensityWindowingFilter.SetOutputMinimum(0)\n        intensityWindowingFilter.SetWindowMaximum(\n            statisticsFilter.GetMean() + self.sigma * statisticsFilter.GetSigma())\n        intensityWindowingFilter.SetWindowMinimum(\n            statisticsFilter.GetMean() - self.sigma * statisticsFilter.GetSigma())\n\n        image = intensityWindowingFilter.Execute(image)\n\n        return {'image': image, 'label': label}\n```\n\n## Reference\n\nhttps://en.wikipedia.org/wiki/Hounsfield_scale\n\nhttps://www.stepwards.com/?page_id=21646\n\nhttps://myctregistryreview.com/courses/my-ct-registry-review-demo/lessons/ct-physics/\n"
  }
}