Automatic centerline

Hi All,

is there a way to generate the centerline automatically?
In my case I have a geometry with always one input and 4 outputs.

Hi - you can use the VMTK extension for that.

This short video should get you started:

If everything works well from the GUI but you need automated processing then you can switch to Python to use the underlying VMTK package directly.

To follow on from Daniele’s question, is there a VMTK package with Python which allows you to calculate the centreline completely automatically, without setting seed points? So far I’ve been unable to find an approach to do this.

Thanks,

Jeff.

Yes, centerline extraction works completely automatically. It requires two clicks (click “Auto-detect” then click “Apply”), so that you have a chance to add/remove endpoints, but if you don’t want this then just click the two buttons and you are done.

1 Like

While not replying directly to your question, I wish to know why is it felt so cumbersome to place a few endpoints on a model to extract the exact centerline of a targeted portion of a segment ? This allows you to be in control of what you’re doing.

Thanks Andras. So far I’ve been using vmtkcenterlines via PypePad so am excited to try this. Thanks

Hey, great question and I do agree that that would be ideal.
I’m making a fully automated clinician-oriented tool where the clinician can input raw CT images and we output useful metrics for the medical conditions we’re interested in. I’ve got the segmentation fully automated and would be ideal to automate this portion of the work too. I have my vmtk pipeline working great with just this one stage of intervention so we’ll see how well the fully-automated version can compare :slight_smile:

1 Like

Hi Andras, I’m pleased to now have my workflow now working as a .py script. At the centreline extraction stage I’m using “vmtkcenterlines” but I don’t see any kind of “Auto-detect” prompt or button appearing? Can you please confirm if I’m using the wrong command or otherwise missing something? Thanks

It is in Extract Centerline module:

image

Thanks so much for such a quick reply! I think perhaps I misunderstood the capabilities: I was hoping to run a script from the command line, completely avoiding the need to use 3DSlicer or other programs. Is this not possible?

I have my script working (without needing to enter 3DSlicer) but there a few points which require manual intervention which I’m currently trying to remove. Is it possible using pypes to use this kind of auto-detect functionality or must that be done in 3DSlicer? Thanks

You can have a look at the source code of this module, it is a pure Python script. You can either cop-paste just the parts that you need into your current script or use the code as is.

If you want to use the entire module as is, then you need to use Slicer’s virtual Python environment, but you need to use some Python environment anyway, so why not use Slicer’s? You can pip install any Python packages into it the same way as into any other. The Python environment is available without showing any GUI, so you can run your Python script with Slicer --no-main-window --python-script path/to/myscript.py as you would do it with python path/to/myscript.py in another Python environment.

There are Slicer docker images that you can use (you may need to add a step to install SlicerVMTK, but probably that’s all), so it all becomes a single command on the command-line. You can also run Slicer as a web service, so that you can use any of its features remotely, from a web or mobile application via a REST API. If you are developing a desktop application then probably you could save enormous amount of software development, maintenance, and support time by building your application based on Slicer (replacing the top-level GUI with your custom UI layer - this is how most companies develop their Slicer-based medical imaging products).

Also note that automated processing workflows can never guarantee 100% success rate. In medical applications, the typical target for automated processing success rate is 95% because there are always variability between patients, in imaging, etc. In some cases, maybe you can achieve 99%. But you cannot afford to errors slip through for a few percent of your patients. Therefore, you always need a GUI (for approval/quality assurance) and a way to manually correct those 5% of cases where automation does not provide perfect results.

1 Like

Thanks again Andras, this is extremely useful and valuable advice.
My background is not in coding so it’ll take me a little time to digest all of this information and put it into practice. I have a very simple script in pypepad which works great for my vmtk operations, I’m hoping I can get this working without too much trouble, either way I appreciate you being on hand to help!

Thanks also for the warning about automated workflows, I’m definitely taking that advice on board and we already plan to include a gui with the option for manual intervention if necessary.

If you have not invested a lot of time into developing your application yet then it is a perfect time to make a decision about switching to a proper medical imaging application platform, which can drive your entire clinical workflow: getting the input images (via DICOM files or networking), specifying inputs, running processing, showing results, allowing users to make manual adjustments, generating structured reports and saving/sending it via DICOM or other formats. Slicer provides 99% of all these features, so you can focus on developing your custom processing workflow, underlying custom algorithms (if needed), and design a convenient custom GUI.

If you write a bit more about what your overall goal is then we can make recommendations about how to achieve it. We are of course all like Slicer so we will be somewhat biased towards recommending it in general, but we also friends with developers of other web and desktop medical imaging platforms (OHIF, MITK, Mevis, etc.) so if you tell us specific requirements then we may be able to guide you in the right direction.

Thank you Andras!
I have already developed the segmentation algorithm workflow so now it is just the centreline and geometry analysis I definitely need to tackle. The project I am working on is just a pilot study so it doesn’t need to be perfect or flashy but of course it would be good to build a solid foundation using the best tools available. I appreciate your comment about using slicer or similar as the platform, I’d certainly like to explore the capabilities if it could be quick to try. Quite easily I could likely wrap up what I’ve got and incorporate it in, though again I am not a programming-whizz!

The workflow is as follows:

  • Import images
  • Use segmentation script I’ve already fine-tuned and want to continue using. Exports segmented .nii.gz
  • Then the bit I’ve been working on recently: using vmtk to extract a .dat of the vessel diameter fully automatically. More details on that further down.
  • Finally to create a report with visuals and stating the maximum diameter of the segmented anatomy. Again I’ve already got a basic version of this but would be great to use some of what slicer may have available.

So I’d be interested potentially in using the slicer platform but equally for now simply want to get the bit I’ve been doing in vmtk working automatically so that I have at least a basic version of whole automated pipeline. There are just two manual intervention steps I’d like to solve in the first instance, one of them (thresholding) should be I can select the same settings each time, whereas the centreline seed points was the more difficult step and the reason for my initial post.

My vmtk script is quite simple and could be further streamlined but here are the steps I’m carrying out:
#Threshold & create surface mesh:
vmtklevelsetsegmentation -ifile “data_file” --pipe vmtkmarchingcubes -i @.o -ofile Sx_1thresh.vtp

#Computer centrelines combined with viewer:
vmtksurfacereader -ifile Sx_1thresh.vtp --pipe vmtkcenterlines --pipe vmtkrenderer --pipe vmtksurfaceviewer -opacity 0.25 --pipe vmtksurfaceviewer -i @vmtkcenterlines.o -array MaximumInscribedSphereRadius -ofile Sx_2centrelines.vtp

#Compute centre-line geometry
vmtkcenterlinegeometry -ifile Sx_2centrelines.vtp -smoothing 1 -ofile Sx_3clgeo.vtp
vmtkcenterlinegeometry -ifile Sx_2centrelines.vtp -smoothing 1 -ofile Sx_3clgeodat.dat

This week I want to try your suggestions from earlier in the thread but again must state that I’m trying to at least give the option for a fully-automated script with no user intervention necessary.

Thanks in advance, I very much appreciate your help!!

You can find the automatic endpoint detection implementation in onAutoDetectEndPoints method. It has some code to get/put VTK data objects from/to MRML nodes, but you can ignore those and just work with the VTK data objects.

1 Like

Hi Andras,
I’m starting to pick up this piece of work again and have been running some tests within Slicer’s python environment. I can load volumes and models, carry out thresholds etc all with the centralised Slicer functions but I am now stuck at how to access/use the vmtk functions as mentioned in this thread within the slicer environment.

For example I can load my model with:
slicer.util.loadModel(file)

But I can’t for the life of me figure out the equivilant command to use, for example, the extract centreline and autodetect end points functions as discussed earlier in this thread? It is certainly my lack of coding experience letting me down. Any help you can provide would be very much appreciated. Thanks in advance

You can use the automatic test of the Extract Centerline module as an example of how to use the module from a Python script:

Thanks as always for such a prompt response, Andras.
I am still a little lost though, my background is not in coding!

When I enter

logic = ExtractCenterlineLogic()

I get:

NameError: name 'ExtractCenterlineLogic' is not defined 

I have used the module finder and see it states:
Internal name: ExtractCenterline
Type: Python Scripted Loadable

But I still for the life of me can’t figure out how I can access this within the slicer python environment. I have tried many combinations of " slicer." such as “slicer.ScriptedLoadableModule.” to then track it down but still have no luck. Could you please possibly provide an idiot-proof guidance?
Thank you.

In the test that I linked above, ExtractCenterlineLogic was in the same file, so there was no need to import it. However, if you want to use this class from another Python file then you need to import it, for example by adding this line:

from ExtractCenterline import ExtractCenterlineLogic