Issue with using SCT in python terminal or IDE (PyCharm)

Hi all!

I would like to ask for some help about SCT!
I’m pretty new here and trying to discover as many SCT features as I can.
Can I use all part os the toolbox via Python IDE or terminal? I’m using Win10 and I can run all the commands via Windows Command Promt, but I’m curious of that if I can use it from an IDE. SCT is written in python, as I best know, that’s why I thought of that.
I have read some stuff about it and I couldn’t find it out that is it possible or not.

Thank you for reading my question! :slight_smile:

Hi @Tamas_Dudas,

We typically recommend sticking with the command line scripts. This is mostly to make things easier for SCT’s users, as many of our users have never worked with Python (or PyCharm) directly.

However, for advanced users (like yourself), it is indeed possible! SCT maintains an internal developer wiki, and in that wiki, there are instructions on how to add SCT’s virtual environment as a PyCharm interpreter.

In fact, as an SCT developer myself, PyCharm is actually what I personally use when working on SCT:

Some notes/disclaimers:

  • SCT is not a typical Python package. Although it is written in Python, it is not currently pip-installable (it is not on PyPI). So, if you build something on top of the Python API, you won’t be able to specify “spinalcordtoolbox” as a dependency in e.g., pyproject.toml, requirements.txt, etc.
  • Because SCT’s Python API isn’t designed to be user-facing, the modules and functions you find might not be up to the same standards that you may expect from other Python packages. (SCT was first developed in 2014 with CLI scripts in mind, and only in recent years have we begun refactoring the codebase to prioritize the Python API. See also: Point 7. in this GitHub comment.)
  • SCT is currently gearing up to release v6.0, which will update the Windows installer to use Miniconda (instead of the system Python). Because of this, the instructions for adding SCT as a PyCharm interpreter will change slightly in the future.

Please let me know if you have any other questions! I’d be happy to help. :slight_smile:

Kind regards,


Thank you for your informative reply @joshuacwnewton ! :slight_smile:

I had a few questions reflecting to your message:

  • I’m sorry, if you mentioned it before, but I do not get it completely. Do I have the opportunity to use all the algorith like: sct_propseg, sct_deepseg_sc, … in a python environment, not just from CMD, and get the same outputs like: t2_seg.nii.gz, t2_seg_labeled.nii.gz
  • As I see, this SCT is mainly used for the segmentation of the cervical spinal cord, but I would like to know that, can I use it for the segmentation of lumbar section spinal cord from MRI DICOM data?
  • The license of SCT is the GNU General Public License v3 (GPLv3), I’m not an expert of these type of Legal Matters. :smiley: Can I use SCT for a research and development project?
  • As far as I know, SCT also uses artificial intelligence. I would like to ask that what kind of teaching data did you used during the training? :slight_smile:

Thank you for helping me out!

Best wishes,

Yes, you can! The main way to do this would be:

from spinalcordtoolbox.scripts import sct_deepseg_sc

sct_deepseg_sc.main(["cli", "arguments", "go", "here"])

Although, note that calling the scripts in this way will still output the .nii.gz files to the working directory, rather than returning them as Python objects.

Reading through the source paper for sct_deepseg_sc, its model was trained with a diverse set of images, with coverage spanning cervical, thoracic, and lumbar regions. So, I would presume that it is capable of segmenting the lumbar section of the spinal cord.

But, the most straightforward thing to do would be to select a sample image or two and try both of our segmentation tools (sct_deepseg_sc and sct_propseg) directly.

(I don’t have sample data myself on hand with visible lumbar sections, or else I would have tested this out myself.)

It depends!

  • For research projects focused on analyzing image data, you are absolutely encouraged to use SCT. In fact, we maintain a list of research studies that have used SCT in their analysis. (For data analysis studies, there are little to no restrictions involved, beyond a request for you to cite SCT in your work.)
  • For research projects focused on developing new methods or tools, where the SCT source code would be copied/modified/distributed, you must follow the conditions listed on the GPLv3 License Page (you can hover over each permission/condition for more details).

The answer to this question varies greatly depending on which tools you are using.

  • Generally speaking, many of the AI tools developed in the NeuroPoly lab rely on the Spine Generic data-multi-subject dataset.
  • However, for more specific details, I would recommend reading the research publications associated with each tool, found here.

We are also working to make this information more accessible – see this GitHub issue. So, if you are unable to find sufficient information in a given publication, please let us know. :slight_smile:

Kind regards,

As Joshua said, sct_deepseg_sc and sct_propseg usually work well on lumbar data, but in case it does not, you also have sct_deepseg, which has a lumbar model (called “seg_lumbar_sc_t2w”). For more info, type sct_deepseg -list-tasks.

As far as I know, SCT also uses artificial intelligence. I would like to ask that what kind of teaching data did you used during the training?

AI models mostly use private datasets. We start using the spine generic now, but not for models that are currently accessible in SCT.