Tutorial
Introduction to MeVisLab
Tutorial Introduction
Welcome to MeVisLab!
More than 20 years of experience and the continuous implementation of adaptations made MeVisLab one of the most powerful development platforms for medical image processing. Several applications and their prototypes are based on and could be realized because of MeVisLab, including software assistants for neuro-imaging, dynamic image analysis, surgery planning, and cardiovascular analysis.
MeVisLab is a development environment for rapid prototyping and product development of medical and industrial imaging applications. It includes a Software Development Kit (SDK) and an ApplicationBuilder for deploying your applications to end-customers.
Chapter I: Basic Mechanisms of MeVisLab
Basic Mechanics of MeVisLab (Example: Building a Contour Filter)
In this chapter you will learn the basic mechanisms of the MeVisLab IDE. You will learn how to re-use existing modules to load and view data and you will build your first processing pipeline.
Loading Data
First, we need to load the data we would like to work on, e.g. a CT scan. In MeVisLab, modules are used to perform their associated specific task, they are the basic entities you will be working with. Each module has a different functionality for processing, visualization and interaction. Connecting modules enables the development of complex processing pipelines. You will get to know different types of modules throughout the course of this tutorial.
Example 1: Data import in MeVisLab
Example 1: Data Import in MeVisLab
MeVisLab provides several pre-defined modules to import data for processing in your networks.
These chapters explain the data formats and modules related to this example:
Example 1.1: MeVisLab Coordinate Systems
Example 1.1: MeVisLab Coordinate Systems
Three coordinate systems exist next to each other:
- World coordinates
- Voxel coordinates
- Device coordinates
World coordinate systems in MeVisLab are always right handed.
The blue rectangle shows the same region in the three coordinate systems.
World coordinates
World coordinates are:
- Global: Combine several objects in a view
- Isotropic: All directions are equivalent
- Orthogonal: Coordinate axes are orthogonal to each other
The origin of the world coordinate system can be anywhere and is not clearly defined. Origins of the other coordinate systems can always be mapped to the world coordinate system. In case of DICOM images, this mapping is defined by DICOM tags.
Example 1.2: DICOM Coordinate Systems
Example 1.2: DICOM Coordinate Systems
General
Coordinate systems in DICOM are basically the same as world coordinates in MeVisLab (except for the 0.5 voxel offset). World coordinates also refer to the patient axes. They are:
- Based on the patient’s main body axes (transverse, coronal, sagittal)
- Measured as 1 coordinate unit = 1 millimeter
- Right-handed
- Not standardized regarding their origin
Example 2: Macro modules and Module Interaction
Example 2: Macro modules
Macro modules and Module Interactions via User Interface and Python Scripting
MeVisLab provides different types of modules, which can be distinguished by their color. The brown modules are called Macro modules. Macro modules condense a whole network into one module. You can open the internal network by pressing the middle mouse button or via right mouse click and select [ Help → Show Internal Network ]. Macro modules provide the possibility to create customized user interfaces and Python interactions.
Example 2.1: Package Creation
Example 2.1: Package creation
Introduction
Packages are the way MeVisLab organizes different development projects.
Macro modules and projects are stored in packages. If you like to create a global macro module, you need a package in which this macro module can be stored in. In this chapter, we will create our own package. We start our package creation by creating a package group, because every package needs to be stored in a package group. You can find detailed information about packages and package groups here and in the package documentation .
Example 2.2: Creation of global macro modules
Example 2.2: Global macro modules
Introduction
In this chapter you will learn how to create global macro modules. There are many ways to do this. You can convert local macros into global macro modules or you can directly create global macro modules using the Project Wizard. In contrast to local macro modules, global macro modules are commonly available throughout projects and can be found via module search and under [ Modules ].
Example 2.3: Creation of module help
Example 2.3: Creation of module help
Generating help of a macro module is part of the video about macro modules from Example 2: Creation of global macro modules
Introduction
In this chapter, you will learn how to create a help page and an example network. For hands-on training, we will use the macro module Filter
, which was created in the previous chapter.
Example 2.4: GUI development
Example 2.4: Building a Panel Layout: Interactions with macro modules
Introduction
This chapter will give you an introduction into the creation of module panels and user interfaces. For the implementation you will need to use the MeVisLab Definition Language (MDL) .
Creating a panel for the macro module flilter
Creation of a module panel
In Example 2.2 we created the global macro module Filter
. By now, this module does not have a proper panel. When double-clicking
the module, the Automatic Panel is shown.
Example 2.5: Interactions via Python scripting
Example 2.5: Module Interactions Using Python Scripting
Introduction
This chapter will give you an overview over Python scripting in MeVisLab. Here, no introduction into Python will be given. However, basic knowledge in Python is helpful. Instead, we will show how to integrate and use Python in the MeVisLab SDK.
In fact, nearly everything in MeVisLab can be done via Python scripting: You can add modules to your network, or remove modules, you can dynamically establish and remove connections and so on. But, much more important: You can access module inputs and outputs, as well as module fields to process their parameters and data. You can equip user interfaces and panel with custom functionalities. Python can be used to implement module interactions. When you open a panel or you press a button in a panel, the executed actions are implemented via Python scripting.
Example 2.5.1: The module RunPythonScript
Example 2.5.1: The module RunPythonScript
Introduction
The module RunPythonScript
allows to execute Python scripts from within a MeVisLab network. You can draw parameter connection from modules to RunPythonScript
and back, to process parameter fields using Python scripting.
Steps to do
Develop your network
In this example, we like to dynamically change the color of a cube in an Open Inventor scene. For that, add and connect the following modules as shown.
Example 2.5.2: Module interactions via Python scripting
Example 2.5.2: Module interactions via Python scripting
Introduction
In this example, you will learn how to add Python scripting to your User Interface. The network used in Chapter V will be used for creating the macro module.
Steps to do
Creating the macro module
First, we condense the example network into a macro module and then we create a panel for that module. To create a macro module use the Project Wizard, which you find under [ File → Run Project Wizard ]. Select Macro module and press Run.
Example 3: Creating a simple application
Example 3: Creating a simple application
Introduction
In the previous examples, you already learned how to create macro modules, user interfaces and how to interact with your UI via Python scripting.
In this example, you will learn how to create a simple Prototype application in MeVisLab including a User Interface with 2D and 3D viewer. You will learn how to implement field listeners and react on events.
Steps to do
Create your network
Start with an empty network and add the Module ImageLoad
to your workspace. Then add a View2D
and View3D
to your workspace and connect the modules as seen below.
Example 4: Installing additional Python packages using the PythonPip module
Example 4: Installing additional Python packages using the PythonPip module
Introduction
MeVisLab already comes with a lot of integrated third party software tools ready to use. Nevertheless it might be necessary to install additional Python packages for your specific needs. This example will walk you through the process of adding packages through usage of/using the PythonPip
module.
The PythonPip
module allows to work with the Python package manager pip. It can be used to install Python packages into the site-packages of the MeVisLab Python installation.
Chapter II: Open Inventor
Open Inventor modules
Introduction
In total, there are three types of modules:
- blue ML modules
- brown macro modules
- green Open Inventor modules
The names of Open Inventor modules start with the prefix So\*
(for Scene Objects). Open Inventor modules process and render 3D scene objects and enable image interactions. Scene objects are transmitted using the semi-circle shaped input and output connectors. With the help of these modules, Open Inventor scenes can be implemented.
Example 1: Open Inventor Objects
Example 1: Open Inventor Objects
Introduction
In this example we like to construct an Open Inventor scene in which we display three 3D objects of different color and shape.
Steps to do
Generating Open Inventor Objects
First, add the modules SoExaminerViewer
and SoCone
to the workspace and connect both modules as shown. The module SoCone
creates a cone shaped object, which can be displayed in the Viewer SoExaminerViewer
.
Example 2: Mouse interactions in Open Inventor
Example 2: Mouse interactions in Open Inventor
Introduction
In this example, we implement some image or object interactions. We will create a 3D scene, in which we display a cube and change its size using the mouse. We also get to know another viewer, the module SoExaminerViewer
. This viewer is important. It enables the rendering of Open Inventor scenes and allows interactions with the Open Inventor scenes.
Example 3: Camera Interactions in Open Inventor
Example 3: Camera Interactions in Open Inventor
Introduction
In this example, we are learning the basic principles of camera interactions in Open Inventor. We will show the difference between a SoRenderArea
and a SoExaminerViewer
and use different modules of the SoCamera*
group.
The SoRenderArea
module
The module SoRenderArea
is a simple renderer for Open Inventor scenes. It offers functionality to record movies and to create snapshots, but does not include an own camera or light.
Example 4: Post Effects in Open Inventor
Example 4: Post Effects in Open Inventor
Introduction
Up to this point, we practiced constructing Open Inventor scenes and placed three-dimensional Open Inventor objects of different colors and shapes within them. In this tutorial, we will go over the steps to add shadows to our 3D-objects, make them glow and vary their opacity to make them transparent. We will also incorporate WEMs from multi-frame DICOMs and render them as scene objects to see how different post effects can be used on them.
Chapter III: Visualization
Visualization in MeVisLab
Introduction
Images and data objects can be rendered in 2D and 3D and interacted with in several ways using a set of tools available through MeVisLab. In this chapter in particular, we will focus on simple image interaction with two- and three-dimensional visualizations.
View2D and View3D
An easy way to display data and images in 2D and 3D is by using the Modules View2D
and View3D
. What can be done with these viewers?
Example 1: Synchronous view of two images
Example 1: Synchronous view of two images
Introduction
In this example we like to use the module SynchroView2D
to be able to inspect two different images simultaneously.
The module SynchroView2D
 provides two 2D viewers that are synchronized.
