Medical Imaging Interaction Toolkit  2016.11.0
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,
6 Division of Medical and Biological Informatics.
7 All rights reserved.
8 
9 This software is distributed WITHOUT ANY WARRANTY; without
10 even the implied warranty of MERCHANTABILITY or FITNESS FOR
11 A PARTICULAR PURPOSE.
12 
13 See LICENSE.txt or http://www.mitk.org for details.
14 
15 ===================================================================*/
16 
17 #ifndef MITKGRABCUTOPENCVIMAGEFILTER_H
18 #define MITKGRABCUTOPENCVIMAGEFILTER_H
19 
20 // mitk headers
22 #include "mitkVector.h"
23 
24 // itk headers
25 #include "itkObjectFactory.h"
26 #include "itkMutexLock.h"
27 
28 // opencv headers
29 #include "cv.h"
30 
31 namespace itk {
32 template<unsigned int T> class Index;
33 template<class T> class SmartPointer;
34 class MultiThreader;
35 class ConditionVariable;
36 class FastMutexLock;
37 }
38 
39 namespace mitk {
40 class PointSet;
41 
61 class MITKOPENCVVIDEOSUPPORT_EXPORT GrabCutOpenCVImageFilter : public AbstractOpenCVImageFilter
62 {
63 public:
65  typedef std::vector<itk::Index<2> > ModelPointsList;
66 
68  itkFactorylessNewMacro(Self)
69  itkCloneMacro(Self)
70 
72  virtual ~GrabCutOpenCVImageFilter();
73 
83  bool OnFilterImage( cv::Mat& image ) override;
84 
89  void SetModelPoints(ModelPointsList foregroundPoints);
90 
96  void SetModelPoints(ModelPointsList foregroundPoints, ModelPointsList backgroundPoints);
97 
101  void SetModelPoints(cv::Mat foregroundMask);
102 
108  void SetModelPoints(cv::Mat foregroundMask, cv::Mat backgroundMask);
109 
122  void SetModelPointsDilationSize(int modelPointsDilationSize);
123 
135  void SetUseOnlyRegionAroundModelPoints(unsigned int additionalBorder);
136 
143  void SetUseFullImage();
144 
151  cv::Rect GetRegionAroundModelPoints();
152 
164  int GetResultImageId();
165 
174  cv::Mat GetResultMask();
175 
190  std::vector<ModelPointsList> GetResultContours();
191 
209  ModelPointsList GetResultContourWithPixel(itk::Index<2> pixelIndex);
210 
211 protected:
216  cv::Mat GetMaskFromPointSets();
217 
223  cv::Rect GetBoundingRectFromMask(cv::Mat mask);
224 
231  cv::Mat RunSegmentation(cv::Mat input, cv::Mat mask);
232 
236  ModelPointsList ConvertMaskToModelPointsList(cv::Mat mask);
237 
238  int m_ModelPointsDilationSize;
239 
240  bool m_UseOnlyRegionAroundModelPoints;
241  unsigned int m_AdditionalWidth;
242  cv::Rect m_BoundingBox;
243 
244  ModelPointsList m_ForegroundPoints;
245  ModelPointsList m_BackgroundPoints;
246 
247  cv::Mat m_InputImage;
248  cv::Mat m_GrabCutMask;
249  cv::Mat m_ResultMask;
250 
251  unsigned int m_CurrentProcessImageNum;
252 
254  int m_InputImageId;
255 
257  int m_ResultImageId;
258 
259 private:
268  static ITK_THREAD_RETURN_TYPE SegmentationWorker(void* pInfoStruct);
269 
270  int m_ThreadId;
271 
273  bool m_StopThread;
274 
275  itk::SmartPointer<itk::MultiThreader> m_MultiThreader;
276  itk::SmartPointer<itk::ConditionVariable> m_WorkerBarrier;
277 
279  itk::SmartPointer<itk::FastMutexLock> m_ImageMutex;
280 
282  itk::SmartPointer<itk::FastMutexLock> m_ResultMutex;
283 
285  itk::SmartPointer<itk::FastMutexLock> m_PointSetsMutex;
286 };
287 } // namespace mitk
288 
289 #endif // MITKGRABCUTOPENCVIMAGEFILTER_H
std::vector< itk::Index< 2 > > ModelPointsList
List holding image indices of the model points.
STL namespace.
DataCollection - Class to facilitate loading/accessing structured data.
Makes the OpenCV GrabCut filter available as OpenCVImageFilter.
#define mitkClassMacro(className, SuperClassName)
Definition: mitkCommon.h:44
Interface for image filters on OpenCV images.