Python

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.

Example 2.5.1: The module RunPythonScript

Example 2.5.1: The module RunPythonScript      This example is also available on YouTube. 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      This example is also available on YouTube. 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 ].

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.

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 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.

Example 1: Writing a simple test case in MeVisLab

Example 1: Writing a simple test case in MeVisLab      This example is also available on YouTube. 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 3: Iterative tests in MeVisLab with Screenshots

Example 3: Iterative tests in MeVisLab      This example is also available on YouTube. 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.

Step 3: Prototyping - User Interface and Python scripting

Step 3: Prototyping - User Interface and Python scripting      This example is also available on YouTube. 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.

Step 4: Review - Automated Tests

Step 4: Review - Automated Tests      This example is also available on YouTube. 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 *.

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. Example Network The viewer is empty because the image needs to be set via Python scripting. Info:  More information about the PythonImage module can be found here Create a macro module Now you need to create a macro module from your network.

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. Info:  The Python code used in this example has been taken from Towards Data Science. Steps to do Open Example 1 Add the macro module developed in Example 1 to your workspace. Download trained classifier XML file Initially you need to download the trained classifier XML file. It is available in the OpenCV GitHub repository.

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. Warning:  You should not use the general Python pip command from a locally installed Python, because MeVisLab will not know these packages and they cannot be used in MeVisLab directly. The module either allows to install packages into the global MeVisLab installation directory, or into your defined user package.

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.

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. WebCamTest module Open the internal network of the module via middle mouse button and right click on the tab of the workspace showing the internal network.