How to run PypeS programmatically in Windows (for centerlines extraction)

319 views
Skip to first unread message

David

unread,
Sep 7, 2013, 12:52:32 PM9/7/13
to vmtk-...@googlegroups.com
Hi Luca, 

Thank you, this solved my problem. 

I'm now facing the automation of it; I'd like to run a script based on known source and target points (coordinates), so the system would 
generate the data file defining centerlines automatically.

While trying the following (highlighted in blue), I'm getting the message  IOError: (13, 'Permission denied') related to the first line starting with imp.load_source

import imp
import sys
import os 
import string

imp.load_source('pypes', 'C:/Program Files/vmtk/Install/lib/vmtk/vmtk')
imp.load_source('vmtkscripts', 'C:/Program Files/vmtk/Install/lib/vmtk/vmtk')

viewCAAA7 = 'vmtksurfacereader -ifile C:/Temp/Arterial-Lumen.stl --pipe vmtkcenterlines -seedselector pointlist -sourcepoints -9.983509 -139.666973 1085.0 -targetpoints 77.759418 -207.856856 725.0 -67.952994 -213.997088 725.0 -endpoints 1 --pipe vmtkcenterlineresampling -length 0.1 --pipe vmtkcenterlinesmoothing --pipe vmtkbranchextractor --pipe vmtkbranchclipper --pipe vmtkrenderer --pipe vmtksurfaceviewer -opacity 0.25 --pipe vmtkcenterlineviewer -cellarray GroupIds --pipe vmtksurfacewriter -i @vmtkbranchextractor.o -ofile Artery_centerlines.dat'

pype = pypes.PypeRun(viewCAAA7)


So, first of all, I'm having a problem with the importation of vmtk modules, even after giving administrator rights to the 
installation folder of vmtk (C:/Program Files/vmtk).

Any help would be appreciated. 


Thanks in advance
David



---------------------------------------------

Hi David,
 have you tried removing the quotes? If this doesn't solve it, please send more information.
Best,

Luca


On Sep 6, 2013, at 10:02 PM, David Roy wrote:

Hi,  

I need to run VMTK in Windows 7 64 bit, knowing my code (for vessel centerlines extraction) works well in linux.  

I installed CMake 2.6 and VMTK 1.0.0 (both for 32 bit, as I could not install their 64 bit version), but when I enter my code
(between simple quotes) in the top panel and run it, nothing happens. 

Please, could you provide me with any clue of what's going wrong ?


Thanks
David
(PhD stu., Montréal)

Greg Hanowski

unread,
Sep 7, 2013, 6:03:10 PM9/7/13
to vmtk-...@googlegroups.com

David,

Would you mind sharing how you got your centerline script to work on Windows 7?

In W8 running PypePad I've tried vmtkcenterlines -seedselector openprofiles -ifile trachea.vtp -ofile c:\VMTK_Centerllines\trachea_centerline.vtp

But an error comes up about not being able to write to the output file.  There is apparently some kind of W8 security crap preventing it.  I've tried everything I can think of but nothing works.  I am the administrator and only user on this computer.

Here are some of the things I've tried:

1)  Created subfolder in the standard Documents folder and at C: level

2) Made sure the permissions of each group or user name listed for the output folder was set to Full control

3) In Properties for the folder, clicked Advanced button in Security tab.  Disabled inheritance and made sure each Principal was set to Full control.

4) "Open as administrator" a dos shell.  Used the attrib -r -s Drive:Foldername to reset read-only flag and system flag of folder, if set.

5) Created a text file in the folder called trachea_centerlines.vtp.  Set each Principal  for it to Full Control.  (Thinking that if a file by that name already existed, maybe it would be able to modify it.)

6) Set pythonw.exe compatibility to Windows 7

 

Thanks,

Greg

--
You received this message because you are subscribed to the Google Groups "vmtk-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vmtk-users+...@googlegroups.com.
To post to this group, send email to vmtk-...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Ian Campbell

unread,
Sep 7, 2013, 7:19:40 PM9/7/13
to vmtk-...@googlegroups.com
Hi Greg,

Have you turned off User Access Control in Windows 8? Even the administrator has to click Yes before performing certain operations. Don't forget to reboot once you change UAC settings, if you haven't already. I can't say for sure whether this will help VMTK, but I don't see it on your list below so thought I'd suggest it.

Good luck,
Ian

Greg Hanowski

unread,
Sep 8, 2013, 4:53:27 PM9/8/13
to vmtk-...@googlegroups.com

Ian,

Thanks for the suggestion but unfortunately that didn't work either. 

 

7. Turned off User Access Control and reboot.

 

Greg

David

unread,
Sep 10, 2013, 8:17:49 AM9/10/13
to vmtk-...@googlegroups.com

Hi, 

You're right, I didn't see the output file was not generated. This is curious because the same line of "vmtk" code works in linux. 
I tried to re-install the versions 1.0.0 and 1.0.1 of VMTK (win 7, 64 bit), without success. 

So, I'm still struggling with it. Any clue would be appreciated. 


Thanks
David

Jason Smith [Contractor]

unread,
Sep 10, 2013, 9:57:38 AM9/10/13
to vmtk-...@googlegroups.com
I'm not sure this will help anyone, but I am running VMTK to do centerline extraction and other activities on 64-bit Windows 7.  I believe I had to do two Windows specific things to get everything working.

(1) First I run a batch script to setup my python environment first, it looks like:

title VMTK Environment
echo Enabling VMTK Environment
@echo off
set VMTK=C:\Program Files\vmtk\Install
set PATH=%PATH%;%VMTK%\bin
set PYTHONPATH=%PYTHONPATH%;%VMTK%\bin\Python
set PYTHONPATH=%PYTHONPATH%;%VMTK%\lib\vtk-5.8
set PYTHONPATH=%PYTHONPATH%;%VMTK%\lib\vmtk
@echo on


(2) I also explicitly do pathname separator "correction", if I recall correctly I had a problem with the VMTK scripts not liking or generating some default windows path names.  That method basically looks something like: 

def run_script(script, files):
    """Runs the specified VMTK script using Pypes"""
    # Combine VMTK script with input and output file specifications
    fullscript = script.format(**files)
    fullscript = fullscript.replace('\\','/')

    # Pass script to Pypes environment for execution
    try:
        pipeline = pypes.PypeRun(fullscript)
    except RuntimeError, e:
        print '!'*80
        print 'ERROR'
        print e
        print '!'*80


Jason Smith
Software Developer, HJF
Biotechnology HPC Software Applications Institute




--

David

unread,
Sep 10, 2013, 1:07:26 PM9/10/13
to vmtk-...@googlegroups.com

Hi Jason, 

Thanks for your detailed reply. 

I'm ok with the point 1), but I still don't see how to implement the function you gave in your point 2). 
Could you provide an example please ?


Regards
D. 

Greg Hanowski

unread,
Sep 10, 2013, 1:23:12 PM9/10/13
to vmtk-...@googlegroups.com

Jason,

Thanks for your reply.  Like David, I don't understand item 2 but it gave me the clue about the path separator.  I set things up so that I could take them out and that worked! (I think).  Now I finally have a file called trachea_centerline.vtp.

 

But now how do I view it, along with the trachea to inspect how well it did? 

 

Then I will also need to bring the centerline back into Blender software to overlay on the geometry.  Can anyone shed some light?

Thank you,

Greg

 

From: vmtk-...@googlegroups.com [mailto:vmtk-...@googlegroups.com] On Behalf Of Jason Smith [Contractor]


Sent: Tuesday, September 10, 2013 7:58 AM
To: vmtk-...@googlegroups.com

Jason Smith [Contractor]

unread,
Sep 10, 2013, 1:50:04 PM9/10/13
to vmtk-...@googlegroups.com
The two Windows file name things I do are replace backslashes with forward slashes, and make sure filenames in script strings are enclosed by double quotes.


David: I have attached a simple example of running a script that is hopefully clearer, the filename is "sample.py".


Greg: I think you have some different options for visualization.
(1) VMTK provides a vmtkcenterlineviewer function, you should be able to combine that with vmtksurfaceviewer or other render type functions and adjust the opacity in a VMTK script.

(2) I don't have any Blender experience, in general I open my result STP files in ParaView for visualization.


(3) Finally, I also wrote a custom visualizer app for my pipeline that makes use of VTK and VMTK renderer, the references I used for that include:

Jason Smith
Software Developer, HJF
Biotechnology HPC Software Applications Institute


sample.py

Greg Hanowski

unread,
Sep 10, 2013, 2:17:27 PM9/10/13
to vmtk-...@googlegroups.com

David,

I tried the following script:

