Medical Imaging Interaction Toolkit  2018.4.99-12ad79a3
Medical Imaging Interaction Toolkit
mitkGrabCutOpenCVImageFilter.h
Go to the documentation of this file.
1 /*============================================================================
2 
3 The Medical Imaging Interaction Toolkit (MITK)
4 
5 Copyright (c) German Cancer Research Center (DKFZ)
6 All rights reserved.
7 
8 Use of this source code is governed by a 3-clause BSD license that can be
9 found in the LICENSE file.
10 
11 ============================================================================*/
12 
13 #ifndef MITKGRABCUTOPENCVIMAGEFILTER_H
14 #define MITKGRABCUTOPENCVIMAGEFILTER_H
15 
16 // mitk headers
18 #include "mitkVector.h"
19 
20 // itk headers
21 #include "itkObjectFactory.h"
22 #include "itkMutexLock.h"
23 
24 // opencv headers
25 #include <opencv2/core.hpp>
26 
27 namespace itk {
28 template<unsigned int T> class Index;
29 template<class T> class SmartPointer;
30 class MultiThreader;
31 class ConditionVariable;
32 class FastMutexLock;
33 }
34 
35 namespace mitk {
36 class PointSet;
37 
58 {
59 public:
61  typedef std::vector<itk::Index<2> > ModelPointsList;
62 
64  itkFactorylessNewMacro(Self)
65  itkCloneMacro(Self)
66 
68  ~GrabCutOpenCVImageFilter() override;
69 
79  bool OnFilterImage( cv::Mat& image ) override;
80 
85  void SetModelPoints(ModelPointsList foregroundPoints);
86 
92  void SetModelPoints(ModelPointsList foregroundPoints, ModelPointsList backgroundPoints);
93 
97  void SetModelPoints(cv::Mat foregroundMask);
98 
104  void SetModelPoints(cv::Mat foregroundMask, cv::Mat backgroundMask);
105 
118  void SetModelPointsDilationSize(int modelPointsDilationSize);
119 
131  void SetUseOnlyRegionAroundModelPoints(unsigned int additionalBorder);
132 
139  void SetUseFullImage();
140 
147  cv::Rect GetRegionAroundModelPoints();
148 
160  int GetResultImageId();
161 
170  cv::Mat GetResultMask();
171 
186  std::vector<ModelPointsList> GetResultContours();
187 
205  ModelPointsList GetResultContourWithPixel(itk::Index<2> pixelIndex);
206 
207 protected:
212  cv::Mat GetMaskFromPointSets();
213 
219  cv::Rect GetBoundingRectFromMask(cv::Mat mask);
220 
227  cv::Mat RunSegmentation(cv::Mat input, cv::Mat mask);
228 
232  ModelPointsList ConvertMaskToModelPointsList(cv::Mat mask);
233 
235 
237  unsigned int m_AdditionalWidth;
238  cv::Rect m_BoundingBox;
239 
240  ModelPointsList m_ForegroundPoints;
241  ModelPointsList m_BackgroundPoints;
242 
243  cv::Mat m_InputImage;
244  cv::Mat m_GrabCutMask;
245  cv::Mat m_ResultMask;
246 
248 
251 
254 
255 private:
264  static ITK_THREAD_RETURN_TYPE SegmentationWorker(void* pInfoStruct);
265 
266  int m_ThreadId;
267 
269  bool m_StopThread;
270 
273 
276 
279 
281  itk::SmartPointer<itk::FastMutexLock> m_PointSetsMutex;
282 };
283 } // namespace mitk
284 
285 #endif // MITKGRABCUTOPENCVIMAGEFILTER_H
std::vector< itk::Index< 2 > > ModelPointsList
List holding image indices of the model points.
int m_ResultImageId
id of the image which segmentation result is currently present in m_ResultMask
DataCollection - Class to facilitate loading/accessing structured data.
#define MITKOPENCVVIDEOSUPPORT_EXPORT
Makes the OpenCV GrabCut filter available as OpenCVImageFilter.
#define mitkClassMacro(className, SuperClassName)
Definition: mitkCommon.h:40
mitk::Image::Pointer image
Interface for image filters on OpenCV images.
mitk::Image::Pointer mask
int m_InputImageId
id of the image currently set as m_InputImage