Medical Imaging Interaction Toolkit  2022.10.99-efe2ad43
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 <itkThreadSupport.h>
23 
24 // opencv headers
25 #include <opencv2/core.hpp>
26 
27 #include <condition_variable>
28 #include <mutex>
29 #include <thread>
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 
62 {
63 public:
65  typedef std::vector<itk::Index<2> > ModelPointsList;
66 
68 
69  itkFactorylessNewMacro(Self);
70 
71  itkCloneMacro(Self);
72 
74  ~GrabCutOpenCVImageFilter() override;
75 
85  bool OnFilterImage( cv::Mat& image ) override;
86 
91  void SetModelPoints(ModelPointsList foregroundPoints);
92 
98  void SetModelPoints(ModelPointsList foregroundPoints, ModelPointsList backgroundPoints);
99 
103  void SetModelPoints(cv::Mat foregroundMask);
104 
110  void SetModelPoints(cv::Mat foregroundMask, cv::Mat backgroundMask);
111 
124  void SetModelPointsDilationSize(int modelPointsDilationSize);
125 
137  void SetUseOnlyRegionAroundModelPoints(unsigned int additionalBorder);
138 
145  void SetUseFullImage();
146 
153  cv::Rect GetRegionAroundModelPoints();
154 
166  int GetResultImageId();
167 
176  cv::Mat GetResultMask();
177 
192  std::vector<ModelPointsList> GetResultContours();
193 
211  ModelPointsList GetResultContourWithPixel(itk::Index<2> pixelIndex);
212 
213 protected:
218  cv::Mat GetMaskFromPointSets();
219 
225  cv::Rect GetBoundingRectFromMask(cv::Mat mask);
226 
233  cv::Mat RunSegmentation(cv::Mat input, cv::Mat mask);
234 
238  ModelPointsList ConvertMaskToModelPointsList(cv::Mat mask);
239 
241 
243  unsigned int m_AdditionalWidth;
244  cv::Rect m_BoundingBox;
245 
248 
249  cv::Mat m_InputImage;
250  cv::Mat m_GrabCutMask;
251  cv::Mat m_ResultMask;
252 
254 
257 
260 
261 private:
269  void SegmentationWorker();
270 
271  std::thread m_Thread;
272 
274  bool m_StopThread;
275 
276  std::condition_variable m_WorkerBarrier;
277 
279  std::mutex m_ImageMutex;
280 
282  std::mutex m_ResultMutex;
283 
285  std::mutex m_PointSetsMutex;
286 };
287 } // namespace mitk
288 
289 #endif // MITKGRABCUTOPENCVIMAGEFILTER_H
mitk::AbstractOpenCVImageFilter
Interface for image filters on OpenCV images.
Definition: mitkAbstractOpenCVImageFilter.h:36
mitk::GrabCutOpenCVImageFilter
Makes the OpenCV GrabCut filter available as OpenCVImageFilter.
Definition: mitkGrabCutOpenCVImageFilter.h:61
mitk::GrabCutOpenCVImageFilter::m_ResultMask
cv::Mat m_ResultMask
Definition: mitkGrabCutOpenCVImageFilter.h:251
itk::SmartPointer
Definition: mitkIFileReader.h:30
mitk::GrabCutOpenCVImageFilter::m_GrabCutMask
cv::Mat m_GrabCutMask
Definition: mitkGrabCutOpenCVImageFilter.h:250
mitk
DataCollection - Class to facilitate loading/accessing structured data.
Definition: RenderingTests.dox:1
mitk::GrabCutOpenCVImageFilter::ModelPointsList
std::vector< itk::Index< 2 > > ModelPointsList
List holding image indices of the model points.
Definition: mitkGrabCutOpenCVImageFilter.h:65
mitk::GrabCutOpenCVImageFilter::m_ForegroundPoints
ModelPointsList m_ForegroundPoints
Definition: mitkGrabCutOpenCVImageFilter.h:246
mitk::GrabCutOpenCVImageFilter::m_BackgroundPoints
ModelPointsList m_BackgroundPoints
Definition: mitkGrabCutOpenCVImageFilter.h:247
mitk::GrabCutOpenCVImageFilter::m_BoundingBox
cv::Rect m_BoundingBox
Definition: mitkGrabCutOpenCVImageFilter.h:244
mitk::GrabCutOpenCVImageFilter::m_CurrentProcessImageNum
unsigned int m_CurrentProcessImageNum
Definition: mitkGrabCutOpenCVImageFilter.h:253
itk
SET FUNCTIONS.
Definition: itkIntelligentBinaryClosingFilter.h:30
mitk::GrabCutOpenCVImageFilter::m_UseOnlyRegionAroundModelPoints
bool m_UseOnlyRegionAroundModelPoints
Definition: mitkGrabCutOpenCVImageFilter.h:242
mitkClassMacro
#define mitkClassMacro(className, SuperClassName)
Definition: mitkCommon.h:36
mitk::GrabCutOpenCVImageFilter::m_AdditionalWidth
unsigned int m_AdditionalWidth
Definition: mitkGrabCutOpenCVImageFilter.h:243
itk::Index
Definition: mitkGrabCutOpenCVImageFilter.h:32
MITKOPENCVVIDEOSUPPORT_EXPORT
#define MITKOPENCVVIDEOSUPPORT_EXPORT
Definition: MitkOpenCVVideoSupportExports.h:15
mitkVector.h
mitk::GrabCutOpenCVImageFilter::m_ModelPointsDilationSize
int m_ModelPointsDilationSize
Definition: mitkGrabCutOpenCVImageFilter.h:240
mitk::GrabCutOpenCVImageFilter::m_InputImage
cv::Mat m_InputImage
Definition: mitkGrabCutOpenCVImageFilter.h:249
mitkAbstractOpenCVImageFilter.h
mitk::GrabCutOpenCVImageFilter::m_ResultImageId
int m_ResultImageId
id of the image which segmentation result is currently present in m_ResultMask
Definition: mitkGrabCutOpenCVImageFilter.h:259
mitk::GrabCutOpenCVImageFilter::m_InputImageId
int m_InputImageId
id of the image currently set as m_InputImage
Definition: mitkGrabCutOpenCVImageFilter.h:256