Medical Imaging Interaction Toolkit
2016.11.0
Medical Imaging Interaction Toolkit
|
The MITK Python Module provides a service class to interactively run python code (passed as C++ strings) and evaluate the results. Furthermore the service class offers means to convert an MITK Image to an ITK/OpenCV image in their wrapped python environment. Thus, one can process MITK images with Python Code from the OpenCV and ITK wrapping system. Furthermore one can convert an mitk::Surface to a vtkPolyData in its Python environment.
Under the hood, the MITK build system takes care that the wrapping build process for SimpleITK/VTK/OpenCV is correctly initiated and all paths are correctly set within MITK code. To use the features of the different toolkits make sure they are enabled during the superbuild process.
Have a look at Qt5 Support on how to build MITK-Python with Qt5. The following CMake build options are available:
MITK_USE_Python enables the python wrapping in MITK. When the option is activated the build of the additional dependency SimpleITK is also enabled. The default behaviour is to download and build Python 2.7.3 with numpy and embed it into MITK. To use an own custom runtime see MITK_USE_SYSTEM_PYTHON.
This option is deactivated by default. If MITK_USE_SYSTEM_PYTHON is activated the python runtime from the system is used. Only Python 2.7.x is supported. The user can also specify it's own runtime by modifying the variables added by the FindPythonLib.cmake script. Note: A Python runtime with numpy is needed to use the MITK Python wrapping. When using this options all additional libraries installed in the python runtime will be available within the MITK-Python console.
In order to build MITK-Python with Qt5 support an external build of CTK and PythonQt 3.0 is necessary. The current MITK CTK superbuild only supports PythonQt 2.0 that has no Qt 5 support. This will most likely only work with the MITK_USE_SYSTEM_PYTHON option due to dependencies of each external project. It can be build with the following steps:
PythonQt 3 has no CMake build system and has to be build by hand with qmake. Download and build PythonQt 3 from sourceforge.
Build the current CTK master with the external PythonQt 3 binaries. The external PythonQt 3 binaries can be added in CTK by adding the following CMake variable that points to the PythonQt build directory:
More information about the changes added in CTK for PythonQt are available on Github.
In the last step MITK has to be build with the CTK from the previous step Step2 - Build CTK. This is done by setting the CTK_Dir to the CTK build directory:
The following data types in MITK are supported in the MITK Python Wrapping:
Mitk Images can be transferred to python. The images are copied in-memory and transferred as a numpy array to Python and vice versa. The MITK python wrapping creates a SimpleITK image using the numpy array with the properties of the MITK Image. Two dimensional images can also be transferred as an OpenCV image to python.
Surfaces within mitk can be transferred as a vtkPolyData Object to Python. The surfaces are fully memory mapped. When changing a python wrapped surface the original object is also modified on the C++ side of MITK.