As in Tutorial Chapter 1 - Basic Mechanics of MeVisLab, the processed and the unprocessed image can be displayed simultaneously. Scrolling through one image automatically changes the slices of both viewers, so slices with the same slice number are shown in both images.
Example 2: Creating a magnifier
Example 2: Creating a magnifier
Introduction
Medical images are typically displayed in three different viewing directions (see image): coronal, axial and sagittal.
Using the Viewer OrthoView2D
you are able to decide, which viewing direction you like to use. In addition to that, you have the opportunity to display all three orthogonal viewing directions simultaneously. Here, we like to display an image of the head in all three viewing directions and mark positions in the image.
Example 3: Image Overlays
Example 3: How to blend images over each other
Introduction
In this example we will show you how to blend a 2D image over another one. With the help of the module SoView2DOverlay
we will create an overlay, which allows us to highlight all bones in the scan.
Steps to do
Develop your network
Start this example by adding the shown modules, connecting the modules to form a network and loading the example image Bone.tiff.
Example 4: Display 2D images in Open Inventor SoRenderArea
Example 4: Display images converted to Open Inventor scene objects
Introduction
In the previous example you learned how to use the module SoView2DOverlay
together with a View2D
. MeVisLab provides a whole family of SoView2D*
modules (SoView2DOverlay
, SoView2DRectangle
, SoView2DGrid
, …). All these modules create or interact with scene objects and are based on the module SoView2D
, which can convert a voxel-image into a scene object. In this example, you will get to know some members of the SoView2D
-family.
Example 5: Volume rendering and interactions
Example 5: Volume rendering and interactions
Introduction
In this example we like to convert a scan of a head into a 3D scene-object. The scene-object allows to add some textures, interactions and animations.
Steps to do
Develop your network
Implement the following network and open the image $(DemoDataPath)/BrainMultiModal/ProbandT1.tif.
The module SoGVRVolumeRenderer
allows volume rendering of 3D and 4D images.
Example 6: MeVis Path Tracer
Example 6: MeVis Path Tracer
Introduction
The MeVis Path Tracer offers a Monte Carlo Path Tracing framework running on CUDA GPUs. It offers photorealistic rendering of volumes and meshes, physically based lightning with area lights and soft shadows and fully integrates into MeVisLab Open Inventor (camera, depth buffer, clipping planes, etc.).
Example 6.1: Volume Rendering vs. Path Tracer
Example 6.1: Volume Rendering vs. Path Tracer
Introduction
In this example you develop a network to show some differences between volume rendering and the MeVisLab Path Tracer. You will visualize the same scene using both 3D rendering techniques and some of the modules for path tracing.
The MeVis Path Tracer requires an NVIDIA graphics card with CUDA support. In order to check your hardware, open MeVisLab and add a SoPathTracer
module to your workspace. You will see a message if your hardware does not support CUDA:
Example 6.2: Visualization using Path Tracer
Example 6.2: Visualization using SoPathTracer
Introduction
In this tutorial, we will explain the basics of using the SoPathTracer
module in MeVisLab. You will learn how to create a scene, assign materials, add light sources, and configure the PathTracer to generate enhanced renderings.
The MeVis Path Tracer requires an NVIDIA graphics card with CUDA support. In order to check your hardware, open MeVisLab and add a SoPathTracer
module to your workspace. You will see a message if your hardware does not support CUDA:
Example 7: Add 3D viewer to OrthoView2D
Example 7: Add 3D viewer to OrthoView2D
Introduction
In this example we will use the OrthoView2D
module and add a 3D viewer to the layout Cube.
Steps to do
Develop your network
Add the modules LocalImage
and OrthoView2D
to your workspace and connect them.
The OrthoView2D
module allows you to select multiple layouts. Select layout Cube Equal. The layout shows your image in three orthogonal viewing directions. The top left segment remains empty.
Example 8: Vessel Segmentation using SoVascularSystem
Example 8: Vessel Segmentation using SoVascularSystem
Introduction
In this tutorial, we are using an input mask to create a vessel centerline using the DtfSkeletonization
module and visualize the vascular structures in 3D using the SoVascularSystem
module. The second part uses the distance between centerline and surface of the vessel structures to color thin vessels red and thick vessels green.
Steps to do
Develop your network
Load the example tree mask by using the LocalImage
module. Connect the output to a DtfSkeletonization
module as seen below. The initial output of the DtfSkeletonization
module is empty. Press the Update button to calculate the skeleton and the erosion distances.
Example 9: Creating Dynamic 3D Animations using AnimationRecorder
Example 9: Creating Dynamic 3D Animations using AnimationRecorder
Introduction
In this tutorial, we are using the AnimationRecorder
module to generate dynamic and visually appealing animations of our 3D scenes. We will be recording a video of the results of our previous project, particularly the detailed visualizations of the muscles, bones and blood vessels created using PathTracer
.
Steps to do
Open the network and files of Example 6.2, add a SoSeparator
module and an AnimationRecorder
module to your workspace and connect them as shown below.
Chapter IV: Image Processing
Image Processing in MeVisLab
Digital image processing is the use of a digital computer to process digital images through an algorithm (see Wikipedia).
MeVisLab provides multiple modules for image processing tasks, such as:
- Filters
- Masks
- Transformations
- Arithmetics
- Statistics
For details about Image Processing in MeVisLab, see the MeVisLab Documentation
In this chapter, you will find some examples for different types of image processing in MeVisLab.
Example 1: Arithmetic operations on two images
Example 1: Arithmetic operations on two images
Introduction
We are using the Arithmetic2
module to apply basic scalar functions on two images. The module provides 2 inputs for images and 1 output image for the result.
Steps to do
Develop your network
Add two LocalImage
modules to your workspace for the input images. Select $(DemoDataPath)/BrainMultiModal/ProbandT1.dcm and $(DemoDataPath)/BrainMultiModal/ProbandT2.dcm from MeVisLab demo data and add a SynchroView2D
to your network.
Example 2: Masking images
Example 2: Masking images
Introduction
The background of medical images is black for most cases. In case an image is inverted or window/level values are adapted, these black pixels outside clinical relevant pixels might become very bright or even white.
Being in a dark room using a large screen, the user might be blended by these large white regions.
Image masking is a very good way to select a defined region where image processing shall be applied. A mask allows to define a region (the masked region) to allow image modifications whereas pixels outside the mask remain unchanged.
Example 3: Region Growing
Example 3: Region Growing
Introduction
A very simple approach to segment parts of an image is the region growing method. A general explanation can be found here.
In this example, you will segment the brain of an image and show the segmentation results as an overlay on the original image.
Steps to do
Develop your network
Add a LocalImage
module to your workspace and select load $(DemoDataPath)/BrainMultiModal/ProbandT1.dcm. Add a View2D
module and connect both as seen below.
Example 4: Subtract 3D objects
Example 4: Subtract 3D objects
Introduction
In this example, we load an image and render it as WEMIsoSurface
. Then we create a 3-dimensional SoSphere
and subtract the sphere from the initial WEM.
Steps to do
Develop your network
Add a LocalImage
module to your workspace and select load $(DemoDataPath)/BrainMultiModal/ProbandT1.dcm. Add a WEMIsoSurface
, a SoWEMRenderer
, a SoBackground
and a SoExaminerViewer
module and connect them as seen below. Make sure to configure the WEMIsoSurface
to use a Iso Min. Value of 420 and a Voxel Sampling 1.
Example 5: Clip Planes
Example 5: Clip Planes
Introduction
In this example, we are using the SoGVRDrawOnPlane
module to define the currently visible slice from a 2D view as a clip plane in 3D.
Steps to do
Develop your network
First we need to develop the network to scroll through the slices. Add a LocalImage
module to your workspace and select the file ProbandT1 from MeVisLab demo data.
Chapter V: Data Objects
Data Objects in MeVisLab
MeVisLab provides pre-defined data objects, e. g.
- Contour Segmented Objects (CSOs)
which are three-dimensional objects encapsulating formerly defined contours within images. - Surface Objects (Winged Edge Meshes or WEMs)
represent the surface of geometrical figures and allow the user to manipulate them. - Markers
are used to mark specific locations or aspects of an image and allow to process those later on. - Curves
can print the results of a function as two-dimensional mathematical graphs into a diagram.
Usage, advantages and disadvantages of each above mentioned data object type will be covered in the following specified chapters, where you will be building example networks for some of the most common use cases.
Contour Objects (CSO)
Contour Segmented Objects (CSOs) in MeVisLab
Introduction
Structure of CSOs
MeVisLab provides modules to create contours in images. 3D objects which encapsulate these contours are called Contour Segmented Objects (CSOs).
In the next image, you can see a rectangular shaped CSO. The pink circles you can see are called Seed Points.
Seed Points define the shape of the CSO. In case of a rectangle, you need four Seed Points forming the corners, to define the whole rectangle.
Contour Example 1: Creation of Contours
Contour Example 1: Creation of Contours
Introduction
We like to start with the creation of CSOs. To create CSOs, you need a SoCSO*
-Editor. There are several different editors, which can be used to create CSOs (see here). Some of them are introduced in this example.
Steps to do
Develop your network
For this example, we need the following modules. Add the modules to your workspace, connect them as shown below and load the example image $(DemoDataPath)/BrainMultiModal/ProbandT1.tif.
Contour Example 2: Contour Interpolation
Contour Example 2: Creating Contours using Live Wire and Interpolation
Introduction
In this example, we like to create CSOs using the Live Wire Algorithm, which allows semi-automatic CSO creation. The algorithm uses edge detection to support the user creating CSOs.
We also like to interpolate CSOs over slices. That means additional CSOs are generated between manual segmentations based on a linear interpolation.
Contour Example 3: 2D and 3D Visualization of Contours
Contour Example 3: Overlay Creation and 3D Visualization of Contours
Introduction
In this example, we’d like to use the created CSOs to display an overlay. This allows us to mark one of two lungs. In addition to that, we will display the whole segmented lobe of the lung in a 3D image.
Steps to do
Develop your network
Use the network from the contour example 2 and add the modules VoxelizeCSO
,
SoView2DOverlay
and View2D
to your workspace. Connect the module as
shown. The module VoxelizeCSO
allows to convert CSOs into voxel images.
Contour Example 4: Annotation of Images
Contour Example 4: Annotation of Images
Introduction
In this example we like to calculate the volume of our object, in this case the part of the lung we have segmented.
Steps to do
Develop your network and calculate the lung volume
Add the module CalculateVolume
and SoView2DAnnotation
to your workspace
and connect both modules as shown. Update the module CalculateVolume
,
which directly shows the volume of our object.
Contour Example 5: Contours and Ghosting
Contour Example 5: Visualizing Contours and Images
Introduction
In this example, we like to automatically create CSOs based on a predefined iso value.
Steps to do
Develop your network
Add the following modules to your workspace and connect them as shown. Load the example image Bone.tiff.
Automatic creation of CSOs based on the iso value
Now, open the panel of CSOIsoGenerator
to set the Iso Value to 1200. If you press Update in
the panel, you can see the creation of CSOs on every slide, when opening
the module View2D
. In addition to that the number of CSOs is displayed in the CSOManager
. The module
CSOIsoGenerator
generates iso-contours for each slice at a fixed iso
value. This means that closed CSOs are formed based on the detection of the
voxel value of 1200 on every slice.
Contour Example 6: Adding Labels to Contours
Contour Example 6: Adding Labels to Contours
Introduction
In this example, we are adding a label to a contour. The label provides information about measurements and about the contour itself. The label remains connected to the contour and can be moved via mouse interactions.
Steps to do
Develop your network
Add a LocalImage
and a View2D
module to your workspace and connect them as shown below. Load the file ProbandT1.dcm from MeVisLab demo data. In order to create contours (CSOs), we need a SoView2DCSOExtensibleEditor
module. It manages attached CSO editors, renderers and offers an optional default renderer for all types of CSOs.
Contour Example 7: Using the CSOListContainer
Contour Example 7: Using the CSOListContainer
Introduction
In this example, we are using the module CSOListContainer
instead of the CSOManager
. The CSOManager
is a heavy weight, UI driven module. You can use it to see all of your CSOs, CSOLists and CSOGroups in the module panel. The CSOListContainer
is a light weight module with focus on Python scripting. We recommend to use this module for final application development, because Python provides much more flexibility in handling CSO objects.
Surface Objects (WEM)
Surface Objects (WEMs)
Introduction
In MeVisLab it is possible to create, visualize, process and manipulate surface objects, also known as polygon meshes. Here, we call surface objects Winged Edge Mesh, in short WEM. In this chapter you will get an introduction into WEMs. In addition, you will find examples on how to work with WEMs. For more information on WEMs take a look at the MeVislab Toolbox Reference . If you like to know which WEM formats can be imported into MeVisLab, take a look at the assimp documentation here.
Surface Example 1: Creation of WEMs
Surface Example 1: Create Winged Edge Mesh out of voxel images and CSOs
Introduction
In this example you will learn how to create a Winged Edge Mesh (WEM). There are several approaches on creating WEMs, a few of them are shown in this example. Instead of creating WEMs, they can also be imported, see chapter Surface Objects (WEM).
Steps to do
From image to surface: Generating WEMs out of voxel images
At first, we will create a WEM out of a voxel image using the module WEMIsoSurface
. Add and connect the shown modules. Load the image $(DemoDataPath)/Bone.tiff and set the Iso Min. Value in the panel of WEMIsoSurface
to 1200. Tick the box Use image max. value. The module WEMIsoSurface
creates surface objects out of all voxels with an Iso value equal or above 1200 (and smaller than the image max value). The module SoWEMRenderer
can now be used to generate an Open Inventor scene, which can be displayed by the module SoExaminerViewer
.
Surface Example 2: Processing and Modification of WEM
Surface Example 2: Processing and Modification of WEM
Introduction
In this example, you will learn how to modify and process WEMs.
Steps to do
Develop your network
Modification of WEMs
Use the module WEMLoad
to load the file venus.off. Then add and connect the shown modules. We like to display the WEM venus two times, one time this WEM is modified. You can use the module WEMModify
to apply modifications. In its panel, change the scale and the size of the WEM. Now you see two times the venus
next to each other.
Surface Example 3: Interactions with WEM
Surface Example 3: Interactions with WEM
Introduction
In these examples, we are showing 2 different possibilities to interact with a WEM:
- Scale, rotate and move a WEM in a scene
- Modify a WEM in a scene
Scale, rotate and move a WEM in a scene
We are using a SoTransformerDragger
module to apply transformations on a 3D WEM object via mouse interactions.
Surface Example 4: Interactively moving WEM
Surface Example 4: Interactively moving WEM
Introduction
In this example, we like to interactively move WEMs using SoDragger
modules insight a viewer.
Develop your network
Interactively translating objects in 3D using SoDragger modules
Add and connect the following modules as shown. In the panel of the module WEMInitialize
select the Model Octasphere. After that, open the viewer SoExaminerViewer
and make sure to select the Interaction Mode. Now, you are able to click on the presented Octaspehere and move it alongside one axis. The following modules are involved in the interactions:
Surface Example 5: WEM - Primitive Value Lists
Surface Example 5: WEM - Primitive Value Lists
Introduction
WEMs do not only contain the coordinates of nodes and surfaces, they can also contain additional information. These information are stored in so called Primitive Value Lists (PVLs). Every node, every surface and every edge can contains such a list. In these lists, you can for example store the color of the node or specific patient information. These information can be used for visualization or for further statistical analysis.
Chapter VI: Testing
MeVisLab Tutorial Chapter VI
Testing, Profiling and Debugging in MeVisLab
The MeVisLab Integrated Development Environment (IDE) provides tools to write automated tests in Python, profile your network performance and to debug your Python code. All of these funtionalities will be addressed in this chapter.
Testing
The MeVisLab TestCenter is the starting point of your tests. Select [ File → Run TestCaseManager ] to open the user interface of the TestCaseManager.
Marker Objects
Markers in MeVisLab
In MeVisLab you can equip images and other data objects with markers. In this example you will see how to create, process and use markers.
Creation and Rendering
To create markers, you can use a marker editor, for example the SoView2DMarkerEditor
. Connect this editor to a viewer as shown below. Now you can interactively create new markers. Connect the module XMarkerListContainer
to your marker editor to store markers in a list.
Example 1: Distance between Markers
Example 1: Calculating the distance between markers
Introduction
In this example, we will measure the distance between one position in an image to a list of markers.
Steps to do
Develop your network
Add the following modules and connect them as shown.
We changed the names of the modules SoView2DMarkerEditor
and XMarkerLIstContainer
, to distinguish these modules from two similar modules we will add later on. Open the panel of SoView2DMarkerEditor
and select the tab Drawing. Now chose the Color red.
Example 1: Writing a simple test case in MeVisLab
Example 1: Writing a simple test case in MeVisLab
Introduction
In this example, you will learn how to write an automated test for a simple network using the DicomImport
, MinMaxScan
and View3D
modules. Afterwards, you will be able to write test cases for any other module and network yourself.
Steps to do
Creating the network to be used for testing
Add the following modules to your workspace and connect them as seen below:
Example 2: Profiling in MeVisLab
Example 2: Profiling in MeVisLab
Introduction
In this example, we are using the MeVisLab Profiler to inspect the memory and CPU consumption of the modules in an example network.
Steps to do
Creating the network to be used for profiling
You can open any network you like, here we are using the example network of the module MinMaxScan
for profiling. Add the module MinMaxScan
to your workspace, open the example network via right-click
and select [
Help
→
Show Example Network
].
Example 3: Iterative tests in MeVisLab with Screenshots
Example 3: Iterative tests in MeVisLab
Introduction
In this example, you are writing an iterative test. Iterative test functions run a function for every specified input. They return a tuple consisting of the function object called and the inputs iterated over. The iterative test functions are useful if the same function should be applied to different input data. These could be input values, names of input images, etc.
Curves
Curves in MeVisLab
Introduction
Curves can be used in MeVisLab to print the results of a function as two-dimensional mathematical curves into a diagram.
In the given example, only modules available in commercial MeVisLab Professional SDK have been used. The non-commercial MeVisLab Standard SDK provides more modules for curves.
Example 1: Drawing curves
Example 1: Drawing curves
Introduction
In this example, you will draw one or more curves into a diagram and define different styles for the curves.
Steps to do
Develop your network
A curve requires x- and y-coordinates to be printed. You can use the CurveCreator
module as input for these coordinates. The SoDiagram2D
draws the curves into a SoRenderArea
. You can also define the style of the curves by using the StylePalette
module.
Chapter VII: Application Development
MeVisLab Tutorial Chapter VII
Summary
This chapter will summarize all previous chapters and you will develop a whole application in MeVisLab. The complete workflow from developing a prototype to delivering your final application to your customer is explained step-by-step.
Some of the features described here will require a separate license. Building an installable executable requires the MeVisLab ApplicationBuilder license. It extends the MeVisLab SDK so that you can generate an installer of your developed macro module.
Step 1: Prototyping - Develop your Network
Step 1: Prototyping - Develop your Network
Introduction
In this example, we will develop a network which fulfills the requirements mentioned on the overview page. The network will be developed by re-using existing modules and defining basic field values.
Steps to do
2D viewer
The 2D viewer shall visualize the loaded images. In addition to that, it shall be possible to click into the image to trigger a RegionGrowing algorithm to segment parts of the loaded image based on a threshold.
Step 2: Prototyping - Create a macro module
Step 2: Prototyping - Create a macro module
Introduction
In this example, we encapsulate the previously developed prototype network into a macro module for future application development and automated testing.
Steps to do
Make sure to have your *.mlab file from the previous tutorial available.
Package creation
Packages are described in detail in Example 2.1: Package creation. If you already have your own package, you can skip this part and continue creating a macro module.
Step 3: Prototyping - User Interface and Python scripting
Step 3: Prototyping - User Interface and Python scripting
Introduction
In this step, we will develop a user interface and add Python scripting to the macro module you created in Step 2.
Steps to do
Develop the User Interface
A mockup of the user interface you are going to develop is available here. The interface provides the possibility to load files and shows a 2D and a 3D viewer. In addition to that, some settings and information for our final application are available.
Step 4: Review - Automated Tests
Step 4: Review - Automated Tests
Introduction
In the previous chapters you developed a macro module with User Interface and Python scripting. In this step you will see how to implement an automated test to verify and validate the Requirements defined in Overview.
Steps to do
Create a test network using your macro module
Create a new and empty network and save it as *.mlab file. Remember the location.
Step 5: Review - Installer creation
Step 5: Review - Installer creation
Introduction
Your macro module has been tested manually and/or automatically? Then you should create your first installable executable and deliver it to your customer(s) for final evaluation.
Steps to do
Install tools necessary for installer generation
The MeVisLab Project Wizard for Standalone Applications [ File → Run Project Wizard... → Standalone Application ] provides a check for all necessary tools you need to install before generating an installer.
Step 6: Refine - Update Application
Step 6: Refine - Update Application
Introduction
In previous step you developed an application which can be installed on your customers systems for usage. In this step we are going to integrate simple feedback into our executable and re-create the installer.
We want to show you how easy it is to update your application using MeVisLab.
Your customer requests an additional requirement to define the transparency of your 2D overlay in addition to defining the color.
Step 7: Refine - Re-Build Installer
Step 7: Refine - Re-Build Installer
Introduction
In this step you are re-creating your application installer after changing the UI in previous Step 6: Refine - Update Application.
Steps to do
Update the *.mlinstall file
You do not need to use the Project Wizard now, because you already have a valid *.mlinstall file. The location should be in your package, under .\Configuration\Installers\TutorialSummary. Open the file in any text editor and search for the $VERSION 0.5. Change the version to something else, in our case we now have our first major release 1.0.
Extra: Run your application in Browser
Extra: Run your application in Browser
Introduction
This step explains how to run your developed application in a browser. The MeVisLab network remains the same, only some adaptations are necessary for running any macro module in a browser window.
Steps to do
Make sure to have your macro module from previous Step 2 available.
Chapter VIII: ThirdParty components
MeVisLab Tutorial Chapter VIII
Using ThirdParty software integrated into MeVisLab
MeVisLab is equipped with a lot of useful software right out of the box, like the Insight Segmentation and Registration Toolkit (ITK) or the Visualization Toolkit (VTK). This chapter works as a guide on how to use some of the third party components integrated in MeVisLab for your projects via Python scripting.
PythonPip
module.OpenCV
Open Source Computer Vision Library (OpenCV)
Introduction
OpenCV (Open Source Computer Vision Library) is an open source computer vision and machine learning software library.
This chapter provides some examples how to use OpenCV in MeVisLab.
Other resources
You can find a lot of OpenCV examples and tutorials on their website.
Example 1: WebCam access with OpenCV
Example 1: WebCam access with OpenCV
Introduction
In this example, we are using the PythonImage
module and access your WebCam to show the video in a View2D
.
Steps to do
Creating the network to be used for testing
Add the modules to your workspace and connect them as seen below.
The viewer is empty because the image needs to be set via Python scripting.
Example 2: Face Detection with OpenCV
Example 2: Face Detection with OpenCV
Introduction
This example uses the OpenCV WebCam Python script and adds a basic face detection.
Steps to do
Open Example 1
Add the macro module developed in Example 1 to your workspace.
assimp
Asset-Importer-Lib (assimp)
Introduction
Assimp (Asset-Importer-Lib) is a library to load and process geometric scenes from various 3D data formats.
This chapter provides some examples of how 3D formats can be imported into MeVisLab. In general you always need a SoSceneLoader
module. The SoSceneLoader
allows to load meshes as Open Inventor points/lines/triangles/faces using the Open Asset Import Library.
You can also use the SoSceneWriter
module to export your 3D scenes from MeVisLab into any of the output formats listed below.
Example 1: 3D Printing in MeVisLab
Example 1: 3D Printing in MeVisLab
Introduction
This example uses the assimp library to load a 3D file and save the file as *.stl for 3D printing.
Steps to do
Develop your network
Add the modules SoSceneLoader
, SoBackground
and SoExaminerViewer
to your workspace and connect them as seen below.
Open the 3D file
Select the file vtkCow.obj from MeVisLab demo data directory. Open SoExaminerViewer
and inspect the scene. You will see a 3D cow.
PyTorch
PyTorch
Introduction
PyTorch is a machine learning framework based on the Torch library, used for applications such as Computer Vision and Natural Language Processing, originally developed by Meta AI and now part of the Linux Foundation umbrella.
A lot of AI frameworks can be used within MeVisLab. We currently do not provide a preintegrated AI framework though as we try to avoid compatibility issues, and AI frameworks are very fast-moving by nature.
Example 1: Installing PyTorch using the PythonPip module
Example 1: Installing PyTorch using the PythonPip module
Introduction
The module PythonPip
allows you to install additional Python packages to be used in MeVisLab.
The module either allows to install packages into the global MeVisLab installation directory, or into your defined user package. We will use the user package directory, because then the installed packages remain available in your packages even if you uninstall or update MeVisLab. In addition to that, no administrative rights are necessary if you did install MeVisLab for all users.
Example 2: Brain Parcellation using PyTorch
Example 2: Brain Parcellation using PyTorch
Introduction
In this example, you are using a pre-trained PyTorch deep learning model (HighRes3DNet) to perform a full brain parcellation. HighRes3DNet is a 3D residual network presented by Li et al. in On the Compactness, Efficiency, and Representation of 3D Convolutional Networks: Brain Parcellation as a Pretext Task.
Steps to do
Add a LocalImage
module to your workspace and select the file MRI_Head.dcm. For PyTorch it is necessary to resample the data to a defined size. Add a Resample3D
module to the LocalImage
and open the panel. Change Keep Constant to Voxel Size and define Image Size as 176, 217, 160.
Example 3: Segment persons in webcam videos
Example 3: Segment persons in webcam videos
Introduction
This tutorial is based on Example 2: Face Detection with OpenCV. You can re-use some of the scripts already developed in the other tutorial.
Steps to do
Add the macro module developed in the previous example to your workspace.
Open the internal network of the module via middle mouse button and right click on the tab of the workspace showing the internal network. Select Show Enclosing Folder.
Matplotlib
Matplotlib
Matplotlib, introduced by John Hunter in 2002 and initially released in 2003, is a comprehensive data visualization library in Python. It is widely used among the scientific world as it is easy to grasp for beginners and provides high quality plots and images, that are widely customizable.
As MeVisLab supports the integration of Python scripts e. g. for test automation, Matplotlib can be used to visualize any data you might want to see. And as it is directly integrated into MeVisLab, you don’t have to install it (via PythonPip
module) first.
Example 1: Module Setup
Example 1: Module Setup
Introduction
To be able to access the data needed for our grayscale distribution plots, we need a network consisting of a module that imports DICOM data, a module that differentiates between slices and another that ouputs histogram data.
Steps to do
Open up your MeVisLab workspace and add the modules LocalImage
, SubImage
and Histogram
to it.
Connect the output of LocalImage
to the input of SubImage
and the output of SubImage
with the input of Histogram
.
If you feel like using a shortcut, you can also download the base network below and open it in your MeVisLab.
Example 2: 2D Plotting
Example 2: 2D Plotting
Introduction
In this tutorial, we will equip the macro module we created in the previous tutorial with a responsive and interactable panel to plot grayscale distributions of single slices as well as defined sequences of slices in 2D.
Steps to do
Open the module definition folder of your macro module and the related .script file in MATE. Then activate the Preview as shown below:
Example 3: Slice Comparison
Example 3: Slice Comparison
Introduction
We will adapt the previously created macro module to be able to overlay two defined slices to compare their grayscale distributions.
- The module we are adapting has been set up in the Example 1: Module Setup tutorial.
- The panel and two-dimensional plotting functionality has been added in [Example 2: 2D Plotting] (/tutorials/thirdparty/matplotlib/2dplotting).
Steps to do
At first, we will extend the panel: Open your BaseNetwork
macro module within an empty MeVisLab workspace and select the .script file from its related files.
Example 4: 3D Plotting
Example 4: 3D Plotting
Introduction
In this tutorial, we will equip the macro module we created in the Example 1: Module Setup and later on adapted by enabling it to plot grayscale distributions of single slices and sequences in 2D in Example 2: 2D Plotting with a three dimensional plotting functionality.
Steps to do
The fields and commands needed have already been prepared in the second tutorial. We will just have to modify our .py file a little to make them usable. Integrate the following code into your .py file and import numpy.
Tips and Tricks
MeVisLab Tips and Tricks
This chapter shows some features and functionalities which are helpful but do not provide its own tutorial.
- Keyboard Shortcuts
- Using Snippets
- Scripting Assistant
- User Scripts
- Show status of module in- and output
- Module suggestion of module in- and output
Keyboard Shortcuts
This is a collection of useful keyboard shortcuts in MeVisLab, hopefully it grows continuously.
Shortcut | Functionality |
---|---|
Ctrl+1 | Automatically arrange selection of modules / in the current network |
Ctrl+2 | Open most recent network file |
Ctrl+3 | Run most recent test case (extremely useful for developers) | Ctrl+A then Ctrl+1 | Layout network | Ctrl+A then Tab | Layout .script file (in MATE) | Ctrl+D | Duplicate currently selected module (including all field values) | Ctrl+Left Mouse or Middle Mouse Button | Show Internal Network | Space | Show hidden outputs of the currently selected module | Ctrl+Alt+T | Start test center | Ctrl+K | Restart MeVisLab | Ctrl+R | Run script file with the same name of your network file if available in the same directory. |
Using Snippets
Sometimes you have to create the same network over and over again – for example, to quickly preview DICOM files. Generally, you will at least add one module to load and another module to display your images. Sometimes you may also want to view the DICOM header data. A network you possibly generate whenever opening DICOM files will be the following: