Makes the OpenCV GrabCut filter available as OpenCVImageFilter.
More...
#include <mitkGrabCutOpenCVImageFilter.h>
Makes the OpenCV GrabCut filter available as OpenCVImageFilter.
Image filtering is done asynchronly by using a worker thread as GrabCut segmentation can take up to some seconds. Calling the mitk::GrabCutOpenCVImageFilter::OnFilterImage() method sets just the input image and wakes up the worker thread. It is not guaranteed that every image gets segmented. If multiple new images where set before a segmentation was finished, only the last new image gets segmented afterwards.
At least foreground model points have to be set by mitk::GrabCutOpenCVImageFilter::SetModelPoints() before a segmentation can be performed. The worder thread will not be waken up before any model points were set.
When a new segmentation is ready, mitk::GrabCutOpenCVImageFilter::GetCurrentImageId() returns a new image id. The segmentation can be got then by calling mitk::GrabCutOpenCVImageFilter::GetResultMask(), mitk::GrabCutOpenCVImageFilter::GetResultContours() or mitk::GrabCutOpenCVImageFilter::GetResultContourWithPixel().
Definition at line 61 of file mitkGrabCutOpenCVImageFilter.h.
◆ ModelPointsList
◆ GrabCutOpenCVImageFilter()
mitk::GrabCutOpenCVImageFilter::GrabCutOpenCVImageFilter |
( |
| ) |
|
◆ ~GrabCutOpenCVImageFilter()
mitk::GrabCutOpenCVImageFilter::~GrabCutOpenCVImageFilter |
( |
| ) |
|
|
override |
◆ Clone()
Pointer mitk::GrabCutOpenCVImageFilter::Clone |
( |
| ) |
const |
◆ ConvertMaskToModelPointsList()
ModelPointsList mitk::GrabCutOpenCVImageFilter::ConvertMaskToModelPointsList |
( |
cv::Mat |
mask | ) |
|
|
protected |
Creates a list of points from every non-zero pixel of the given mask.
◆ GetBoundingRectFromMask()
cv::Rect mitk::GrabCutOpenCVImageFilter::GetBoundingRectFromMask |
( |
cv::Mat |
mask | ) |
|
|
protected |
◆ GetMaskFromPointSets()
cv::Mat mitk::GrabCutOpenCVImageFilter::GetMaskFromPointSets |
( |
| ) |
|
|
protected |
◆ GetRegionAroundModelPoints()
cv::Rect mitk::GrabCutOpenCVImageFilter::GetRegionAroundModelPoints |
( |
| ) |
|
◆ GetResultContours()
std::vector<ModelPointsList> mitk::GrabCutOpenCVImageFilter::GetResultContours |
( |
| ) |
|
Getter for the contours of the current segmentation.
A segmentation can consist of multiple regions therefore a list of contours is returned. If one needs only one specific region he can call mitk::GrabCutOpenCVImageFilter::GetResultContourWithPixel().
This result of this method is not necessarily consistent with the result of mitk::GrabCutOpenCVImageFilter::GetResultContours() if they are called afterwards. The segmentation may have changed in the meantime. One should decide if he needs a mask or a contour or convert one into the other on his own.
- Returns
- List containing lists of pixel indices for every contour.
◆ GetResultContourWithPixel()
Getter for one specific contour of the current segmentation.
Can be used if only one (of possible multiple contours) is needed. A pixel index must be given to select from the contours. This could be one of the foreground model pixels for example. If other criteria are needed to distinguish the contours mitk::GrabCutOpenCVImageFilter::GetResultContours() can be used instead and therefore contour selection can be done by hand then.
This result of this method is not necessarily consistent with the result of mitk::GrabCutOpenCVImageFilter::GetResultContours() if they are called afterwards. The segmentation may have changed in the meantime. One should decide if he needs a mask or a contour or convert one into the other on his own.
- Parameters
-
pixelIndex | index of a pixel which lies inside the contour |
- Returns
- list of pixel indices for the selected contour
◆ GetResultImageId()
int mitk::GrabCutOpenCVImageFilter::GetResultImageId |
( |
| ) |
|
Getter for an ascending id of the current result image. The id will be increased for every segmentation that is produced by the worker thread. It can be used to determine if a new segmentation was produced since the last time a segmentation was got from this filter.
int lastResultImageId = grabCutFilter->GetResultImageId(); // do something if ( lastResultImageId != grabCutFilter->GetResultImageId() ) // get new segmentation
◆ GetResultMask()
cv::Mat mitk::GrabCutOpenCVImageFilter::GetResultMask |
( |
| ) |
|
Getter for the result mask of the current segmentation. The result of this method is not necessarily consistent with the result of mitk::GrabCutOpenCVImageFilter::GetResultContours() if they are called afterwards. The segmentation may have changed in the meantime. One should decide if he needs a mask or a contour or convert one into the other on his own.
- Returns
- image of the size of the input image where all pixels segmented as foreground are non-zero
◆ mitkClassMacro()
◆ New()
static Pointer mitk::GrabCutOpenCVImageFilter::New |
( |
| ) |
|
|
static |
◆ OnFilterImage()
bool mitk::GrabCutOpenCVImageFilter::OnFilterImage |
( |
cv::Mat & |
image | ) |
|
|
overridevirtual |
Implementation of the virtual image filtering method. The input image is copied to a member attribute, but the actual filtering is not done in this method. Instead a worker thread is waken up every time this method is called, if foreground model points were set before.
- Parameters
-
image | OpenCV image to be segmentated |
- Returns
- false if an empty image was set, true otherwise
Implements mitk::AbstractOpenCVImageFilter.
◆ RunSegmentation()
cv::Mat mitk::GrabCutOpenCVImageFilter::RunSegmentation |
( |
cv::Mat |
input, |
|
|
cv::Mat |
mask |
|
) |
| |
|
protected |
Performs a GrabCut segmentation of the given input image.
- Parameters
-
input | image on which the segmentation will be performed |
mask | foreground and background pixels used as basis for segmentation |
- Returns
- mask with every pixel of the segmented foreground object set non-zero
◆ SetModelPoints() [1/4]
void mitk::GrabCutOpenCVImageFilter::SetModelPoints |
( |
cv::Mat |
foregroundMask | ) |
|
Sets a mask where every non-zero pixel is treated as a foreground model pixel.
◆ SetModelPoints() [2/4]
void mitk::GrabCutOpenCVImageFilter::SetModelPoints |
( |
cv::Mat |
foregroundMask, |
|
|
cv::Mat |
backgroundMask |
|
) |
| |
Sets masks specifying foreground and background points.
- Parameters
-
foregroundMask | every non-zero pixel is treated as a foreground model pixel |
backgroundMask | every non-zero pixel is treated as a background model pixel |
◆ SetModelPoints() [3/4]
void mitk::GrabCutOpenCVImageFilter::SetModelPoints |
( |
ModelPointsList |
foregroundPoints | ) |
|
Sets a list of image indices as foreground model points.
- Parameters
-
foregroundPoints | List of image indices which definitely belong to the foreground. |
◆ SetModelPoints() [4/4]
Sets a list of image indices as foreground and another list as background model points.
- Parameters
-
foregroundPoints | List of image indices which definitely belong to the foreground. |
backgroundPoints | List of image indices which definitely belong to the background. |
◆ SetModelPointsDilationSize()
void mitk::GrabCutOpenCVImageFilter::SetModelPointsDilationSize |
( |
int |
modelPointsDilationSize | ) |
|
Set a size of which each model point is dilated before image filtering. The more color information of the foreground object the GrabCut filter gets the better the result will be. Therefore the foreground pixels can be dilated before filtering. The caller is responsible for setting a dilation size so that no foreground model pixels will be indeed part of the background after dilation.
Dilation is done to the background model pixles as well, if there are any set for the filter.
- Parameters
-
modelPointsDilationSize | how many pixels are added in every direction, 0 sets back to no dilation |
◆ SetUseFullImage()
void mitk::GrabCutOpenCVImageFilter::SetUseFullImage |
( |
| ) |
|
◆ SetUseOnlyRegionAroundModelPoints()
void mitk::GrabCutOpenCVImageFilter::SetUseOnlyRegionAroundModelPoints |
( |
unsigned int |
additionalBorder | ) |
|
Use only the region around the foreground model points for the segmentation.
This is mainly for reasons of segmentation speed and has the drawback that the foreground model points (plus the given additional border) have to cover the whole foreground object.
The segmentation filter can be set back to using the whole image by calling mitk::GrabCutOpenCVImageFilter::SetUseFullImage().
- Parameters
-
additionalBorder | size of the border around the foreground points which will be used for segmentation, too |
◆ m_AdditionalWidth
unsigned int mitk::GrabCutOpenCVImageFilter::m_AdditionalWidth |
|
protected |
◆ m_BackgroundPoints
◆ m_BoundingBox
cv::Rect mitk::GrabCutOpenCVImageFilter::m_BoundingBox |
|
protected |
◆ m_CurrentProcessImageNum
unsigned int mitk::GrabCutOpenCVImageFilter::m_CurrentProcessImageNum |
|
protected |
◆ m_ForegroundPoints
◆ m_GrabCutMask
cv::Mat mitk::GrabCutOpenCVImageFilter::m_GrabCutMask |
|
protected |
◆ m_InputImage
cv::Mat mitk::GrabCutOpenCVImageFilter::m_InputImage |
|
protected |
◆ m_InputImageId
int mitk::GrabCutOpenCVImageFilter::m_InputImageId |
|
protected |
◆ m_ModelPointsDilationSize
int mitk::GrabCutOpenCVImageFilter::m_ModelPointsDilationSize |
|
protected |
◆ m_ResultImageId
int mitk::GrabCutOpenCVImageFilter::m_ResultImageId |
|
protected |
◆ m_ResultMask
cv::Mat mitk::GrabCutOpenCVImageFilter::m_ResultMask |
|
protected |
◆ m_UseOnlyRegionAroundModelPoints
bool mitk::GrabCutOpenCVImageFilter::m_UseOnlyRegionAroundModelPoints |
|
protected |
The documentation for this class was generated from the following file: