Medical Imaging Interaction Toolkit  2018.4.99-701c8286
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 
65  itkFactorylessNewMacro(Self);
66 
67  itkCloneMacro(Self);
68 
70  ~GrabCutOpenCVImageFilter() override;
71 
81  bool OnFilterImage( cv::Mat& image ) override;
82 
87  void SetModelPoints(ModelPointsList foregroundPoints);
88 
94  void SetModelPoints(ModelPointsList foregroundPoints, ModelPointsList backgroundPoints);
95 
99  void SetModelPoints(cv::Mat foregroundMask);
100 
106  void SetModelPoints(cv::Mat foregroundMask, cv::Mat backgroundMask);
107 
120  void SetModelPointsDilationSize(int modelPointsDilationSize);
121 
133  void SetUseOnlyRegionAroundModelPoints(unsigned int additionalBorder);
134 
141  void SetUseFullImage();
142 
149  cv::Rect GetRegionAroundModelPoints();
150 
162  int GetResultImageId();
163 
172  cv::Mat GetResultMask();
173 
188  std::vector<ModelPointsList> GetResultContours();
189 
207  ModelPointsList GetResultContourWithPixel(itk::Index<2> pixelIndex);
208 
209 protected:
214  cv::Mat GetMaskFromPointSets();
215 
221  cv::Rect GetBoundingRectFromMask(cv::Mat mask);
222 
229  cv::Mat RunSegmentation(cv::Mat input, cv::Mat mask);
230 
234  ModelPointsList ConvertMaskToModelPointsList(cv::Mat mask);
235 
237 
239  unsigned int m_AdditionalWidth;
240  cv::Rect m_BoundingBox;
241 
242  ModelPointsList m_ForegroundPoints;
243  ModelPointsList m_BackgroundPoints;
244 
245  cv::Mat m_InputImage;
246  cv::Mat m_GrabCutMask;
247  cv::Mat m_ResultMask;
248 
250 
253 
256 
257 private:
266  static ITK_THREAD_RETURN_TYPE SegmentationWorker(void* pInfoStruct);
267 
268  int m_ThreadId;
269 
271  bool m_StopThread;
272 
275 
278 
281 
283  itk::SmartPointer<itk::FastMutexLock> m_PointSetsMutex;
284 };
285 } // namespace mitk
286 
287 #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
Interface for image filters on OpenCV images.
int m_InputImageId
id of the image currently set as m_InputImage