From a4688ef4d139ad6cc58a192cbe3f3608915750e8 Mon Sep 17 00:00:00 2001 From: Sebastian Rios Date: Thu, 4 Jul 2024 02:16:02 -0400 Subject: [PATCH] Removing dependency of SCT 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. --- interactive.ipynb | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/interactive.ipynb b/interactive.ipynb index 0d62562..635b342 100644 --- a/interactive.ipynb +++ b/interactive.ipynb @@ -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.
\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.
\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.
\n", - "If you want, you can also manually add a label (through a process of your liking) and also follow through the steps below.
\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.
\n", + "\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.
\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.
\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.
\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.
" + ] + }, + { + "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.
\n", + "We then create a whole where we want the mask to be by multiplying it with our main labeled file." ] }, { @@ -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" @@ -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.
\n", + "*Note that we use temp as it is better to create a copy and edit the copy instead of the original.*" ] }, { @@ -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.
\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." ] }, { @@ -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.
\n", "- Also recommended, check the mask before multplication as I have deleted some files by multiplying inappropriate inversed masks.
\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."