Medical Imaging Interaction Toolkit  2018.04.99-46eee069
Medical Imaging Interaction Toolkit
MITK Tutorial - Step 9: A plug-in

MITK uses a very modular concept to maximize reusability and portability. A MITK application based on the BlueBerry application framework (for example the MITK Workbench) consists of several bundles (or plug-ins). A bundle can contain resources and program logic. It can also contribute so-called Views to the main application, which provide a specific user interface for controlling the bundles functions.

The creation of a MITK plug-in is considerably facilitated by using the MITK PluginGenerator as described in How to create a new MITK Plugin if you want to add a new view to an existing plugin see Adding a new view to a MITK Plugin.

The mentioned tool was used to create a plug-in called org.mitk.example.gui.regiongrowing. Let's first take a look at which files the PluginGenerator has created:

  modules.dox......................... Doxygen file for documenting your plug-in

  icon.png............................ The icon of your plug-in. GIMP or other programs (including your text editor)
                                       can be used to change this

  QmitkRegionGrowingView.cpp.......... The most important file, implementing behaviour
  QmitkRegionGrowingView.h............ Header file of the functionality
  QmitkRegionGrowingViewControls.ui... XML file of the Qt Designer, describes buttons, combo boxes, etc. of your controls

CMakeLists.txt \...................... Build system related files for CMake
files.cmake    /
manifest_headers.cmake................ Information about your plug-in
plugin.xml ........................... BlueBerry integration

If you are not familiar with Qt development, please look into this Qt company page describing .ui files

The C++ files implement a subclass of QmitkAbstractView. In this special case of QmitkRegionGrowing, we added the option to set some seed points and run a region grower. If you are interested in the concrete changes necessary to turn a freshly generated QmitkRegionGrowing into an integrated one:

The plug-in will be build as part of MITK Workbench. Do use it start MITK Workbench an select the region growing view in the view menu.

To add a mitk::PointSet for the seed points: QmitkRegionGrowingView.h

Add includes and forward declarations:

#include "mitkPointSet.h"
#include <itkImage.h>

Add the point set and a pointer to a QmitkPointListWidget as a private member:

QmitkPointListWidget *m_PointListWidget;



// create a QmitkPointListWidget and add it to the widget created from .ui file
m_PointListWidget = new QmitkPointListWidget();
m_Controls.verticalLayout->addWidget(m_PointListWidget, 1);
// retrieve a possibly existing IRenderWindowPart
if (mitk::IRenderWindowPart *renderWindowPart = GetRenderWindowPart())
// let the point set widget know about the render window part (crosshair updates)
// create a new DataNode containing a PointSet with some interaction
m_PointSet = mitk::PointSet::New();
pointSetNode->SetName("seed points for region growing");
pointSetNode->SetProperty("helper object", mitk::BoolProperty::New(true));
pointSetNode->SetProperty("layer", mitk::IntProperty::New(1024));
// add the pointset to the data storage (for rendering and access by other modules)
// tell the GUI widget about the point set

To use the ITK region grower:


Add the private method:

template <typename TPixel, unsigned int VImageDimension>
void ItkImageProcessing(itk::Image<TPixel, VImageDimension> *itkImage, mitk::BaseGeometry *imageGeometry);


Add includes:

// Qmitk
#include "mitkImageCast.h"
#include "mitkProperties.h"
// ITK
#include <itkConnectedThresholdImageFilter.h>


// So we have an image. Let's see if the user has set some seed points already
if (m_PointSet->GetSize() == 0)
// no points there. Not good for region growing
"Region growing functionality",
"Please set some seed points inside the image first.\n"
"(hold Shift key and click left mouse button inside the image.)");
// actually perform region growing. Here we have both an image and some seed points
image, ItkImageProcessing, image->GetGeometry()) // some magic to call the correctly templated function

And add the new method:

template <typename TPixel, unsigned int VImageDimension>
void QmitkRegionGrowingView::ItkImageProcessing(itk::Image<TPixel, VImageDimension> *itkImage,
mitk::BaseGeometry *imageGeometry)
typedef itk::Image<TPixel, VImageDimension> InputImageType;
typedef typename InputImageType::IndexType IndexType;
// instantiate an ITK region growing filter, set its parameters
typedef itk::ConnectedThresholdImageFilter<InputImageType, InputImageType> RegionGrowingFilterType;
typename RegionGrowingFilterType::Pointer regionGrower = RegionGrowingFilterType::New();
regionGrower->SetInput(itkImage); // don't forget this
// determine a thresholding interval
IndexType seedIndex;
TPixel min(std::numeric_limits<TPixel>::max());
TPixel max(std::numeric_limits<TPixel>::min());
mitk::PointSet::PointsContainer *points = m_PointSet->GetPointSet()->GetPoints();
for (mitk::PointSet::PointsConstIterator pointsIterator = points->Begin(); pointsIterator != points->End();
// first test if this point is inside the image at all
if (!imageGeometry->IsInside(pointsIterator.Value()))
// convert world coordinates to image indices
imageGeometry->WorldToIndex(pointsIterator.Value(), seedIndex);
// get the pixel value at this point
TPixel currentPixelValue = itkImage->GetPixel(seedIndex);
// adjust minimum and maximum values
if (currentPixelValue > max)
max = currentPixelValue;
if (currentPixelValue < min)
min = currentPixelValue;
MITK_INFO << "Values between " << min << " and " << max;
min -= 30;
max += 30;
// set thresholds and execute filter
mitk::Image::Pointer resultImage;
mitk::CastToMitkImage(regionGrower->GetOutput(), resultImage);
// set some properties
newNode->SetProperty("binary", mitk::BoolProperty::New(true));
newNode->SetProperty("name", mitk::StringProperty::New("dumb segmentation"));
newNode->SetProperty("color", mitk::ColorProperty::New(1.0, 0.0, 0.0));
newNode->SetProperty("volumerendering", mitk::BoolProperty::New(true));
newNode->SetProperty("layer", mitk::IntProperty::New(1));
newNode->SetProperty("opacity", mitk::FloatProperty::New(0.5));
// add result to data tree

Have fun using MITK!

If you meet any difficulties during your first steps, don't hesitate to ask on the MITK mailing list! People there are kind and will try to help you.

[Previous step] [Next Step] [Main tutorial page]