vmtkcenterlineviewer -ifile trachea_centerline.vtp --pipe

vmtksurfaceviewer -ifile trachea.vtp -opacity 0.25

 

and the centerlines showed up and they looked correct (Yea!), but not the trachea.  When I hit q (quit), then the centerlines disappeared and the transparent trachea appeared.

 

I'll try paraview next to see if they will come up together.

Thanks,

Jason Smith [Contractor]

unread,
Sep 10, 2013, 2:31:57 PM9/10/13
to vmtk-...@googlegroups.com
Greg,

I think you can use vmtkrenderer to view your geometries together.  I think there may be a better way, but this snippet overlays both files after I press "q" the first time.

vmtkrenderer --pipe vmtksurfaceviewer -opacity 0.25 -ifile "D:/projects/pipeline/example/surface.vtp" --pipe vmtkcenterlineviewer -ifile "D:/projects/pipeline/example/centerline.vtp"

Jason Smith
Software Developer, HJF
Biotechnology HPC Software Applications Institute


Greg Hanowski

unread,
Sep 10, 2013, 2:42:27 PM9/10/13
to vmtk-...@googlegroups.com

Jason,

Indeed, that worked, thank you!

 

But now I am able to see that the centerlines do not go all the way to the ends.  They stopped short of the inlet and outlet points by about 1/2" (on the screen).  I had generated them with the following command:

vmtkcenterlines -seedselector openprofiles -ifile trachea.vtp -ofile trachea_centerline.vtp

 

here is a screen shot

 

Greg

 

From: vmtk-...@googlegroups.com [mailto:vmtk-...@googlegroups.com] On Behalf Of Jason Smith [Contractor]
Sent: Tuesday, September 10, 2013 12:32 PM
To: vmtk-...@googlegroups.com
Subject: Re: [vmtk-users] Re: How to run PypeS programmatically in Windows (for centerlines extraction)

 

Greg,

--

image003.jpg

Jason Smith [Contractor]

unread,
Sep 10, 2013, 2:57:15 PM9/10/13
to vmtk-...@googlegroups.com
Greg

I think you will need to reference Luca's thesis for the full information, but a relevant bit is in the centerlines tutorial (http://www.vmtk.org/Tutorials/Centerlines/):

"If you inspect the centerlines closely, you'll notice that they don't exactly reach seed and target points, but they just go close to them. The reason is that centerlines lie on the Voronoi diagram, and the Voronoi diagram does not touch the surface (for the ones interested, centerlines stop at the poles associated with seed and target points; look here to find out what poles are). If you want centerlines to end precisely at source and target points, specify the option -endpoints 1: this way the segments from sources and targets to their respective poles are appended to the centerlines."
image003.jpg

Greg Hanowski

unread,
Sep 10, 2013, 3:18:42 PM9/10/13
to vmtk-...@googlegroups.com

Jason,

Thank you, I had forgotten about that.

 

Indeed, that fixed the problem.  Here is the command that worked:

vmtkcenterlines -seedselector openprofiles -ifile trachea.vtp -endpoints 1 -ofile trachea_centerline.vtp

image003.jpg
image004.jpg

David

unread,
Sep 10, 2013, 3:47:39 PM9/10/13
to vmtk-...@googlegroups.com

Jason, 

I tried to merely replace one of my .STL file (too large to be sent) in your script (sample.py) but I got the following messages (with the attached file Test-1.py): 

No module named script
No module named pipeline

If I replace pipeline by pype, I get the messages:

No module named script
Automatic piping pype

And if I just run the script string given in Test-2.py, I can at least compute a centerline, but I'm still unable to generate the corresponding file when I hit q.
Sorry but I'm missing something. 


David



Test-1.py
Test-2.py

Jason Smith [Contractor]

unread,
Sep 11, 2013, 8:06:12 AM9/11/13
to vmtk-...@googlegroups.com
Hi David

The error message about the interpreter thinking that the variables are modules is quite odd, how are you running the script?  I'm running from the command line (i.e. "python Test-1.py").

As far as the VMTK script, I didn't spot anything at first glance, but I'm by no means a VMTK expert.  I would suggest saving the calculated centerline file so you don't have to keep selecting points and running that calculation, then using that file as an input into a new pipeline starting with vmtkbranchextractor as mentioned in the tutorial.  For example,
vmtkbranchextractor -ifile foo_cl.vtp -radiusarray MaximumInscribedSphereRadius
I think that should at least let you iterate on the visualization & data writing part of your script more quickly.
Jason Smith
Software Developer, HJF
Biotechnology HPC Software Applications Institute



David

unread,
Sep 12, 2013, 9:47:44 AM9/12/13
to vmtk-...@googlegroups.com
Hi Jason, 

Thank you for providing your help, this is much appreciated. 

I also run my script from the command line (I made sure ...;C:\Python27 was appended to the Path in the "Environment Variables").

If I simply have the statement print "hi" in my script, I can print hi, but if I add the statement from vmtk import pypes, I get the message ImportError: No module named vmtk 

So, I don't know how to "actually" import the modules from vmtk. Even if I add the full path of the vmtk installation folder to the path, it does not find vmtk libraries/modules/.py files.
Therefore I'm not even able to call any vmtkbranchextractor.py, vmtkcenterlines.py or pypes.py . 

That's why in the very first message of this topic I mentioned the following lines:

import imp
import sys
import os 
import string

imp.load_source('pypes', 'C:/Program Files/vmtk/Install/lib/vmtk/vmtk')
imp.load_source('vmtkscripts', 'C:/Program Files/vmtk/Install/lib/vmtk/vmtk')

As I tried to figure out how call vmtk libraries from my script. This is a crucial point I first need to address. 


Thanks
David


David

unread,
Sep 12, 2013, 10:34:11 AM9/12/13
to vmtk-...@googlegroups.com

David

unread,
Sep 12, 2013, 10:36:29 AM9/12/13
to vmtk-...@googlegroups.com

Hi Jason, 

The problem is solved. 
What you suggested in your last message ("then using that file as an input into a new pipeline starting with vmtkbranchextractor as mentioned in the tutorial")
worked well. 

Thank you very much for your support. 


David

Jason Smith [Contractor]

unread,
Sep 13, 2013, 8:29:45 AM9/13/13
to vmtk-...@googlegroups.com
Hi David

I'm glad you were able to get everything going!  I did have some problems making one "mega" script to do everything, so I actually ended up using a couple of different scripts which build on previous output during my processing pipeline.

Jason



--

Greg Hanowski

unread,
Sep 22, 2013, 9:11:08 PM9/22/13
to vmtk-...@googlegroups.com

Jason and others,

Now that it worked with the test geometry, I'm finally getting around to using it on my real geometry.  I followed the same preparation procedure and enter

vmtkcenterlines -seedselector openprofiles -ifile "Descending thoracic aorta.vtp" -endpoints 1 -ofile "Descending thoracic aorta_centerline.vtp"

 

It brings up a vmtk window with the geometry.  But this time I note there are no inlet and outlet labels

 

I enter q and it asks for the inlet ids.  I enter 0

 

It asks for the outlet ids.  I enter 1

 

It says "Computing centerlines..." and then a Windows 8 dialog pops up saying "pythonw.exe has stopped working".  I can choose from "Check online for a solution and close the program" or "Close the program".

 

Attached is the geometry file if anyone can tell me what's wrong?

 

Thanks,

image001.png
image002.jpg
image003.jpg
Descending thoracic aorta.vtp

Arjan Geers

unread,
Sep 23, 2013, 8:55:07 AM9/23/13
to vmtk-...@googlegroups.com
Hi Greg, 

'Descending thoracic aorta.vtp' is a closed surface and the pype you're using is looking for 'openprofiles' (i.e. holes in the surface) to identify possible inlets and outlets. Instead, I'd recommend using the seedselector option 'pickpoint':

vmtkcenterlines -seedselector pickpoint -ifile "Descending thoracic aorta.vtp" -endpoints 1 -ofile "Descending thoracic aorta_centerline.vtp"

Run this script and a window appears displaying the surface. Position the mouse at the inlet, press the space bar and 'q'. Then, position the mouse at the outlet, press the space bar and 'q'.

If there are multiple inlets or outlets, just repeat 'position the mouse + press space bar' before pressing 'q'. Each selected point will be indicated by a small red sphere.

Hope this helps, 

Arjan
image001.png
image002.jpg
image003.jpg

Greg Hanowski

unread,
Sep 23, 2013, 9:10:34 AM9/23/13
to vmtk-...@googlegroups.com

Thanks Arjan, that makes sense.

Greg

image001.png
image002.jpg
image003.jpg
Reply all
Reply to author
Forward
0 new messages