Skip to content

Commit

Permalink
Removing dependency of SCT
Browse files Browse the repository at this point in the history
Now the label creation is clearer and now guides through the strategy
of adding a new label so that anyone can follow the though process and
do the same with any tool.
I also clarified that I used SCT due practicity for the example case chose.
  • Loading branch information
sriosq committed Jul 4, 2024
1 parent 6c2cfb8 commit a4688ef
Showing 1 changed file with 23 additions and 8 deletions.
31 changes: 23 additions & 8 deletions interactive.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -203,11 +203,25 @@
"id": "2b047e6d-c72c-43f3-9bc8-a055e00135f2",
"metadata": {},
"source": [
"This section will guide you through how to create new labels, you will need SCT toolbox: https://spinalcordtoolbox.com/index.html by De Leener B, Levy S, Dupont SM, Fonov VS, Stikov N, Louis Collins D, Callot V, Cohen-Adad J. SCT: Spinal Cord Toolbox, an open-source software for processing spinal cord MRI data. Neuroimage 2017. </br>\n",
"In this example we will address a current limitation from Total Seg CT, that is that we cannot differentiate CSF, WM or GM from the Spinal Cord. </br>\n",
"In order to add them we need to first register the CT image to the PAM50 space. For this we can use the Spinal Cord segmentation and you can manually create landmarks of spine C2 and C5. With this files ready you can automatically register to PAM50 space and procede with creating new labels. </br> \n",
"If you want, you can also manually add a label (through a process of your liking) and also follow through the steps below. </br>\n",
"Given that the labeling from anatomical image will have a specific value, when we add a new label we must add it with a value that is not included in the look up table. For example, for CT whole body Total Seg we must use a number higher than 117 to avoid conflicts."
"This section will guide you through how to create new labels.\n",
"If you want, you can manually add a label in any desired location. For what you will only need a mask. </br>\n",

This comment has been minimized.

Copy link
@jcohenadad

jcohenadad Jul 4, 2024

Member

This is waaaaay too complicated. Tutorial should be:

  • download this example dataset that includes MRI and label
  • run the CLI

that’s it.

your tool should not cover the part of how to make a label, but you could redirect to existing tools and strategies.

This comment has been minimized.

Copy link
@sriosq

sriosq Jul 4, 2024

Author Contributor

Okay, I understand. Right now it works with CT and labels. The CT dataset is open source I will direct there and state that to use the converter function, the code will require labeled nifti as input. Thanks!

This comment has been minimized.

Copy link
@jcohenadad

jcohenadad Jul 4, 2024

Member

i suggest to include one dummy dataset that could be used for (i) tutorial and (ii) unit testing of your code (good coding practice to include unit tests ran via Github Actions: #5)

This comment has been minimized.

Copy link
@sriosq

sriosq Jul 4, 2024

Author Contributor

@jcohenadad This is the way to go. I'll work on this and soon make the changes. Thanks for the help 💯

This comment has been minimized.

Copy link
@sriosq

sriosq Jul 7, 2024

Author Contributor

Updated here: 10ea7ab Thanks for the help 💯

"\n",
"This examples addresses a, as of June 2024, current limitation from Total Seg CT, that is that we cannot differentiate CSF, WM or GM from the Spinal Cord. </br>\n",
"\n",
"Given that the labeling from anatomical image will have a specific value, when we add a new label we must add it with a value that is not included in the look up table. For example, for CT whole-body Total-Seg we must use a number higher than 117 to avoid conflicts. </br>\n",
"\n",
"\n",
"Given the nature of my example I used Spinal Cord Toolbox (SCT): https://spinalcordtoolbox.com/index.html by De Leener B, Levy S, Dupont SM, Fonov VS, Stikov N, Louis Collins D, Callot V, Cohen-Adad J. SCT: Spinal Cord Toolbox, an open-source software for processing spinal cord MRI data. Neuroimage 2017. </br> \n",
"In order to add them we need to first register the CT image to the PAM50 space. For this we can use the Spinal Cord segmentation and you can manually create landmarks of spine C2 and C5. With this files ready you can automatically register to PAM50 space and procede with creating new labels. </br> "
]
},
{
"cell_type": "markdown",
"id": "fa06aec3",
"metadata": {},
"source": [
"**I.** The trick to add a new label to semgnetation is to first invert the values of the mask so that the ROI has value of 0 and everywhere else 1. </br> \n",
"We then create a whole where we want the mask to be by multiplying it with our main labeled file."
]
},
{
Expand All @@ -223,7 +237,6 @@
},
"outputs": [],
"source": [
"# The trick to add a new semgnetation is to use the mask and invert its values\n",
"sct_maths -i new_label.nii.gz -o inv.nii.gz -sub 1\n",
"sct_maths -i inv.nii.gz -o inv.nii.gz -mul -1\n",
"sct_maths -i temp.nii.gz -o no_label.nii.gz -mul inv.nii.gz"
Expand All @@ -234,7 +247,8 @@
"id": "bdd83860-0029-408c-bdde-e06d0710ecc9",
"metadata": {},
"source": [
"The label we want to add is new_label and we invert it. Then, as we dont want an overlap of labels we multiply the the inversed segmentation and multiply with the volume we want to add the label. Note that we use temp as it is better to create a copy and edit the copy instead of the original."
"**II.** We need to make sure that the new label will have a non-conflictng value depending on the range of the look-up table. </br>\n",
"*Note that we use temp as it is better to create a copy and edit the copy instead of the original.*"
]
},
{
Expand All @@ -258,7 +272,7 @@
"metadata": {},
"source": [
"We choose to multiply twice because there is a maximum value of 40 to multiply in SCT_maths. We can then create a new nifti file with value of 256 for the mask and 0 elsewhere. </br>\n",
"Then we just need to add the new label file to the no_label file"
"**III.** Then we just need to add the new label file to the file with a whole from the label we want to input."
]
},
{
Expand All @@ -277,6 +291,7 @@
"metadata": {},
"source": [
"## Important notes\n",
"- This procedure is not exclusive to SCT and can be perform with any tool of your preference!\n",
"- Once a new label is created, if you want to add more labels you will have to work on top of any previously made new volume with added labels, so creating a temporal copy to test first is recommended. </br>\n",
"- Also recommended, check the mask before multplication as I have deleted some files by multiplying inappropriate inversed masks. </br>\n",
"- In the \"example\" folder you will find an example of a succesfull implementation of 2 new masks to the CT_wb data that adds labels 289 and 256 to the whole body dataset."
Expand Down

0 comments on commit a4688ef

Please sign in to comment.