{
  "id": 510385,
  "title": "One instance number but many coordinates to the same instance",
  "url": "/competitions/rsna-2024-lumbar-spine-degenerative-classification/discussion/510385",
  "author_name": "",
  "post_date": "2024-06-06T04:36:52.279917200Z",
  "votes": 2,
  "comment_count": 3,
  "views": 0,
  "content": "<p>I have found a scenario that I don't know how to manage. For instance, in the train_label_coordinates.csv file, we can find the image below where we have study_id=4003253, series_id=702807833, and instance_number=8.<br>\n<img src=\"https://www.googleapis.com/download/storage/v1/b/kaggle-forum-message-attachments/o/inbox%2F410401%2F31cb3a53b64d2a1f7c62ec751b7ccbba%2F4003253.png?generation=1717647865904468&amp;alt=media\"><br>\n Note that we have 5 references to the same instance_number 8 but in the series_id directory we have only one 8.dcm file.<br>\nHow to manage this scenario?</p>",
  "messages": [
    {
      "id": "2857667",
      "postDate": "06/06/2024 04:36:52",
      "content": "<p>I have found a scenario that I don't know how to manage. For instance, in the train_label_coordinates.csv file, we can find the image below where we have study_id=4003253, series_id=702807833, and instance_number=8.<br>\n<img src=\"https://www.googleapis.com/download/storage/v1/b/kaggle-forum-message-attachments/o/inbox%2F410401%2F31cb3a53b64d2a1f7c62ec751b7ccbba%2F4003253.png?generation=1717647865904468&amp;alt=media\"><br>\n Note that we have 5 references to the same instance_number 8 but in the series_id directory we have only one 8.dcm file.<br>\nHow to manage this scenario?</p>",
      "rawMarkdown": "I have found a scenario that I don't know how to manage. For instance, in the train_label_coordinates.csv file, we can find the image below where we have study_id=4003253, series_id=702807833, and instance_number=8.\n![](https://www.googleapis.com/download/storage/v1/b/kaggle-forum-message-attachments/o/inbox%2F410401%2F31cb3a53b64d2a1f7c62ec751b7ccbba%2F4003253.png?generation=1717647865904468&alt=media)\n Note that we have 5 references to the same instance_number 8 but in the series_id directory we have only one 8.dcm file.\nHow to manage this scenario?",
      "votes": null
    },
    {
      "id": "2858080",
      "postDate": "06/06/2024 08:58:59",
      "content": "<p>It will help to see this slice as an image:<br>\n<img src=\"https://www.googleapis.com/download/storage/v1/b/kaggle-forum-message-attachments/o/inbox%2F1303569%2Fb4700ad12d0c32ba4420d89e1a29560b%2FScreenshot%202024-06-06%20140250.png?generation=1717662843707597&amp;alt=media\" alt=\"study_id=4003253, series_id=702807833, and instance_number=8\"></p>\n<p>You can see there are multiple spinal canals visible in the image. In the rows for instance number 8, all the conditions are \"Canal Stenosis\", but the levels are different.</p>\n<p>To visualize the points:</p>\n<pre><code> pathlib  Path\n\n matplotlib.pyplot  plt\n pandas  pd\n pydicom\n\n\nINPUT_DIR = Path()\ntrain_images_path = INPUT_DIR / \ndf_train_label = pd.read_csv(INPUT_DIR / )\nstudy_id, series_id, instance_number = , , \n\ndcm_path = train_images_path / (study_id) / (series_id) / \n dcm_path.exists()\ndcm = pydicom.dcmread(dcm_path)\n (dcm.InstanceNumber) == instance_number \n\nfig, ax = plt.subplots()\nax.imshow(dcm.pixel_array, )\n\nconditions = (\n    (df_train_label.study_id == study_id)\n    &amp; (df_train_label.series_id == series_id)\n    &amp; (df_train_label.instance_number == instance_number)\n)\nsub_lbls = df_train_label[conditions]\nsub_lbls.plot(, , , ax=ax, color=)\nplt.show()\n</code></pre>\n<p><img src=\"https://www.googleapis.com/download/storage/v1/b/kaggle-forum-message-attachments/o/inbox%2F1303569%2Ff49ade49ca8e8c8ada00576f128cf19c%2Fspline_plot.png?generation=1717664305770088&amp;alt=media\" alt=\"plotted_figure\"></p>",
      "rawMarkdown": "It will help to see this slice as an image:\n![study_id=4003253, series_id=702807833, and instance_number=8](https://www.googleapis.com/download/storage/v1/b/kaggle-forum-message-attachments/o/inbox%2F1303569%2Fb4700ad12d0c32ba4420d89e1a29560b%2FScreenshot%202024-06-06%20140250.png?generation=1717662843707597&alt=media)\n\nYou can see there are multiple spinal canals visible in the image. In the rows for instance number 8, all the conditions are \"Canal Stenosis\", but the levels are different.\n\nTo visualize the points:\n```python\nfrom pathlib import Path\n\nimport matplotlib.pyplot as plt\nimport pandas as pd\nimport pydicom\n\n\nINPUT_DIR = Path(\"../input/rsna-2024-lumbar-spine-degenerative-classification\")\ntrain_images_path = INPUT_DIR / \"train_images\"\ndf_train_label = pd.read_csv(INPUT_DIR / 'train_label_coordinates.csv')\nstudy_id, series_id, instance_number = 4003253, 702807833, 8\n\ndcm_path = train_images_path / str(study_id) / str(series_id) / f\"{instance_number}.dcm\"\nassert dcm_path.exists()\ndcm = pydicom.dcmread(dcm_path)\nassert int(dcm.InstanceNumber) == instance_number # Double check\n\nfig, ax = plt.subplots()\nax.imshow(dcm.pixel_array, \"gray\")\n\nconditions = (\n    (df_train_label.study_id == study_id)\n    & (df_train_label.series_id == series_id)\n    & (df_train_label.instance_number == instance_number)\n)\nsub_lbls = df_train_label[conditions]\nsub_lbls.plot(\"x\", \"y\", \"scatter\", ax=ax, color=\"red\")\nplt.show()\n```\n![plotted_figure](https://www.googleapis.com/download/storage/v1/b/kaggle-forum-message-attachments/o/inbox%2F1303569%2Ff49ade49ca8e8c8ada00576f128cf19c%2Fspline_plot.png?generation=1717664305770088&alt=media)",
      "votes": null
    },
    {
      "id": "2858870",
      "postDate": "06/06/2024 17:29:34",
      "content": "<p>Each condition is caused at different position so there may be instances having condition at 1 level or it may have upto 5 maximum.</p>",
      "rawMarkdown": "Each condition is caused at different position so there may be instances having condition at 1 level or it may have upto 5 maximum.",
      "votes": null
    },
    {
      "id": "2859392",
      "postDate": "06/07/2024 02:41:29",
      "content": "<p>Hi <a href=\"https://www.kaggle.com/coderrkj\" target=\"_blank\">@coderrkj</a> <br>\nThanks for your quick answer. I double checked my code and verified that sometimes, it was plotting the coordinates in a wrong way, which was leading me to a wrong interpretation. Now I can see that, even in axis orientation, the points are correct.</p>",
      "rawMarkdown": "Hi @coderrkj \nThanks for your quick answer. I double checked my code and verified that sometimes, it was plotting the coordinates in a wrong way, which was leading me to a wrong interpretation. Now I can see that, even in axis orientation, the points are correct.",
      "votes": null
    }
  ],
  "comments": [
    {
      "id": 2858080,
      "author_name": "coderrkj",
      "author_url": "",
      "post_date": "06/06/2024 08:58:59",
      "content": "<p>It will help to see this slice as an image:<br>\n<img src=\"https://www.googleapis.com/download/storage/v1/b/kaggle-forum-message-attachments/o/inbox%2F1303569%2Fb4700ad12d0c32ba4420d89e1a29560b%2FScreenshot%202024-06-06%20140250.png?generation=1717662843707597&amp;alt=media\" alt=\"study_id=4003253, series_id=702807833, and instance_number=8\"></p>\n<p>You can see there are multiple spinal canals visible in the image. In the rows for instance number 8, all the conditions are \"Canal Stenosis\", but the levels are different.</p>\n<p>To visualize the points:</p>\n<pre><code> pathlib  Path\n\n matplotlib.pyplot  plt\n pandas  pd\n pydicom\n\n\nINPUT_DIR = Path()\ntrain_images_path = INPUT_DIR / \ndf_train_label = pd.read_csv(INPUT_DIR / )\nstudy_id, series_id, instance_number = , , \n\ndcm_path = train_images_path / (study_id) / (series_id) / \n dcm_path.exists()\ndcm = pydicom.dcmread(dcm_path)\n (dcm.InstanceNumber) == instance_number \n\nfig, ax = plt.subplots()\nax.imshow(dcm.pixel_array, )\n\nconditions = (\n    (df_train_label.study_id == study_id)\n    &amp; (df_train_label.series_id == series_id)\n    &amp; (df_train_label.instance_number == instance_number)\n)\nsub_lbls = df_train_label[conditions]\nsub_lbls.plot(, , , ax=ax, color=)\nplt.show()\n</code></pre>\n<p><img src=\"https://www.googleapis.com/download/storage/v1/b/kaggle-forum-message-attachments/o/inbox%2F1303569%2Ff49ade49ca8e8c8ada00576f128cf19c%2Fspline_plot.png?generation=1717664305770088&amp;alt=media\" alt=\"plotted_figure\"></p>",
      "votes": null,
      "replies": [
        {
          "id": 2859392,
          "author_name": "crldata",
          "author_url": "",
          "post_date": "06/07/2024 02:41:29",
          "content": "<p>Hi <a href=\"https://www.kaggle.com/coderrkj\" target=\"_blank\">@coderrkj</a> <br>\nThanks for your quick answer. I double checked my code and verified that sometimes, it was plotting the coordinates in a wrong way, which was leading me to a wrong interpretation. Now I can see that, even in axis orientation, the points are correct.</p>",
          "votes": null,
          "replies": []
        }
      ]
    },
    {
      "id": 2858870,
      "author_name": "manaidu",
      "author_url": "",
      "post_date": "06/06/2024 17:29:34",
      "content": "<p>Each condition is caused at different position so there may be instances having condition at 1 level or it may have upto 5 maximum.</p>",
      "votes": null,
      "replies": []
    }
  ],
  "raw_markdown_by_id": {
    "2857667": "I have found a scenario that I don't know how to manage. For instance, in the train_label_coordinates.csv file, we can find the image below where we have study_id=4003253, series_id=702807833, and instance_number=8.\n![](https://www.googleapis.com/download/storage/v1/b/kaggle-forum-message-attachments/o/inbox%2F410401%2F31cb3a53b64d2a1f7c62ec751b7ccbba%2F4003253.png?generation=1717647865904468&alt=media)\n Note that we have 5 references to the same instance_number 8 but in the series_id directory we have only one 8.dcm file.\nHow to manage this scenario?",
    "2858080": "It will help to see this slice as an image:\n![study_id=4003253, series_id=702807833, and instance_number=8](https://www.googleapis.com/download/storage/v1/b/kaggle-forum-message-attachments/o/inbox%2F1303569%2Fb4700ad12d0c32ba4420d89e1a29560b%2FScreenshot%202024-06-06%20140250.png?generation=1717662843707597&alt=media)\n\nYou can see there are multiple spinal canals visible in the image. In the rows for instance number 8, all the conditions are \"Canal Stenosis\", but the levels are different.\n\nTo visualize the points:\n```python\nfrom pathlib import Path\n\nimport matplotlib.pyplot as plt\nimport pandas as pd\nimport pydicom\n\n\nINPUT_DIR = Path(\"../input/rsna-2024-lumbar-spine-degenerative-classification\")\ntrain_images_path = INPUT_DIR / \"train_images\"\ndf_train_label = pd.read_csv(INPUT_DIR / 'train_label_coordinates.csv')\nstudy_id, series_id, instance_number = 4003253, 702807833, 8\n\ndcm_path = train_images_path / str(study_id) / str(series_id) / f\"{instance_number}.dcm\"\nassert dcm_path.exists()\ndcm = pydicom.dcmread(dcm_path)\nassert int(dcm.InstanceNumber) == instance_number # Double check\n\nfig, ax = plt.subplots()\nax.imshow(dcm.pixel_array, \"gray\")\n\nconditions = (\n    (df_train_label.study_id == study_id)\n    & (df_train_label.series_id == series_id)\n    & (df_train_label.instance_number == instance_number)\n)\nsub_lbls = df_train_label[conditions]\nsub_lbls.plot(\"x\", \"y\", \"scatter\", ax=ax, color=\"red\")\nplt.show()\n```\n![plotted_figure](https://www.googleapis.com/download/storage/v1/b/kaggle-forum-message-attachments/o/inbox%2F1303569%2Ff49ade49ca8e8c8ada00576f128cf19c%2Fspline_plot.png?generation=1717664305770088&alt=media)",
    "2858870": "Each condition is caused at different position so there may be instances having condition at 1 level or it may have upto 5 maximum.",
    "2859392": "Hi @coderrkj \nThanks for your quick answer. I double checked my code and verified that sometimes, it was plotting the coordinates in a wrong way, which was leading me to a wrong interpretation. Now I can see that, even in axis orientation, the points are correct."
  },
  "source": "meta"
}