{
  "id": 435392,
  "title": "Normalizing pixel spacing",
  "url": "/competitions/rsna-2023-abdominal-trauma-detection/discussion/435392",
  "author_name": "Gunes Evitan",
  "post_date": "2023-08-29T07:11:35.069000",
  "votes": 1,
  "comment_count": 10,
  "views": 0,
  "content": "<p>I noticed that I haven't done this for a while on similar datasets. I tried training on both with and without normalized pixel spacing and there was very little difference in terms of score.</p>\n<p>Some of the scans have asymmetrical pixel spacings. They could be distorted after normalizing pixel values and resizing while training. Do you think it's a good practice? </p>",
  "messages": [
    {
      "id": 2414148,
      "postDate": "2023-08-29T12:25:17.590Z",
      "content": "<p>I didn't observe any improvement in my scores when I resized the data to 1mm and 1.5mm isotropic resolution. I believe the varied pixel spacing and slice thickness values act as good spatio-temporal augmentations.</p>",
      "rawMarkdown": "I didn't observe any improvement in my scores when I resized the data to 1mm and 1.5mm isotropic resolution. I believe the varied pixel spacing and slice thickness values act as good spatio-temporal augmentations.",
      "votes": 1,
      "replies": [
        {
          "id": 2414154,
          "postDate": "2023-08-29T12:29:37.013Z",
          "content": "<p>Yeah it makes sense. I didn't think of it like that.</p>",
          "rawMarkdown": "Yeah it makes sense. I didn't think of it like that."
        }
      ]
    },
    {
      "id": 2414135,
      "postDate": "2023-08-29T12:16:30.220Z",
      "content": "<p>my suggestion is as follows:</p>\n<ol>\n<li><p>use monai datset to do quick experiment (it has easy to use data transform to align nii and dicom; and resample the correct pixdim (i.e. spatial spacing))</p></li>\n<li><p>later, you have write native code for inference in submission to replace monai data api ( monai resampling is using F.interpolate)</p></li>\n</ol>\n<pre><code>https://github./Project-MONAI/tutorials\nd_classification\nd_segmentation\n\n\nnull_transform = MT.Compose([\n    MT.LoadImaged(=[, ]),\n    MT.EnsureChannelFirstd(=[, ]), \n    MT.CropForegroundd(=[, ], source_key=),\n    MT.Orientationd(=[, ], axcodes=),\n    MT.Spacingd(\n        =[, ],\n        pixdim=(, , ),\n        =(, ),\n    ),\n    MT.DivisiblePadd(\n        =[, ],\n        =,\n         = ,\n    ),\n])\n</code></pre>\n<p>navie code</p>\n<pre><code>dicom tag related to spacing\n#  Pixel Spacing      : [., .]\n\nfirst slice:\n(, ) (, ) Image Position (Patient)            : : [X_first   Y_first   Z_first] = [-., -., -.]\n\nlast slice:\n(, ) (, ) Image Position (Patient)            : [X_last   Y_last     Z_last]\n\ne.g. original size \n(, ) = D,H,W\n\n#------------------------------------\nMT.Spacingd\n\nPixel Spacing in dz = (Z_last - Z_first)/(num of slice)\n\nnew D = *dz                        = .\nnew H = *.           = \nnew W = *. =.\n</code></pre>",
      "rawMarkdown": "my suggestion is as follows:\n\n1. use monai datset to do quick experiment (it has easy to use data transform to align nii and dicom; and resample the correct pixdim (i.e. spatial spacing))\n\n2. later, you have write native code for inference in submission to replace monai data api ( monai resampling is using F.interpolate)\n\n```\nhttps://github.com/Project-MONAI/tutorials\n3d_classification\n3d_segmentation\n\n\nnull_transform = MT.Compose([\n\tMT.LoadImaged(keys=['image', 'mask']),\n\tMT.EnsureChannelFirstd(keys=['image', 'mask']), \n\tMT.CropForegroundd(keys=['image', 'mask'], source_key='image'),\n\tMT.Orientationd(keys=['image', 'mask'], axcodes='RAS'),\n\tMT.Spacingd(\n\t\tkeys=['image', 'mask'],\n\t\tpixdim=(1.5, 1.5, 3.0),\n\t\tmode=('bilinear', 'nearest'),\n\t),\n\tMT.DivisiblePadd(\n\t\tkeys=['image', 'mask'],\n\t\tk=32,\n\t\tmode = 'edge',\n\t),\n])\n\n```\n\n\n\nnavie code\n```\ndicom tag related to spacing\n#  Pixel Spacing      : [0.544921875, 0.54531722054381]\n\nfirst slice:\n(0020, 0032) (0020, 0032) Image Position (Patient)            DS: : [X_first   Y_first   Z_first] = [-183.07153670002, -279.42855597498, -425.87080705128]\n \nlast slice:\n(0020, 0032) (0020, 0032) Image Position (Patient)            DS: [X_last   Y_last     Z_last]\n\ne.g. original size \n(104, 662,512) = D,H,W\n\n#------------------------------------\nMT.Spacingd\n\nPixel Spacing in dz = (Z_last - Z_first)/(num of slice)\n\nnew D = 104/1.5*dz                        = 208.0\nnew H = 662/1.5*0.544921875           = 240.4921875\nnew W = 512/1.5*0.54531722054381 =186.13494461228714\n\n\n```",
      "votes": 1,
      "replies": [
        {
          "id": 2414147,
          "postDate": "2023-08-29T12:25:01.390Z",
          "content": "<p>Slice Thickness isn't used in the pixel spacing calculation for z-axis. Slices may overlap, or have gaps between them. Use the Z component of ImagePositionPatient to determine the distance between slices. Otherwise, measurements in the z-axis will not be correct.</p>",
          "rawMarkdown": "Slice Thickness isn't used in the pixel spacing calculation for z-axis. Slices may overlap, or have gaps between them. Use the Z component of ImagePositionPatient to determine the distance between slices. Otherwise, measurements in the z-axis will not be correct.",
          "replies": [
            {
              "id": 2414233,
              "postDate": "2023-08-29T13:43:34.337Z",
              "content": "<p><a href=\"https://www.kaggle.com/davidbroberts\" target=\"_blank\">@davidbroberts</a> <br>\nyou are correct. i have corrected the formula. thanks!</p>\n<p>for those who want to know more, please see<br>\n\"The First Step for Neuroimaging Data Analysis: DICOM to NIfTI conversion\"<br>\n<a href=\"https://core.ac.uk/download/pdf/79518053.pdf\" target=\"_blank\">https://core.ac.uk/download/pdf/79518053.pdf</a></p>\n<p><img src=\"https://www.googleapis.com/download/storage/v1/b/kaggle-forum-message-attachments/o/inbox%2F113660%2Fe94a11bb54f0e94f007a9ebc49a91281%2FSelection_999(2993).png?generation=1693316578527397&amp;alt=media\" alt=\"\"></p>\n<p>the spacing are the diagonal entries of the matrix in eqn(1)</p>",
              "rawMarkdown": "@davidbroberts \nyou are correct. i have corrected the formula. thanks!\n\nfor those who want to know more, please see\n\"The First Step for Neuroimaging Data Analysis: DICOM to NIfTI conversion\"\nhttps://core.ac.uk/download/pdf/79518053.pdf\n\n\n![](https://www.googleapis.com/download/storage/v1/b/kaggle-forum-message-attachments/o/inbox%2F113660%2Fe94a11bb54f0e94f007a9ebc49a91281%2FSelection_999(2993).png?generation=1693316578527397&alt=media)\n\nthe spacing are the diagonal entries of the matrix in eqn(1)",
              "votes": 2
            },
            {
              "id": 2417186,
              "postDate": "2023-08-31T13:22:54.210Z",
              "content": "<p><a href=\"https://www.kaggle.com/hengck23\" target=\"_blank\">@hengck23</a> this PDF says I can compute transformation matrix, but it seems that the rotation part is not valid rotation matrix.<img src=\"https://www.googleapis.com/download/storage/v1/b/kaggle-forum-message-attachments/o/inbox%2F5506850%2F242994240b1f6a9a1c359092f38dbd94%2FScreenshot%20from%202023-08-31%2015-20-45.png?generation=1693488147677706&amp;alt=media\" alt=\"\"><br>\nAm I doing something wrong or I should just normalize rotation matrix?</p>",
              "rawMarkdown": "@hengck23 this PDF says I can compute transformation matrix, but it seems that the rotation part is not valid rotation matrix.![](https://www.googleapis.com/download/storage/v1/b/kaggle-forum-message-attachments/o/inbox%2F5506850%2F242994240b1f6a9a1c359092f38dbd94%2FScreenshot%20from%202023-08-31%2015-20-45.png?generation=1693488147677706&alt=media)\nAm I doing something wrong or I should just normalize rotation matrix?"
            }
          ]
        }
      ]
    },
    {
      "id": 2414116,
      "postDate": "2023-08-29T12:03:00.193Z",
      "content": "<p>I don't think pixel spacing would be of any use, unless you were mapping measurements to real world distances (mm/cm).</p>",
      "rawMarkdown": "I don't think pixel spacing would be of any use, unless you were mapping measurements to real world distances (mm/cm).",
      "votes": 1,
      "replies": [
        {
          "id": 2414125,
          "postDate": "2023-08-29T12:09:07.813Z",
          "content": "<p>That's exactly why I'm doing it. I'm forcing each slice to have 1mm pixel spacing on x and y axes so the things we are looking for would have consistent sizes.</p>",
          "rawMarkdown": "That's exactly why I'm doing it. I'm forcing each slice to have 1mm pixel spacing on x and y axes so the things we are looking for would have consistent sizes.",
          "replies": [
            {
              "id": 2414140,
              "postDate": "2023-08-29T12:19:47.387Z",
              "content": "<p>Ahh, yeah. It seems strange but, not all pixels are square. That's why spacing values aren't the same for x and y in some images. Since all CT images are \"reconstructions\" of raw voxel data and they're done with various techniques across vendors, it's difficult to standardize spatial stuff. With some creative cropping/zooming, you can probably get the sizes pretty close to standardized. </p>",
              "rawMarkdown": "Ahh, yeah. It seems strange but, not all pixels are square. That's why spacing values aren't the same for x and y in some images. Since all CT images are \"reconstructions\" of raw voxel data and they're done with various techniques across vendors, it's difficult to standardize spatial stuff. With some creative cropping/zooming, you can probably get the sizes pretty close to standardized. ",
              "votes": 2
            },
            {
              "id": 2415526,
              "postDate": "2023-08-30T12:21:10.723Z",
              "content": "<p>Thanks for the explanation.</p>",
              "rawMarkdown": "Thanks for the explanation."
            }
          ]
        }
      ]
    },
    {
      "id": 2413801,
      "postDate": "2023-08-29T07:11:35.070Z",
      "content": "<p>I noticed that I haven't done this for a while on similar datasets. I tried training on both with and without normalized pixel spacing and there was very little difference in terms of score.</p>\n<p>Some of the scans have asymmetrical pixel spacings. They could be distorted after normalizing pixel values and resizing while training. Do you think it's a good practice? </p>",
      "rawMarkdown": "I noticed that I haven't done this for a while on similar datasets. I tried training on both with and without normalized pixel spacing and there was very little difference in terms of score.\n\nSome of the scans have asymmetrical pixel spacings. They could be distorted after normalizing pixel values and resizing while training. Do you think it's a good practice? ",
      "votes": 1
    }
  ],
  "comments": [
    {
      "id": 2414148,
      "author_name": "Jebastin Nadar",
      "author_url": "",
      "post_date": "2023-08-29T12:25:17.590000",
      "content": "<p>I didn't observe any improvement in my scores when I resized the data to 1mm and 1.5mm isotropic resolution. I believe the varied pixel spacing and slice thickness values act as good spatio-temporal augmentations.</p>",
      "votes": 1,
      "replies": [
        {
          "id": 2414154,
          "author_name": "Gunes Evitan",
          "author_url": "",
          "post_date": "2023-08-29T12:29:37.013000",
          "content": "<p>Yeah it makes sense. I didn't think of it like that.</p>",
          "votes": 0,
          "replies": []
        }
      ]
    },
    {
      "id": 2414135,
      "author_name": "hengck23",
      "author_url": "",
      "post_date": "2023-08-29T12:16:30.220000",
      "content": "<p>my suggestion is as follows:</p>\n<ol>\n<li><p>use monai datset to do quick experiment (it has easy to use data transform to align nii and dicom; and resample the correct pixdim (i.e. spatial spacing))</p></li>\n<li><p>later, you have write native code for inference in submission to replace monai data api ( monai resampling is using F.interpolate)</p></li>\n</ol>\n<pre><code>https://github./Project-MONAI/tutorials\nd_classification\nd_segmentation\n\n\nnull_transform = MT.Compose([\n    MT.LoadImaged(=[, ]),\n    MT.EnsureChannelFirstd(=[, ]), \n    MT.CropForegroundd(=[, ], source_key=),\n    MT.Orientationd(=[, ], axcodes=),\n    MT.Spacingd(\n        =[, ],\n        pixdim=(, , ),\n        =(, ),\n    ),\n    MT.DivisiblePadd(\n        =[, ],\n        =,\n         = ,\n    ),\n])\n</code></pre>\n<p>navie code</p>\n<pre><code>dicom tag related to spacing\n#  Pixel Spacing      : [., .]\n\nfirst slice:\n(, ) (, ) Image Position (Patient)            : : [X_first   Y_first   Z_first] = [-., -., -.]\n\nlast slice:\n(, ) (, ) Image Position (Patient)            : [X_last   Y_last     Z_last]\n\ne.g. original size \n(, ) = D,H,W\n\n#------------------------------------\nMT.Spacingd\n\nPixel Spacing in dz = (Z_last - Z_first)/(num of slice)\n\nnew D = *dz                        = .\nnew H = *.           = \nnew W = *. =.\n</code></pre>",
      "votes": 1,
      "replies": [
        {
          "id": 2414147,
          "author_name": "David Roberts",
          "author_url": "",
          "post_date": "2023-08-29T12:25:01.390000",
          "content": "<p>Slice Thickness isn't used in the pixel spacing calculation for z-axis. Slices may overlap, or have gaps between them. Use the Z component of ImagePositionPatient to determine the distance between slices. Otherwise, measurements in the z-axis will not be correct.</p>",
          "votes": 0,
          "replies": [
            {
              "id": 2414233,
              "author_name": "hengck23",
              "author_url": "",
              "post_date": "2023-08-29T13:43:34.337000",
              "content": "<p><a href=\"https://www.kaggle.com/davidbroberts\" target=\"_blank\">@davidbroberts</a> <br>\nyou are correct. i have corrected the formula. thanks!</p>\n<p>for those who want to know more, please see<br>\n\"The First Step for Neuroimaging Data Analysis: DICOM to NIfTI conversion\"<br>\n<a href=\"https://core.ac.uk/download/pdf/79518053.pdf\" target=\"_blank\">https://core.ac.uk/download/pdf/79518053.pdf</a></p>\n<p><img src=\"https://www.googleapis.com/download/storage/v1/b/kaggle-forum-message-attachments/o/inbox%2F113660%2Fe94a11bb54f0e94f007a9ebc49a91281%2FSelection_999(2993).png?generation=1693316578527397&amp;alt=media\" alt=\"\"></p>\n<p>the spacing are the diagonal entries of the matrix in eqn(1)</p>",
              "votes": 2,
              "replies": []
            },
            {
              "id": 2417186,
              "author_name": "JanGlinko2",
              "author_url": "",
              "post_date": "2023-08-31T13:22:54.210000",
              "content": "<p><a href=\"https://www.kaggle.com/hengck23\" target=\"_blank\">@hengck23</a> this PDF says I can compute transformation matrix, but it seems that the rotation part is not valid rotation matrix.<img src=\"https://www.googleapis.com/download/storage/v1/b/kaggle-forum-message-attachments/o/inbox%2F5506850%2F242994240b1f6a9a1c359092f38dbd94%2FScreenshot%20from%202023-08-31%2015-20-45.png?generation=1693488147677706&amp;alt=media\" alt=\"\"><br>\nAm I doing something wrong or I should just normalize rotation matrix?</p>",
              "votes": 0,
              "replies": []
            }
          ]
        }
      ]
    },
    {
      "id": 2414116,
      "author_name": "David Roberts",
      "author_url": "",
      "post_date": "2023-08-29T12:03:00.193000",
      "content": "<p>I don't think pixel spacing would be of any use, unless you were mapping measurements to real world distances (mm/cm).</p>",
      "votes": 1,
      "replies": [
        {
          "id": 2414125,
          "author_name": "Gunes Evitan",
          "author_url": "",
          "post_date": "2023-08-29T12:09:07.813000",
          "content": "<p>That's exactly why I'm doing it. I'm forcing each slice to have 1mm pixel spacing on x and y axes so the things we are looking for would have consistent sizes.</p>",
          "votes": 0,
          "replies": [
            {
              "id": 2414140,
              "author_name": "David Roberts",
              "author_url": "",
              "post_date": "2023-08-29T12:19:47.387000",
              "content": "<p>Ahh, yeah. It seems strange but, not all pixels are square. That's why spacing values aren't the same for x and y in some images. Since all CT images are \"reconstructions\" of raw voxel data and they're done with various techniques across vendors, it's difficult to standardize spatial stuff. With some creative cropping/zooming, you can probably get the sizes pretty close to standardized. </p>",
              "votes": 2,
              "replies": []
            },
            {
              "id": 2415526,
              "author_name": "Antonio Félix",
              "author_url": "",
              "post_date": "2023-08-30T12:21:10.723000",
              "content": "<p>Thanks for the explanation.</p>",
              "votes": 0,
              "replies": []
            }
          ]
        }
      ]
    }
  ],
  "raw_markdown_by_id": {
    "2414148": "I didn't observe any improvement in my scores when I resized the data to 1mm and 1.5mm isotropic resolution. I believe the varied pixel spacing and slice thickness values act as good spatio-temporal augmentations.",
    "2414135": "my suggestion is as follows:\n\n1. use monai datset to do quick experiment (it has easy to use data transform to align nii and dicom; and resample the correct pixdim (i.e. spatial spacing))\n\n2. later, you have write native code for inference in submission to replace monai data api ( monai resampling is using F.interpolate)\n\n```\nhttps://github.com/Project-MONAI/tutorials\n3d_classification\n3d_segmentation\n\n\nnull_transform = MT.Compose([\n\tMT.LoadImaged(keys=['image', 'mask']),\n\tMT.EnsureChannelFirstd(keys=['image', 'mask']), \n\tMT.CropForegroundd(keys=['image', 'mask'], source_key='image'),\n\tMT.Orientationd(keys=['image', 'mask'], axcodes='RAS'),\n\tMT.Spacingd(\n\t\tkeys=['image', 'mask'],\n\t\tpixdim=(1.5, 1.5, 3.0),\n\t\tmode=('bilinear', 'nearest'),\n\t),\n\tMT.DivisiblePadd(\n\t\tkeys=['image', 'mask'],\n\t\tk=32,\n\t\tmode = 'edge',\n\t),\n])\n\n```\n\n\n\nnavie code\n```\ndicom tag related to spacing\n#  Pixel Spacing      : [0.544921875, 0.54531722054381]\n\nfirst slice:\n(0020, 0032) (0020, 0032) Image Position (Patient)            DS: : [X_first   Y_first   Z_first] = [-183.07153670002, -279.42855597498, -425.87080705128]\n \nlast slice:\n(0020, 0032) (0020, 0032) Image Position (Patient)            DS: [X_last   Y_last     Z_last]\n\ne.g. original size \n(104, 662,512) = D,H,W\n\n#------------------------------------\nMT.Spacingd\n\nPixel Spacing in dz = (Z_last - Z_first)/(num of slice)\n\nnew D = 104/1.5*dz                        = 208.0\nnew H = 662/1.5*0.544921875           = 240.4921875\nnew W = 512/1.5*0.54531722054381 =186.13494461228714\n\n\n```",
    "2414116": "I don't think pixel spacing would be of any use, unless you were mapping measurements to real world distances (mm/cm).",
    "2413801": "I noticed that I haven't done this for a while on similar datasets. I tried training on both with and without normalized pixel spacing and there was very little difference in terms of score.\n\nSome of the scans have asymmetrical pixel spacings. They could be distorted after normalizing pixel values and resizing while training. Do you think it's a good practice? "
  }
}