{
  "id": 427795,
  "title": "Any Python Knight that could load the nifti files? Since we've No nii file extensions.",
  "url": "/competitions/rsna-2023-abdominal-trauma-detection/discussion/427795",
  "author_name": "Marília Prata",
  "post_date": "2023-07-29T15:31:04.902000",
  "votes": 25,
  "comment_count": 8,
  "views": 0,
  "content": "<p>Since we don't have the nii extensions on the nifti files, how can we load/work with them?</p>\n<p>I'm still waiting till any Kaggler publishes the way of working with those files without Nii.</p>\n<p><img src=\"https://www.googleapis.com/download/storage/v1/b/kaggle-forum-message-attachments/o/inbox%2F3012786%2F5ea4568eeab8cbd141d1b68d79618f39%2Fni%20-%20Copia.jpg?generation=1690642761087069&amp;alt=media\" alt=\"\"></p>\n<h1>The nifti file format (segmentations/annotations)</h1>\n<p><img src=\"https://www.googleapis.com/download/storage/v1/b/kaggle-forum-message-attachments/o/inbox%2F3012786%2Fd7253a80c545f52eff63b497fc100217%2Fformat%20-%20Copia.jpg?generation=1690643297141211&amp;alt=media\" alt=\"\"></p>\n<p>Even if some kagglers like or not the Monty Python references with \"The Knights Who Say \"Ni!\" - </p>\n<p>That will be my Holy Grail to learn on this competition.</p>",
  "messages": [
    {
      "id": 2364774,
      "postDate": "2023-07-29T15:31:04.903Z",
      "content": "<p>Since we don't have the nii extensions on the nifti files, how can we load/work with them?</p>\n<p>I'm still waiting till any Kaggler publishes the way of working with those files without Nii.</p>\n<p><img src=\"https://www.googleapis.com/download/storage/v1/b/kaggle-forum-message-attachments/o/inbox%2F3012786%2F5ea4568eeab8cbd141d1b68d79618f39%2Fni%20-%20Copia.jpg?generation=1690642761087069&amp;alt=media\" alt=\"\"></p>\n<h1>The nifti file format (segmentations/annotations)</h1>\n<p><img src=\"https://www.googleapis.com/download/storage/v1/b/kaggle-forum-message-attachments/o/inbox%2F3012786%2Fd7253a80c545f52eff63b497fc100217%2Fformat%20-%20Copia.jpg?generation=1690643297141211&amp;alt=media\" alt=\"\"></p>\n<p>Even if some kagglers like or not the Monty Python references with \"The Knights Who Say \"Ni!\" - </p>\n<p>That will be my Holy Grail to learn on this competition.</p>",
      "rawMarkdown": "Since we don't have the nii extensions on the nifti files, how can we load/work with them?\n\nI'm still waiting till any Kaggler publishes the way of working with those files without Nii.\n\n![](https://www.googleapis.com/download/storage/v1/b/kaggle-forum-message-attachments/o/inbox%2F3012786%2F5ea4568eeab8cbd141d1b68d79618f39%2Fni%20-%20Copia.jpg?generation=1690642761087069&alt=media)\n\n\n#The nifti file format (segmentations/annotations)\n![](https://www.googleapis.com/download/storage/v1/b/kaggle-forum-message-attachments/o/inbox%2F3012786%2Fd7253a80c545f52eff63b497fc100217%2Fformat%20-%20Copia.jpg?generation=1690643297141211&alt=media)\n\nEven if some kagglers like or not the Monty Python references with \"The Knights Who Say \"Ni!\" - \n\nThat will be my Holy Grail to learn on this competition.",
      "votes": 25
    },
    {
      "id": 2364860,
      "postDate": "2023-07-29T16:56:24.890Z",
      "content": "<p>I copy them to /kaggle/working and add the extension .. like this.</p>\n<pre><code> matplotlib.pylab  plt\n nibabel  nib\n shutil\n\n\nsrc = \ndst = \n\nshutil.copyfile(src, dst);\n\n\nimg = nib.load(dst).get_fdata()\n(img.shape)\n\n\nplt.imshow(img[:,:,])\nplt.show()\n</code></pre>",
      "rawMarkdown": "I copy them to /kaggle/working and add the extension .. like this.\n\n```python\nimport matplotlib.pylab as plt\nimport nibabel as nib\nimport shutil\n\n# Copy a random label file to /kaggle/working directory (without .nii file extension)\nsrc = '/kaggle/input/rsna-2023-abdominal-trauma-detection/segmentations/10000'\ndst = '/kaggle/working/1000.nii'\n\nshutil.copyfile(src, dst);\n\n# Check the shape\nimg = nib.load(dst).get_fdata()\nprint(img.shape)\n\n# Plot a single frame from the middle of the stack\nplt.imshow(img[:,:,150])\nplt.show()\n```",
      "votes": 6,
      "replies": [
        {
          "id": 2365053,
          "postDate": "2023-07-29T22:28:59.493Z",
          "content": "<p>Thank you David for being here to help me so many times.<br>\nIt worked perfectly.<br>\n With my lack of everything I highly appreciated the snippet. </p>",
          "rawMarkdown": "Thank you David for being here to help me so many times.\nIt worked perfectly.\n With my lack of everything I highly appreciated the snippet. ",
          "votes": 1,
          "replies": [
            {
              "id": 2366372,
              "postDate": "2023-07-31T00:09:56.243Z",
              "content": "<p><a href=\"https://www.kaggle.com/mpwolke\" target=\"_blank\">@mpwolke</a> Bring me .. a shrubbery!</p>",
              "rawMarkdown": "@mpwolke Bring me .. a shrubbery!",
              "votes": 1
            },
            {
              "id": 2369460,
              "postDate": "2023-08-01T18:49:44.190Z",
              "content": "<p>Yes Sir Roberts <a href=\"https://www.kaggle.com/davidroberts\" target=\"_blank\">@davidroberts</a> , The Kaggler Knight in shinning armour <br>\nBy the way, being a Sir is much better than a GM : )</p>\n<p>I'll bring you, promptly my Lord (but without chat prompts), a Shubbery.</p>\n<p><img src=\"https://www.googleapis.com/download/storage/v1/b/kaggle-forum-message-attachments/o/inbox%2F3012786%2Fd39e2db2b1d7ead4a242d8489817106b%2Fshubb%20-%20Copia.jpg?generation=1690915481721593&amp;alt=media\" alt=\"\"></p>",
              "rawMarkdown": "Yes Sir Roberts @davidroberts , The Kaggler Knight in shinning armour \nBy the way, being a Sir is much better than a GM : )\n\nI'll bring you, promptly my Lord (but without chat prompts), a Shubbery.\n\n![](https://www.googleapis.com/download/storage/v1/b/kaggle-forum-message-attachments/o/inbox%2F3012786%2Fd39e2db2b1d7ead4a242d8489817106b%2Fshubb%20-%20Copia.jpg?generation=1690915481721593&alt=media)\n\n "
            }
          ]
        },
        {
          "id": 2365211,
          "postDate": "2023-07-30T04:40:11.227Z",
          "content": "<p>thank you David, your code is very useful. But i have 2 question:</p>\n<ol>\n<li>How will the order of dicom files in the train directory be compatible with the mask in the segmentation directory?<br>\nEach file in the segmentation represents the segment mask of a series. But will each individual (512x512) mask correspond to which dicom image in that series? I try to sort the series folder in ascending numerical order, is it correct?</li>\n<li>I see there are multiple masks representing multiple organs in a series, each mask represents a value(1,2,3,4,5). But specifically which mask represents which organ? Example {liver: 1, extravasation: 2, kidney: 3, liver:4, spleen:5}.</li>\n</ol>",
          "rawMarkdown": "thank you David, your code is very useful. But i have 2 question:\n1. How will the order of dicom files in the train directory be compatible with the mask in the segmentation directory?\nEach file in the segmentation represents the segment mask of a series. But will each individual (512x512) mask correspond to which dicom image in that series? I try to sort the series folder in ascending numerical order, is it correct?\n2. I see there are multiple masks representing multiple organs in a series, each mask represents a value(1,2,3,4,5). But specifically which mask represents which organ? Example {liver: 1, extravasation: 2, kidney: 3, liver:4, spleen:5}.",
          "votes": 2
        }
      ]
    },
    {
      "id": 2369252,
      "postDate": "2023-08-01T16:07:15.260Z",
      "content": "<p>Probably this could help. Its old kernel and public now. <a href=\"https://www.kaggle.com/code/meenakshiramaswamy/npy2nii-latest\" target=\"_blank\">https://www.kaggle.com/code/meenakshiramaswamy/npy2nii-latest</a></p>",
      "rawMarkdown": "Probably this could help. Its old kernel and public now. https://www.kaggle.com/code/meenakshiramaswamy/npy2nii-latest",
      "votes": 1,
      "replies": [
        {
          "id": 2369303,
          "postDate": "2023-08-01T16:41:36.507Z",
          "content": "<p>The file extensions have been added to the dataset. They should open properly now.</p>",
          "rawMarkdown": "The file extensions have been added to the dataset. They should open properly now.",
          "votes": 1,
          "replies": [
            {
              "id": 2369489,
              "postDate": "2023-08-01T19:18:51.247Z",
              "content": "<p>Since the hosts added the Nii extensions now, I'm feeling less stupid.</p>\n<p>Though, I learned how to plot nii without Nii. Thanks to Sir David.</p>",
              "rawMarkdown": "Since the hosts added the Nii extensions now, I'm feeling less stupid.\n\nThough, I learned how to plot nii without Nii. Thanks to Sir David."
            }
          ]
        }
      ]
    }
  ],
  "comments": [
    {
      "id": 2364860,
      "author_name": "David Roberts",
      "author_url": "",
      "post_date": "2023-07-29T16:56:24.890000",
      "content": "<p>I copy them to /kaggle/working and add the extension .. like this.</p>\n<pre><code> matplotlib.pylab  plt\n nibabel  nib\n shutil\n\n\nsrc = \ndst = \n\nshutil.copyfile(src, dst);\n\n\nimg = nib.load(dst).get_fdata()\n(img.shape)\n\n\nplt.imshow(img[:,:,])\nplt.show()\n</code></pre>",
      "votes": 6,
      "replies": [
        {
          "id": 2365053,
          "author_name": "Marília Prata",
          "author_url": "",
          "post_date": "2023-07-29T22:28:59.493000",
          "content": "<p>Thank you David for being here to help me so many times.<br>\nIt worked perfectly.<br>\n With my lack of everything I highly appreciated the snippet. </p>",
          "votes": 1,
          "replies": [
            {
              "id": 2366372,
              "author_name": "David Roberts",
              "author_url": "",
              "post_date": "2023-07-31T00:09:56.243000",
              "content": "<p><a href=\"https://www.kaggle.com/mpwolke\" target=\"_blank\">@mpwolke</a> Bring me .. a shrubbery!</p>",
              "votes": 1,
              "replies": []
            },
            {
              "id": 2369460,
              "author_name": "Marília Prata",
              "author_url": "",
              "post_date": "2023-08-01T18:49:44.190000",
              "content": "<p>Yes Sir Roberts <a href=\"https://www.kaggle.com/davidroberts\" target=\"_blank\">@davidroberts</a> , The Kaggler Knight in shinning armour <br>\nBy the way, being a Sir is much better than a GM : )</p>\n<p>I'll bring you, promptly my Lord (but without chat prompts), a Shubbery.</p>\n<p><img src=\"https://www.googleapis.com/download/storage/v1/b/kaggle-forum-message-attachments/o/inbox%2F3012786%2Fd39e2db2b1d7ead4a242d8489817106b%2Fshubb%20-%20Copia.jpg?generation=1690915481721593&amp;alt=media\" alt=\"\"></p>",
              "votes": 0,
              "replies": []
            }
          ]
        },
        {
          "id": 2365211,
          "author_name": "Vietnamese-NHNAM",
          "author_url": "",
          "post_date": "2023-07-30T04:40:11.227000",
          "content": "<p>thank you David, your code is very useful. But i have 2 question:</p>\n<ol>\n<li>How will the order of dicom files in the train directory be compatible with the mask in the segmentation directory?<br>\nEach file in the segmentation represents the segment mask of a series. But will each individual (512x512) mask correspond to which dicom image in that series? I try to sort the series folder in ascending numerical order, is it correct?</li>\n<li>I see there are multiple masks representing multiple organs in a series, each mask represents a value(1,2,3,4,5). But specifically which mask represents which organ? Example {liver: 1, extravasation: 2, kidney: 3, liver:4, spleen:5}.</li>\n</ol>",
          "votes": 2,
          "replies": []
        }
      ]
    },
    {
      "id": 2369252,
      "author_name": "Meenakshi",
      "author_url": "",
      "post_date": "2023-08-01T16:07:15.260000",
      "content": "<p>Probably this could help. Its old kernel and public now. <a href=\"https://www.kaggle.com/code/meenakshiramaswamy/npy2nii-latest\" target=\"_blank\">https://www.kaggle.com/code/meenakshiramaswamy/npy2nii-latest</a></p>",
      "votes": 1,
      "replies": [
        {
          "id": 2369303,
          "author_name": "David Roberts",
          "author_url": "",
          "post_date": "2023-08-01T16:41:36.507000",
          "content": "<p>The file extensions have been added to the dataset. They should open properly now.</p>",
          "votes": 1,
          "replies": [
            {
              "id": 2369489,
              "author_name": "Marília Prata",
              "author_url": "",
              "post_date": "2023-08-01T19:18:51.247000",
              "content": "<p>Since the hosts added the Nii extensions now, I'm feeling less stupid.</p>\n<p>Though, I learned how to plot nii without Nii. Thanks to Sir David.</p>",
              "votes": 0,
              "replies": []
            }
          ]
        }
      ]
    }
  ],
  "raw_markdown_by_id": {
    "2364774": "Since we don't have the nii extensions on the nifti files, how can we load/work with them?\n\nI'm still waiting till any Kaggler publishes the way of working with those files without Nii.\n\n![](https://www.googleapis.com/download/storage/v1/b/kaggle-forum-message-attachments/o/inbox%2F3012786%2F5ea4568eeab8cbd141d1b68d79618f39%2Fni%20-%20Copia.jpg?generation=1690642761087069&alt=media)\n\n\n#The nifti file format (segmentations/annotations)\n![](https://www.googleapis.com/download/storage/v1/b/kaggle-forum-message-attachments/o/inbox%2F3012786%2Fd7253a80c545f52eff63b497fc100217%2Fformat%20-%20Copia.jpg?generation=1690643297141211&alt=media)\n\nEven if some kagglers like or not the Monty Python references with \"The Knights Who Say \"Ni!\" - \n\nThat will be my Holy Grail to learn on this competition.",
    "2364860": "I copy them to /kaggle/working and add the extension .. like this.\n\n```python\nimport matplotlib.pylab as plt\nimport nibabel as nib\nimport shutil\n\n# Copy a random label file to /kaggle/working directory (without .nii file extension)\nsrc = '/kaggle/input/rsna-2023-abdominal-trauma-detection/segmentations/10000'\ndst = '/kaggle/working/1000.nii'\n\nshutil.copyfile(src, dst);\n\n# Check the shape\nimg = nib.load(dst).get_fdata()\nprint(img.shape)\n\n# Plot a single frame from the middle of the stack\nplt.imshow(img[:,:,150])\nplt.show()\n```",
    "2369252": "Probably this could help. Its old kernel and public now. https://www.kaggle.com/code/meenakshiramaswamy/npy2nii-latest"
  }
}