{
  "id": 600804,
  "title": "Nifti files are not aligned now",
  "url": "/competitions/rsna-intracranial-aneurysm-detection/discussion/600804",
  "author_name": "CristinaDaniela Popa",
  "post_date": "2025-08-25T05:57:17.132000",
  "votes": 0,
  "comment_count": 4,
  "views": 0,
  "content": "<p>Hi everyone, It looks like in the new version of the segmentation dataset, the simple .nii files and the _cowseg.nii files are no longer aligned. The shape, spacing and origin are now different per set, they were fine before update. Looking at this file 1.2.826.0.1.3680043.8.498.10035643165968342618460849823699311381_cowseg.nii I found Shape: (512, 512, 20), Voxels spacing: [0.4297     0.42970002 6.5       ]<br>\nImage origin:  [ 99.58613586 -57.20310974 -51.74690247]  and the corresponding file \"/kaggle/input/rsna-intracranial-aneurysm-detection/segmentations/1.2.826.0.1.3680043.8.498.10035643165968342618460849823699311381.nii\" has Shape: (512, 512, 228), Voxels dimension:  [0.47460938 0.47460938 0.7000122 ]<br>\nImage origin: [128.26269531 111.23730469 864.        ]. Are you experiencing the same problem? </p>",
  "messages": [
    {
      "id": 3274726,
      "postDate": "2025-08-25T10:59:27.383Z",
      "content": "<p>I am not able to reproduce this issue. For 1.2.826.0.1.3680043.8.498.10035643165968342618460849823699311381, I get:</p>\n<p>For the image:</p>\n<p><code>Spacing [0.474609, 0.474609, 0.700012]</code><br>\n<code>Origin [-128.263, -111.237, 864]</code><br>\n<code>Direction</code><br>\n<code>1 0 0</code><br>\n<code>0 -1 0</code><br>\n<code>0 0 1</code><br>\n<code>Image Dimensions   : [512, 512, 228]</code><br>\n<code>Bounding Box       : {[-128.263 -111.237 864], [114.737 131.763 1023.6]}</code></p>\n<p>And for the segmentation:</p>\n<p><code>Spacing [0.474609, 0.474609, 0.700012]</code><br>\n<code>Origin [-128.263, -111.237, 864]</code><br>\n<code>Direction</code><br>\n<code>1 0 0</code><br>\n<code>0 -1 0</code><br>\n<code>0 0 1</code><br>\n<code>Image Dimensions   : [512, 512, 228]</code><br>\n<code>Bounding Box       : {[-128.263 -111.237 864], [114.737 131.763 1023.6]}</code></p>\n<p>Here is what I get when I load them in ITK-Snap I can see that they are correctly aligned:<br>\n<img src=\"https://www.googleapis.com/download/storage/v1/b/kaggle-forum-message-attachments/o/inbox%2F8734370%2F239ae26bca82c720d61a3e529e52680c%2FScreenshot%202025-08-25%20at%206.56.01AM.png?generation=1756119376761987&amp;alt=media\" alt=\"\"></p>\n<p>Can you let me know how you are loading your data and examining the header/shape? Perhaps that will reveal the issue.</p>",
      "rawMarkdown": "I am not able to reproduce this issue. For 1.2.826.0.1.3680043.8.498.10035643165968342618460849823699311381, I get:\n\nFor the image:\n\n```Spacing [0.474609, 0.474609, 0.700012]```\n```Origin [-128.263, -111.237, 864]```\n```Direction```\n```1 0 0```\n```0 -1 0```\n```0 0 1```\n```Image Dimensions   : [512, 512, 228]```\n```Bounding Box       : {[-128.263 -111.237 864], [114.737 131.763 1023.6]}```\n\nAnd for the segmentation:\n\n```Spacing [0.474609, 0.474609, 0.700012]```\n```Origin [-128.263, -111.237, 864]```\n```Direction```\n```1 0 0```\n```0 -1 0```\n```0 0 1```\n```Image Dimensions   : [512, 512, 228]```\n```Bounding Box       : {[-128.263 -111.237 864], [114.737 131.763 1023.6]}```\n\nHere is what I get when I load them in ITK-Snap I can see that they are correctly aligned:\n![](https://www.googleapis.com/download/storage/v1/b/kaggle-forum-message-attachments/o/inbox%2F8734370%2F239ae26bca82c720d61a3e529e52680c%2FScreenshot%202025-08-25%20at%206.56.01AM.png?generation=1756119376761987&alt=media)\n\nCan you let me know how you are loading your data and examining the header/shape? Perhaps that will reveal the issue.",
      "replies": [
        {
          "id": 3274729,
          "postDate": "2025-08-25T11:14:11.467Z",
          "content": "<p>Here is my code, beginner here :)<br>\nfile_path_1 = \"/kaggle/input/rsna-intracranial-aneurysm-detection/segmentations/1.2.826.0.1.3680043.8.498.10035643165968342618460849823699311381_cowseg.nii\"</p>\n<h1>Load the NIfTI file</h1>\n<p>cowseg_img = nib.load(file_path_1)</p>\n<h1>Get the image data as a numpy array</h1>\n<p>cowseg_data = cowseg_img.get_fdata()</p>\n<h1>Voxel spacing</h1>\n<p>cowseg_header = cowseg_img.header<br>\ncowseg_pixdim = cowseg_header['pixdim'][1:4]</p>\n<p>cowseg_affine = cowseg_img.affine<br>\ncowseg_origin = cowseg_affine[:3, 3]</p>\n<h1>Inspect basic properties</h1>\n<p>print(\"Shape:\", cowseg_data.shape)<br>\nprint(\"Data type:\", cowseg_data.dtype)<br>\nprint(\"Min value:\", np.min(cowseg_data))<br>\nprint(\"Max value:\", np.max(cowseg_data))<br>\nprint(\"Unique values:\", np.unique(cowseg_data))</p>\n<p>print(\"Voxels spacing:\", cowseg_pixdim)<br>\nprint(\"Image origin: \", cowseg_origin)</p>\n<p>simple_path = \"/kaggle/input/rsna-intracranial-aneurysm-detection/segmentations/1.2.826.0.1.3680043.8.498.10035643165968342618460849823699311381.nii\"</p>\n<h1>Load the aneurysm segmentation</h1>\n<p>seg = nib.load(simple_path)<br>\nsimple_data = seg.get_fdata()<br>\nsimple_header = seg.header<br>\nsimple_pixdim = simple_header['pixdim'][1:4]</p>\n<p>simple_affine = seg.affine<br>\nsimple_origin = simple_affine[:3, 3]</p>\n<h1>Inspect basic properties</h1>\n<p>print(\"Shape:\", simple_data.shape)<br>\nprint(\"Data type:\", simple_data.dtype)<br>\nprint(\"Min value:\", np.min(simple_data))<br>\nprint(\"Max value:\", np.max(simple_data))<br>\nprint(\"Unique values:\", np.unique(simple_data))</p>\n<p>print(\"Voxels dimension: \", simple_pixdim)<br>\nprint(\"Image origin:\", simple_origin)</p>",
          "rawMarkdown": "Here is my code, beginner here :)\nfile_path_1 = \"/kaggle/input/rsna-intracranial-aneurysm-detection/segmentations/1.2.826.0.1.3680043.8.498.10035643165968342618460849823699311381_cowseg.nii\"\n# Load the NIfTI file\ncowseg_img = nib.load(file_path_1)\n\n# Get the image data as a numpy array\ncowseg_data = cowseg_img.get_fdata()\n\n#Voxel spacing\ncowseg_header = cowseg_img.header\ncowseg_pixdim = cowseg_header['pixdim'][1:4]\n\ncowseg_affine = cowseg_img.affine\ncowseg_origin = cowseg_affine[:3, 3]\n\n# Inspect basic properties\nprint(\"Shape:\", cowseg_data.shape)\nprint(\"Data type:\", cowseg_data.dtype)\nprint(\"Min value:\", np.min(cowseg_data))\nprint(\"Max value:\", np.max(cowseg_data))\nprint(\"Unique values:\", np.unique(cowseg_data))\n\nprint(\"Voxels spacing:\", cowseg_pixdim)\nprint(\"Image origin: \", cowseg_origin)\n\nsimple_path = \"/kaggle/input/rsna-intracranial-aneurysm-detection/segmentations/1.2.826.0.1.3680043.8.498.10035643165968342618460849823699311381.nii\"\n\n# Load the aneurysm segmentation\nseg = nib.load(simple_path)\nsimple_data = seg.get_fdata()\nsimple_header = seg.header\nsimple_pixdim = simple_header['pixdim'][1:4]\n\nsimple_affine = seg.affine\nsimple_origin = simple_affine[:3, 3]\n\n# Inspect basic properties\nprint(\"Shape:\", simple_data.shape)\nprint(\"Data type:\", simple_data.dtype)\nprint(\"Min value:\", np.min(simple_data))\nprint(\"Max value:\", np.max(simple_data))\nprint(\"Unique values:\", np.unique(simple_data))\n\nprint(\"Voxels dimension: \", simple_pixdim)\nprint(\"Image origin:\", simple_origin)",
          "replies": [
            {
              "id": 3274733,
              "postDate": "2025-08-25T11:21:46.420Z",
              "content": "<p>It's working now. I don't know why but looks fine now. <a href=\"https://www.kaggle.com/evancalabrese\" target=\"_blank\">@evancalabrese</a>, thank you for your response!</p>",
              "rawMarkdown": "It's working now. I don't know why but looks fine now. @evancalabrese, thank you for your response!"
            },
            {
              "id": 3274810,
              "postDate": "2025-08-25T13:28:04.393Z",
              "content": "<p>Thats great news! Thanks for the update.</p>",
              "rawMarkdown": "Thats great news! Thanks for the update."
            }
          ]
        }
      ]
    },
    {
      "id": 3274607,
      "postDate": "2025-08-25T05:57:17.133Z",
      "content": "<p>Hi everyone, It looks like in the new version of the segmentation dataset, the simple .nii files and the _cowseg.nii files are no longer aligned. The shape, spacing and origin are now different per set, they were fine before update. Looking at this file 1.2.826.0.1.3680043.8.498.10035643165968342618460849823699311381_cowseg.nii I found Shape: (512, 512, 20), Voxels spacing: [0.4297     0.42970002 6.5       ]<br>\nImage origin:  [ 99.58613586 -57.20310974 -51.74690247]  and the corresponding file \"/kaggle/input/rsna-intracranial-aneurysm-detection/segmentations/1.2.826.0.1.3680043.8.498.10035643165968342618460849823699311381.nii\" has Shape: (512, 512, 228), Voxels dimension:  [0.47460938 0.47460938 0.7000122 ]<br>\nImage origin: [128.26269531 111.23730469 864.        ]. Are you experiencing the same problem? </p>",
      "rawMarkdown": "Hi everyone, It looks like in the new version of the segmentation dataset, the simple .nii files and the _cowseg.nii files are no longer aligned. The shape, spacing and origin are now different per set, they were fine before update. Looking at this file 1.2.826.0.1.3680043.8.498.10035643165968342618460849823699311381_cowseg.nii I found Shape: (512, 512, 20), Voxels spacing: [0.4297     0.42970002 6.5       ]\nImage origin:  [ 99.58613586 -57.20310974 -51.74690247]  and the corresponding file \"/kaggle/input/rsna-intracranial-aneurysm-detection/segmentations/1.2.826.0.1.3680043.8.498.10035643165968342618460849823699311381.nii\" has Shape: (512, 512, 228), Voxels dimension:  [0.47460938 0.47460938 0.7000122 ]\nImage origin: [128.26269531 111.23730469 864.        ]. Are you experiencing the same problem? "
    }
  ],
  "comments": [
    {
      "id": 3274726,
      "author_name": "Evan Calabrese",
      "author_url": "",
      "post_date": "2025-08-25T10:59:27.383000",
      "content": "<p>I am not able to reproduce this issue. For 1.2.826.0.1.3680043.8.498.10035643165968342618460849823699311381, I get:</p>\n<p>For the image:</p>\n<p><code>Spacing [0.474609, 0.474609, 0.700012]</code><br>\n<code>Origin [-128.263, -111.237, 864]</code><br>\n<code>Direction</code><br>\n<code>1 0 0</code><br>\n<code>0 -1 0</code><br>\n<code>0 0 1</code><br>\n<code>Image Dimensions   : [512, 512, 228]</code><br>\n<code>Bounding Box       : {[-128.263 -111.237 864], [114.737 131.763 1023.6]}</code></p>\n<p>And for the segmentation:</p>\n<p><code>Spacing [0.474609, 0.474609, 0.700012]</code><br>\n<code>Origin [-128.263, -111.237, 864]</code><br>\n<code>Direction</code><br>\n<code>1 0 0</code><br>\n<code>0 -1 0</code><br>\n<code>0 0 1</code><br>\n<code>Image Dimensions   : [512, 512, 228]</code><br>\n<code>Bounding Box       : {[-128.263 -111.237 864], [114.737 131.763 1023.6]}</code></p>\n<p>Here is what I get when I load them in ITK-Snap I can see that they are correctly aligned:<br>\n<img src=\"https://www.googleapis.com/download/storage/v1/b/kaggle-forum-message-attachments/o/inbox%2F8734370%2F239ae26bca82c720d61a3e529e52680c%2FScreenshot%202025-08-25%20at%206.56.01AM.png?generation=1756119376761987&amp;alt=media\" alt=\"\"></p>\n<p>Can you let me know how you are loading your data and examining the header/shape? Perhaps that will reveal the issue.</p>",
      "votes": 0,
      "replies": [
        {
          "id": 3274729,
          "author_name": "CristinaDaniela Popa",
          "author_url": "",
          "post_date": "2025-08-25T11:14:11.467000",
          "content": "<p>Here is my code, beginner here :)<br>\nfile_path_1 = \"/kaggle/input/rsna-intracranial-aneurysm-detection/segmentations/1.2.826.0.1.3680043.8.498.10035643165968342618460849823699311381_cowseg.nii\"</p>\n<h1>Load the NIfTI file</h1>\n<p>cowseg_img = nib.load(file_path_1)</p>\n<h1>Get the image data as a numpy array</h1>\n<p>cowseg_data = cowseg_img.get_fdata()</p>\n<h1>Voxel spacing</h1>\n<p>cowseg_header = cowseg_img.header<br>\ncowseg_pixdim = cowseg_header['pixdim'][1:4]</p>\n<p>cowseg_affine = cowseg_img.affine<br>\ncowseg_origin = cowseg_affine[:3, 3]</p>\n<h1>Inspect basic properties</h1>\n<p>print(\"Shape:\", cowseg_data.shape)<br>\nprint(\"Data type:\", cowseg_data.dtype)<br>\nprint(\"Min value:\", np.min(cowseg_data))<br>\nprint(\"Max value:\", np.max(cowseg_data))<br>\nprint(\"Unique values:\", np.unique(cowseg_data))</p>\n<p>print(\"Voxels spacing:\", cowseg_pixdim)<br>\nprint(\"Image origin: \", cowseg_origin)</p>\n<p>simple_path = \"/kaggle/input/rsna-intracranial-aneurysm-detection/segmentations/1.2.826.0.1.3680043.8.498.10035643165968342618460849823699311381.nii\"</p>\n<h1>Load the aneurysm segmentation</h1>\n<p>seg = nib.load(simple_path)<br>\nsimple_data = seg.get_fdata()<br>\nsimple_header = seg.header<br>\nsimple_pixdim = simple_header['pixdim'][1:4]</p>\n<p>simple_affine = seg.affine<br>\nsimple_origin = simple_affine[:3, 3]</p>\n<h1>Inspect basic properties</h1>\n<p>print(\"Shape:\", simple_data.shape)<br>\nprint(\"Data type:\", simple_data.dtype)<br>\nprint(\"Min value:\", np.min(simple_data))<br>\nprint(\"Max value:\", np.max(simple_data))<br>\nprint(\"Unique values:\", np.unique(simple_data))</p>\n<p>print(\"Voxels dimension: \", simple_pixdim)<br>\nprint(\"Image origin:\", simple_origin)</p>",
          "votes": 0,
          "replies": [
            {
              "id": 3274733,
              "author_name": "CristinaDaniela Popa",
              "author_url": "",
              "post_date": "2025-08-25T11:21:46.420000",
              "content": "<p>It's working now. I don't know why but looks fine now. <a href=\"https://www.kaggle.com/evancalabrese\" target=\"_blank\">@evancalabrese</a>, thank you for your response!</p>",
              "votes": 0,
              "replies": []
            },
            {
              "id": 3274810,
              "author_name": "Evan Calabrese",
              "author_url": "",
              "post_date": "2025-08-25T13:28:04.393000",
              "content": "<p>Thats great news! Thanks for the update.</p>",
              "votes": 0,
              "replies": []
            }
          ]
        }
      ]
    }
  ],
  "raw_markdown_by_id": {
    "3274726": "I am not able to reproduce this issue. For 1.2.826.0.1.3680043.8.498.10035643165968342618460849823699311381, I get:\n\nFor the image:\n\n```Spacing [0.474609, 0.474609, 0.700012]```\n```Origin [-128.263, -111.237, 864]```\n```Direction```\n```1 0 0```\n```0 -1 0```\n```0 0 1```\n```Image Dimensions   : [512, 512, 228]```\n```Bounding Box       : {[-128.263 -111.237 864], [114.737 131.763 1023.6]}```\n\nAnd for the segmentation:\n\n```Spacing [0.474609, 0.474609, 0.700012]```\n```Origin [-128.263, -111.237, 864]```\n```Direction```\n```1 0 0```\n```0 -1 0```\n```0 0 1```\n```Image Dimensions   : [512, 512, 228]```\n```Bounding Box       : {[-128.263 -111.237 864], [114.737 131.763 1023.6]}```\n\nHere is what I get when I load them in ITK-Snap I can see that they are correctly aligned:\n![](https://www.googleapis.com/download/storage/v1/b/kaggle-forum-message-attachments/o/inbox%2F8734370%2F239ae26bca82c720d61a3e529e52680c%2FScreenshot%202025-08-25%20at%206.56.01AM.png?generation=1756119376761987&alt=media)\n\nCan you let me know how you are loading your data and examining the header/shape? Perhaps that will reveal the issue.",
    "3274607": "Hi everyone, It looks like in the new version of the segmentation dataset, the simple .nii files and the _cowseg.nii files are no longer aligned. The shape, spacing and origin are now different per set, they were fine before update. Looking at this file 1.2.826.0.1.3680043.8.498.10035643165968342618460849823699311381_cowseg.nii I found Shape: (512, 512, 20), Voxels spacing: [0.4297     0.42970002 6.5       ]\nImage origin:  [ 99.58613586 -57.20310974 -51.74690247]  and the corresponding file \"/kaggle/input/rsna-intracranial-aneurysm-detection/segmentations/1.2.826.0.1.3680043.8.498.10035643165968342618460849823699311381.nii\" has Shape: (512, 512, 228), Voxels dimension:  [0.47460938 0.47460938 0.7000122 ]\nImage origin: [128.26269531 111.23730469 864.        ]. Are you experiencing the same problem? "
  }
}