Medical Imaging Interaction Toolkit  2018.4.99-12ad79a3
Medical Imaging Interaction Toolkit
mitkLabelSetImage.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 __mitkLabelSetImage_H_
14 #define __mitkLabelSetImage_H_
15 
16 #include <mitkImage.h>
17 #include <mitkLabelSet.h>
18 
19 #include <MitkMultilabelExports.h>
20 
21 namespace mitk
22 {
23  //##Documentation
24  //## @brief LabelSetImage class for handling labels and layers in a segmentation session.
25  //##
26  //## Handles operations for adding, removing, erasing and editing labels and layers.
27  //## @ingroup Data
28 
30  {
31  public:
32  mitkClassMacro(LabelSetImage, Image) itkNewMacro(Self)
33 
35 
41  Message<> BeforeChangeLayerEvent;
42 
48  Message<> AfterChangeLayerEvent;
49 
55  using mitk::Image::Initialize;
56  void Initialize(const mitk::Image *image) override;
57 
60  void Concatenate(mitk::LabelSetImage *image);
61 
64  void ClearBuffer();
65 
73  void MergeLabel(PixelType pixelValue, PixelType sourcePixelValue, unsigned int layer = 0);
74 
82  void MergeLabels(PixelType pixelValue, std::vector<PixelType>& vectorOfSourcePixelValues, unsigned int layer = 0);
83 
86  void UpdateCenterOfMass(PixelType pixelValue, unsigned int layer = 0);
87 
94  void RemoveLabels(std::vector<PixelType> &VectorOfLabelPixelValues, unsigned int layer = 0);
95 
103  void EraseLabel(PixelType pixelValue, unsigned int layer = 0);
104 
110  void EraseLabels(std::vector<PixelType> &VectorOfLabelPixelValues, unsigned int layer = 0);
111 
114  bool ExistLabel(PixelType pixelValue) const;
115 
122  bool ExistLabel(PixelType pixelValue, unsigned int layer) const;
123 
126  bool ExistLabelSet(unsigned int layer) const;
127 
133  mitk::Label *GetActiveLabel(unsigned int layer = 0);
134 
141  mitk::Label *GetLabel(PixelType pixelValue, unsigned int layer = 0) const;
142 
147  mitk::LabelSet *GetActiveLabelSet();
148 
154  mitk::LabelSet *GetLabelSet(unsigned int layer = 0);
155  const mitk::LabelSet *GetLabelSet(unsigned int layer = 0) const;
156 
161  unsigned int GetActiveLayer() const;
162 
168  unsigned int GetNumberOfLabels(unsigned int layer = 0) const;
169 
174  unsigned int GetTotalNumberOfLabels() const;
175 
176  // This function will need to be ported to an external class
177  // it requires knowledge of pixeltype and dimension and includes
178  // too much algorithm to be sensibly part of a data class
180  // * \brief */
181  // void SurfaceStamp(mitk::Surface* surface, bool forceOverwrite);
182 
185  mitk::Image::Pointer CreateLabelMask(PixelType index, bool useActiveLayer = true, unsigned int layer = 0);
186 
194  void InitializeByLabeledImage(mitk::Image::Pointer image);
195 
198  void MaskStamp(mitk::Image *mask, bool forceOverwrite);
199 
202  void SetActiveLayer(unsigned int layer);
203 
206  unsigned int GetNumberOfLayers() const;
207 
213  unsigned int AddLayer(mitk::LabelSet::Pointer layer = nullptr);
214 
221  unsigned int AddLayer(mitk::Image::Pointer layerImage, mitk::LabelSet::Pointer lset = nullptr);
222 
235  void AddLabelSetToLayer(const unsigned int layerIdx, const mitk::LabelSet::Pointer labelSet);
236 
241  void RemoveLayer();
242 
245  mitk::Image *GetLayerImage(unsigned int layer);
246 
247  const mitk::Image *GetLayerImage(unsigned int layer) const;
248 
249  void OnLabelSetModified();
250 
255  void SetExteriorLabel(mitk::Label *label);
256 
261  mitk::Label *GetExteriorLabel();
262 
263  const mitk::Label *GetExteriorLabel() const;
264 
265  protected:
267 
268  LabelSetImage();
269  LabelSetImage(const LabelSetImage &other);
270  ~LabelSetImage() override;
271 
272  template <typename ImageType1, typename ImageType2>
273  void ChangeLayerProcessing(ImageType1 *source, ImageType2 *target);
274 
275  template <typename TPixel, unsigned int VImageDimension>
276  void LayerContainerToImageProcessing(itk::Image<TPixel, VImageDimension> *source, unsigned int layer);
277 
278  template <typename TPixel, unsigned int VImageDimension>
279  void ImageToLayerContainerProcessing(itk::Image<TPixel, VImageDimension> *source, unsigned int layer) const;
280 
281  template <typename ImageType>
282  void CalculateCenterOfMassProcessing(ImageType *input, PixelType index, unsigned int layer);
283 
284  template <typename ImageType>
285  void ClearBufferProcessing(ImageType *input);
286 
287  template <typename ImageType>
288  void EraseLabelProcessing(ImageType *input, PixelType index, unsigned int layer);
289 
290  // template < typename ImageType >
291  // void ReorderLabelProcessing( ImageType* input, int index, int layer);
292 
293  template <typename ImageType>
294  void MergeLabelProcessing(ImageType *input, PixelType pixelValue, PixelType index);
295 
296  template <typename ImageType>
297  void ConcatenateProcessing(ImageType *input, mitk::LabelSetImage *other);
298 
299  template <typename ImageType>
300  void MaskStampProcessing(ImageType *input, mitk::Image *mask, bool forceOverwrite);
301 
302  template <typename LabelSetImageType, typename ImageType>
303  void InitializeByLabeledImageProcessing(LabelSetImageType *input, ImageType *other);
304 
305  std::vector<LabelSet::Pointer> m_LabelSetContainer;
306  std::vector<Image::Pointer> m_LayerContainer;
307 
308  int m_ActiveLayer;
309 
310  bool m_activeLayerInvalid;
311 
312  mitk::Label::Pointer m_ExteriorLabel;
313  };
314 
332  MITKMULTILABEL_EXPORT bool Equal(const mitk::LabelSetImage &leftHandSide,
333  const mitk::LabelSetImage &rightHandSide,
334  ScalarType eps,
335  bool verbose);
336 
337 } // namespace mitk
338 
339 #endif // __mitkLabelSetImage_H_
Base of all data objects.
Definition: mitkBaseData.h:37
itk::Image< unsigned char, 3 > ImageType
double ScalarType
STL namespace.
DataCollection - Class to facilitate loading/accessing structured data.
A data structure describing a label.
Definition: mitkLabel.h:31
#define MITKMULTILABEL_EXPORT
#define mitkClassMacro(className, SuperClassName)
Definition: mitkCommon.h:40
bool verbose(false)
Image class for storing images.
Definition: mitkImage.h:72
Event/message/notification class.
Definition: mitkMessage.h:568
mitk::Label::PixelType PixelType
mitk::Image::Pointer image
#define mitkCloneMacro(classname)
Definition: mitkCommon.h:158
MITKNEWMODULE_EXPORT bool Equal(mitk::ExampleDataStructure *leftHandSide, mitk::ExampleDataStructure *rightHandSide, mitk::ScalarType eps, bool verbose)
Returns true if the example data structures are considered equal.
LabelSetImage class for handling labels and layers in a segmentation session.
MITKCORE_EXPORT const ScalarType eps
mitk::Image::Pointer mask