{
  "id": 532360,
  "title": "The slices in a folder is not consecutive.",
  "url": "/competitions/rsna-2024-lumbar-spine-degenerative-classification/discussion/532360",
  "author_name": "",
  "post_date": "2024-09-05T22:45:12.901410100Z",
  "votes": 3,
  "comment_count": 4,
  "views": 0,
  "content": "<p>I was trying to load the entire folder as a volume and use conv3d on it. However, after some investigation, I realized that the slices in the same folder may not be consecutive.<br>\nSometimes, the spacing and size are different. Sometimes, the directions are different. I tried to load different volumes in the same folder separately and then tried to resample and merge them into the same volume. However, I found the coordinate system of the physical seems to change as well.<br>\nJust want to share my experiences so that you don't need to do the same.</p>\n<p>For example, these are how many consecutive volumes I found in the same folder:</p>\n<pre><code>  []\n  []\n  [, ]\n  []\n  []\n  []\n  []\n  [, , , , ]\n  []\n  []\n  []\n  [, , , , ]\n  [, , , , , , , ]\n  [, , , , , , , , , , , , , , , ]\n</code></pre>",
  "messages": [
    {
      "id": "2980527",
      "postDate": "09/05/2024 22:45:12",
      "content": "<p>I was trying to load the entire folder as a volume and use conv3d on it. However, after some investigation, I realized that the slices in the same folder may not be consecutive.<br>\nSometimes, the spacing and size are different. Sometimes, the directions are different. I tried to load different volumes in the same folder separately and then tried to resample and merge them into the same volume. However, I found the coordinate system of the physical seems to change as well.<br>\nJust want to share my experiences so that you don't need to do the same.</p>\n<p>For example, these are how many consecutive volumes I found in the same folder:</p>\n<pre><code>  []\n  []\n  [, ]\n  []\n  []\n  []\n  []\n  [, , , , ]\n  []\n  []\n  []\n  [, , , , ]\n  [, , , , , , , ]\n  [, , , , , , , , , , , , , , , ]\n</code></pre>",
      "rawMarkdown": "I was trying to load the entire folder as a volume and use conv3d on it. However, after some investigation, I realized that the slices in the same folder may not be consecutive.\nSometimes, the spacing and size are different. Sometimes, the directions are different. I tried to load different volumes in the same folder separately and then tried to resample and merge them into the same volume. However, I found the coordinate system of the physical seems to change as well.\nJust want to share my experiences so that you don't need to do the same.\n\n\nFor example, these are how many consecutive volumes I found in the same folder:\n```\n4003253 702807833 1 [14]\n4003253 1054713880 1 [14]\n4003253 2448190387 2 [23, 19]\n4646740 3201256954 1 [53]\n4646740 3486248476 1 [16]\n4646740 3666319702 1 [16]\n7143189 132939515 1 [16]\n7143189 1951927562 5 [3, 5, 5, 5, 4]\n7143189 3219733239 1 [16]\n8785691 481125819 1 [14]\n8785691 1570286759 1 [14]\n8785691 2406919186 5 [4, 4, 5, 4, 3]\n10728036 142859125 8 [1, 4, 6, 6, 1, 5, 6, 6]\n10728036 2073726394 16 [22, 9, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]\n```",
      "votes": null
    },
    {
      "id": "2980707",
      "postDate": "09/06/2024 05:21:09",
      "content": "<p>You are right that Axial T2 series have multiple groups inside them, but I am unsure how you grouped these slices. For example, for study_id=10728036 series_id=2073726394, There are only 2 groups, instance number 1 to 22 with IOP approximately <code>[0.998409, -0.0112538, 0.0552605, 0.0248317, 0.96751, -0.251609]</code> and 23 to 46 with IOP approximately <code>[0.995523, -0.00352097, 0.0944522, 0.00371198, 0.999991, -0.00184702]</code>.<br>\nHere is a 3D visualization:<br>\n<img src=\"https://www.googleapis.com/download/storage/v1/b/kaggle-forum-message-attachments/o/inbox%2F1303569%2Ff1c8452e678a46920a45cd6f3138d10b%2FScreenshot%202024-09-06%20104757.png?generation=1725599913544731&amp;alt=media\" alt=\"\"></p>\n<p>You can see the comments in these discussion for more: <a href=\"https://www.kaggle.com/competitions/rsna-2024-lumbar-spine-degenerative-classification/discussion/522956\" target=\"_blank\">2d to 3d coord conversion: Are the dicom tag wrong?</a></p>",
      "rawMarkdown": "You are right that Axial T2 series have multiple groups inside them, but I am unsure how you grouped these slices. For example, for study_id=10728036 series_id=2073726394, There are only 2 groups, instance number 1 to 22 with IOP approximately `[0.998409, -0.0112538, 0.0552605, 0.0248317, 0.96751, -0.251609]` and 23 to 46 with IOP approximately `[0.995523, -0.00352097, 0.0944522, 0.00371198, 0.999991, -0.00184702]`.\nHere is a 3D visualization:\n![](https://www.googleapis.com/download/storage/v1/b/kaggle-forum-message-attachments/o/inbox%2F1303569%2Ff1c8452e678a46920a45cd6f3138d10b%2FScreenshot%202024-09-06%20104757.png?generation=1725599913544731&alt=media)\n\nYou can see the comments in these discussion for more: [2d to 3d coord conversion: Are the dicom tag wrong?](https://www.kaggle.com/competitions/rsna-2024-lumbar-spine-degenerative-classification/discussion/522956)",
      "votes": null
    },
    {
      "id": "2981603",
      "postDate": "09/06/2024 23:57:56",
      "content": "<p>With the direction, spacing, and origin of the current slice, you can predict where the origin of the next slice should be. If they don't match it is a different group. Or if the spacing or size is different from the current slice, it is also a different group. <br>\nby direction and origin, I mean \"ImageOrientationPatient\" and \"ImagePositionPatient\". </p>",
      "rawMarkdown": "With the direction, spacing, and origin of the current slice, you can predict where the origin of the next slice should be. If they don't match it is a different group. Or if the spacing or size is different from the current slice, it is also a different group. \nby direction and origin, I mean \"ImageOrientationPatient\" and \"ImagePositionPatient\".",
      "votes": null
    },
    {
      "id": "2981873",
      "postDate": "09/07/2024 07:49:15",
      "content": "<p>Sorry, I should have specified above that IOP means \"ImageOrientationPatient\". My grouping is done as follows:</p>\n<ol>\n<li>Traverse in order of \"Instance Number\" in a series folder.</li>\n<li>If previous and current IOP have a difference greater than 1e-5, place current slice in a new group.</li>\n</ol>\n<p>You can use <code>itertools.groupby</code> to do this type of grouping by ordering slices with \"Instance Number\"</p>",
      "rawMarkdown": "Sorry, I should have specified above that IOP means \"ImageOrientationPatient\". My grouping is done as follows:\n1. Traverse in order of \"Instance Number\" in a series folder.\n1. If previous and current IOP have a difference greater than 1e-5, place current slice in a new group.\n\nYou can use `itertools.groupby` to do this type of grouping by ordering slices with \"Instance Number\"",
      "votes": null
    },
    {
      "id": "2982514",
      "postDate": "09/07/2024 22:21:25",
      "content": "<p>I see. I think for study_id=10728036 series_id=2073726394, they all have a small difference, so it probably falls into your 1e-5 tolerance.</p>",
      "rawMarkdown": "I see. I think for study_id=10728036 series_id=2073726394, they all have a small difference, so it probably falls into your 1e-5 tolerance.",
      "votes": null
    }
  ],
  "comments": [
    {
      "id": 2980707,
      "author_name": "coderrkj",
      "author_url": "",
      "post_date": "09/06/2024 05:21:09",
      "content": "<p>You are right that Axial T2 series have multiple groups inside them, but I am unsure how you grouped these slices. For example, for study_id=10728036 series_id=2073726394, There are only 2 groups, instance number 1 to 22 with IOP approximately <code>[0.998409, -0.0112538, 0.0552605, 0.0248317, 0.96751, -0.251609]</code> and 23 to 46 with IOP approximately <code>[0.995523, -0.00352097, 0.0944522, 0.00371198, 0.999991, -0.00184702]</code>.<br>\nHere is a 3D visualization:<br>\n<img src=\"https://www.googleapis.com/download/storage/v1/b/kaggle-forum-message-attachments/o/inbox%2F1303569%2Ff1c8452e678a46920a45cd6f3138d10b%2FScreenshot%202024-09-06%20104757.png?generation=1725599913544731&amp;alt=media\" alt=\"\"></p>\n<p>You can see the comments in these discussion for more: <a href=\"https://www.kaggle.com/competitions/rsna-2024-lumbar-spine-degenerative-classification/discussion/522956\" target=\"_blank\">2d to 3d coord conversion: Are the dicom tag wrong?</a></p>",
      "votes": null,
      "replies": [
        {
          "id": 2981603,
          "author_name": "sychen52",
          "author_url": "",
          "post_date": "09/06/2024 23:57:56",
          "content": "<p>With the direction, spacing, and origin of the current slice, you can predict where the origin of the next slice should be. If they don't match it is a different group. Or if the spacing or size is different from the current slice, it is also a different group. <br>\nby direction and origin, I mean \"ImageOrientationPatient\" and \"ImagePositionPatient\". </p>",
          "votes": null,
          "replies": [
            {
              "id": 2981873,
              "author_name": "coderrkj",
              "author_url": "",
              "post_date": "09/07/2024 07:49:15",
              "content": "<p>Sorry, I should have specified above that IOP means \"ImageOrientationPatient\". My grouping is done as follows:</p>\n<ol>\n<li>Traverse in order of \"Instance Number\" in a series folder.</li>\n<li>If previous and current IOP have a difference greater than 1e-5, place current slice in a new group.</li>\n</ol>\n<p>You can use <code>itertools.groupby</code> to do this type of grouping by ordering slices with \"Instance Number\"</p>",
              "votes": null,
              "replies": [
                {
                  "id": 2982514,
                  "author_name": "sychen52",
                  "author_url": "",
                  "post_date": "09/07/2024 22:21:25",
                  "content": "<p>I see. I think for study_id=10728036 series_id=2073726394, they all have a small difference, so it probably falls into your 1e-5 tolerance.</p>",
                  "votes": null,
                  "replies": []
                }
              ]
            }
          ]
        }
      ]
    }
  ],
  "raw_markdown_by_id": {
    "2980527": "I was trying to load the entire folder as a volume and use conv3d on it. However, after some investigation, I realized that the slices in the same folder may not be consecutive.\nSometimes, the spacing and size are different. Sometimes, the directions are different. I tried to load different volumes in the same folder separately and then tried to resample and merge them into the same volume. However, I found the coordinate system of the physical seems to change as well.\nJust want to share my experiences so that you don't need to do the same.\n\n\nFor example, these are how many consecutive volumes I found in the same folder:\n```\n4003253 702807833 1 [14]\n4003253 1054713880 1 [14]\n4003253 2448190387 2 [23, 19]\n4646740 3201256954 1 [53]\n4646740 3486248476 1 [16]\n4646740 3666319702 1 [16]\n7143189 132939515 1 [16]\n7143189 1951927562 5 [3, 5, 5, 5, 4]\n7143189 3219733239 1 [16]\n8785691 481125819 1 [14]\n8785691 1570286759 1 [14]\n8785691 2406919186 5 [4, 4, 5, 4, 3]\n10728036 142859125 8 [1, 4, 6, 6, 1, 5, 6, 6]\n10728036 2073726394 16 [22, 9, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]\n```",
    "2980707": "You are right that Axial T2 series have multiple groups inside them, but I am unsure how you grouped these slices. For example, for study_id=10728036 series_id=2073726394, There are only 2 groups, instance number 1 to 22 with IOP approximately `[0.998409, -0.0112538, 0.0552605, 0.0248317, 0.96751, -0.251609]` and 23 to 46 with IOP approximately `[0.995523, -0.00352097, 0.0944522, 0.00371198, 0.999991, -0.00184702]`.\nHere is a 3D visualization:\n![](https://www.googleapis.com/download/storage/v1/b/kaggle-forum-message-attachments/o/inbox%2F1303569%2Ff1c8452e678a46920a45cd6f3138d10b%2FScreenshot%202024-09-06%20104757.png?generation=1725599913544731&alt=media)\n\nYou can see the comments in these discussion for more: [2d to 3d coord conversion: Are the dicom tag wrong?](https://www.kaggle.com/competitions/rsna-2024-lumbar-spine-degenerative-classification/discussion/522956)",
    "2981603": "With the direction, spacing, and origin of the current slice, you can predict where the origin of the next slice should be. If they don't match it is a different group. Or if the spacing or size is different from the current slice, it is also a different group. \nby direction and origin, I mean \"ImageOrientationPatient\" and \"ImagePositionPatient\".",
    "2981873": "Sorry, I should have specified above that IOP means \"ImageOrientationPatient\". My grouping is done as follows:\n1. Traverse in order of \"Instance Number\" in a series folder.\n1. If previous and current IOP have a difference greater than 1e-5, place current slice in a new group.\n\nYou can use `itertools.groupby` to do this type of grouping by ordering slices with \"Instance Number\"",
    "2982514": "I see. I think for study_id=10728036 series_id=2073726394, they all have a small difference, so it probably falls into your 1e-5 tolerance."
  },
  "source": "meta"
}