4.2. Implementing the Contour Filter

We want to implement a contour filter that is composed of the following image processing pipeline:

  1. Take an input image a.

  2. Smooth the input image with an average kernel: Average[image a] -> image b.

  3. Dilate the smoothed image by means of a morphological kernel operation: Dilate[image b] -> image c.

  4. Subtract the smoothed image from the dilated and smoothed image: Subtract[image c,image b] -> image d.

  5. Show the filter output image d.

For this processing pipeline we need the following basic image operators:

Proceed as follows:

  1. Add the modules Convolution, Morphology, and Arithmetic2 to the network.

    Alternatively you could find and add the modules to the network via the Modules menu:

    1. via ModulesFiltersKernelConvolution,

    2. via ModulesFiltersMorphologyMorphology and

    3. via ModulesAnalysisArithmeticBinaryArithmetic2.

    The image we use as input has to be processed first via the Convolution module. After that, the resulting convoluted image will be processed and also output directly to the Arithmetic2 module where the two images will be subtracted.

    For the subtraction, the following information is offered in the help of Arithmetic2: “The input image 1 decreased by input image 2 is passed to the output.” Therefore, it is important to connect the images in the correct order, otherwise the result will look rather strange.

  2. Open the panels of Convolution, Morphology and Arithmetic2 by double-clicking the modules. Then adjust/check the default values of the following parameters:

    1. Module Convolution: Keep the default kernel type "3x3 Average Kernel" for predefKernel.

    2. Module Morphology:

      1. In the field Filter Mode, keep the default value "Dilation".

      2. For the Kernel Geometry, use a kernel of the size 3x3x1.

    3. Module Arithmetic2: In the field Function, change the default value "Add" to the value "Subtract".

    Figure 4.3. Adjust Filter Parameters

    Adjust Filter Parameters

    [Tip]Tip

    You can view and edit module field values also in the Module Inspector View. On the Fields tab, all fields of the currently selected module are listed by names and values.

    [Note]Note

    Field names (in the module) and field labels (in the interface of the module panel) do not have to be the same. To find the field name, right-click the field label on the panel; the field name is listed as first entry of the context menu.

  3. To view the results of every step in the processing pipeline, use the Output Inspector, which can be opened via the menu bar, ViewViews. Click each connector to follow the image processing.

    Figure 4.4. Constructing the Filter Pipeline — Convolution Output

    Constructing the Filter Pipeline — Convolution Output

    Figure 4.5. Constructing the Filter Pipeline — Morphology Output

    Constructing the Filter Pipeline — Morphology Output

    Figure 4.6. Constructing the Filter Pipeline — Arithmetic2 Output

    Constructing the Filter Pipeline — Arithmetic2 Output

  4. To distinguish the image processing pipeline, you can create a group for it. For that:

    1. Select the three modules, for example by dragging a selection rectangle around them, or by single-selecting the modules while pressing SHIFT.

    2. Right-click the selection to open the context menu and select Add to New Group.

    3. Enter a name for the new group, for example “Filter”.

    Figure 4.7. Creating a New Group

    Creating a New Group

    The new group is created and displayed as a green rectangle. The group allows for quick interaction; for example, a double-click on its title bar zooms in and centers the group; a right-click on the title bar opens a menu for editing and deleting the group. You can also change the default color in the Preferences. For further information on groups, please refer to the MeVisLab Reference Manual, chapter Using Groups.

  5. For the output, add another View2D module, either via the quick search or by selecting the existing View2D module in the network and duplicating it (via EditDuplicate or by pressing the keyboard shortcuts given there).

    Figure 4.8. Resulting Contour Filter Network

    Resulting Contour Filter Network

    [Tip]Tip

    The filter can be tuned via some parameters given in the Convolution and Morphology modules. Changing the convolution kernel size (field predefKernel of the Convolution module) and/or the dilation kernel (fields kernelX, kernelY, kernelZ of the Morphology module) will enhance contours at different scales.

    In a final step, we will synchronize the Viewers of the two View2D modules by establishing parameter connections between them.