Documentation/4.1/Developers/Python scripting
- do this before building slicer4 - or do "cd Slicer4-superbuild/; rm -rf python* ; make"
sudo apt-get install libreadline6-dev
cd Slicer4-superbuild
- this should be done in superbuild script
(cd ./VTK-build/Wrapping/Python; ../../../Slicer-build/Slicer4 --launch ../../../python-build/bin/python setup.py install)
git clone git://github.com/ipython/ipython.git
git checkout 0.10.2
(cd ./ipython; ../Slicer-build/Slicer4 --launch ../python-build/bin/python setup.py install)
svn co https://matplotlib.svn.sourceforge.net/svnroot/matplotlib/branches/v1_0_maint matplotlib-source
(cd ./matplotlib-source; ../Slicer-build/Slicer4 --launch ../python-build/bin/python setup.py install)
rm -rf matplotlib-source
./Slicer-build --launch xterm &
- in xterm:
./python-build/bin/ipython
import vtk import slicer mrml = slicer.vtkMRMLScene() vl = slicer.vtkSlicerVolumesLogic() vl.SetAndObserveMRMLScene(mrml) n = vl.AddArchetypeVolume('../Slicer4/Testing/Data/Input/MRHeadResampled.nhdr', 'CTC') i = n.GetImageData() print (i.GetScalarRange())
import vtk.util.numpy_support a = vtk.util.numpy_support.vtk_to_numpy(i.GetPointData().GetScalars()) print(a.min(),a.max())
import matplotlib import matplotlib.pyplot n, bins, patches = matplotlib.pyplot.hist(a, 50, facecolor='g', alpha=0.75) matplotlib.pyplot.show()