Medical Imaging Interaction Toolkit  2022.10.99-efe2ad43
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:
33  itkNewMacro(Self);
34 
36 
43 
50 
57  void Initialize(const mitk::Image *image) override;
58 
61  void ClearBuffer();
62 
70  void MergeLabel(PixelType pixelValue, PixelType sourcePixelValue, unsigned int layer = 0);
71 
79  void MergeLabels(PixelType pixelValue, std::vector<PixelType>& vectorOfSourcePixelValues, unsigned int layer = 0);
80 
83  void UpdateCenterOfMass(PixelType pixelValue, unsigned int layer = 0);
84 
92  void RemoveLabel(PixelType pixelValue, unsigned int layer = 0);
93 
102  void RemoveLabels(std::vector<PixelType> &VectorOfLabelPixelValues, unsigned int layer = 0);
103 
110  void EraseLabel(PixelType pixelValue);
111 
117  void EraseLabels(std::vector<PixelType> &VectorOfLabelPixelValues);
118 
121  bool ExistLabel(PixelType pixelValue) const;
122 
129  bool ExistLabel(PixelType pixelValue, unsigned int layer) const;
130 
133  bool ExistLabelSet(unsigned int layer) const;
134 
140  mitk::Label *GetActiveLabel(unsigned int layer = 0);
141  const mitk::Label* GetActiveLabel(unsigned int layer = 0) const;
142 
149  mitk::Label *GetLabel(PixelType pixelValue, unsigned int layer = 0) const;
150 
155  mitk::LabelSet *GetActiveLabelSet();
156  const mitk::LabelSet* GetActiveLabelSet() const;
157 
163  mitk::LabelSet *GetLabelSet(unsigned int layer = 0);
164  const mitk::LabelSet *GetLabelSet(unsigned int layer = 0) const;
165 
170  unsigned int GetActiveLayer() const;
171 
177  unsigned int GetNumberOfLabels(unsigned int layer = 0) const;
178 
183  unsigned int GetTotalNumberOfLabels() const;
184 
185  // This function will need to be ported to an external class
186  // it requires knowledge of pixeltype and dimension and includes
187  // too much algorithm to be sensibly part of a data class
189  // * \brief */
190  // void SurfaceStamp(mitk::Surface* surface, bool forceOverwrite);
191 
194  mitk::Image::Pointer CreateLabelMask(PixelType index, bool useActiveLayer = true, unsigned int layer = 0);
195 
203  void InitializeByLabeledImage(mitk::Image::Pointer image);
204 
207  void MaskStamp(mitk::Image *mask, bool forceOverwrite);
208 
211  void SetActiveLayer(unsigned int layer);
212 
215  unsigned int GetNumberOfLayers() const;
216 
222  unsigned int AddLayer(mitk::LabelSet::Pointer labelSet = nullptr);
223 
230  unsigned int AddLayer(mitk::Image::Pointer layerImage, mitk::LabelSet::Pointer labelSet = nullptr);
231 
244  void AddLabelSetToLayer(const unsigned int layerIdx, const mitk::LabelSet::Pointer labelSet);
245 
250  void RemoveLayer();
251 
254  mitk::Image *GetLayerImage(unsigned int layer);
255 
256  const mitk::Image *GetLayerImage(unsigned int layer) const;
257 
258  void OnLabelSetModified();
259 
264  void SetExteriorLabel(mitk::Label *label);
265 
270  mitk::Label *GetExteriorLabel();
271 
272  const mitk::Label *GetExteriorLabel() const;
273 
274  protected:
276 
277  LabelSetImage();
278  LabelSetImage(const LabelSetImage &other);
279  ~LabelSetImage() override;
280 
281  template <typename TPixel, unsigned int VImageDimension>
282  void LayerContainerToImageProcessing(itk::Image<TPixel, VImageDimension> *source, unsigned int layer);
283 
284  template <typename TPixel, unsigned int VImageDimension>
285  void ImageToLayerContainerProcessing(itk::Image<TPixel, VImageDimension> *source, unsigned int layer) const;
286 
287  template <typename ImageType>
288  void CalculateCenterOfMassProcessing(ImageType *input, PixelType index, unsigned int layer);
289 
290  template <typename ImageType>
291  void ClearBufferProcessing(ImageType *input);
292 
293  template <typename ImageType>
294  void EraseLabelProcessing(ImageType *input, PixelType index);
295 
296  template <typename ImageType>
297  void MergeLabelProcessing(ImageType *input, PixelType pixelValue, PixelType index);
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 
309 
311 
313  };
314 
332  MITKMULTILABEL_EXPORT bool Equal(const mitk::LabelSetImage &leftHandSide,
333  const mitk::LabelSetImage &rightHandSide,
334  ScalarType eps,
335  bool verbose);
336 
337 
341  namespace MultiLabelSegmentation
342  {
343  enum class MergeStyle
344  {
345  Replace, //The old label content of a lable value will be replaced by its new label content.
346  //Therefore pixels that are labeled might become unlabeled again.
347  //(This means that a lock of the value is also ignored).
348  Merge //The union of old and new label content will be generated.
349  };
350 
351  enum class OverwriteStyle
352  {
353  RegardLocks, //Locked labels in the same spatial group will not be overwritten/changed.
354  IgnoreLocks //Label locks in the same spatial group will be ignored, so these labels might be changed.
355  };
356  }
357 
379  MITKMULTILABEL_EXPORT void TransferLabelContent(const LabelSetImage* sourceImage, LabelSetImage* destinationImage,
380  std::vector<std::pair<Label::PixelType, Label::PixelType> > labelMapping = { {1,1} },
383  const TimeStepType timeStep = 0);
384 
409  MITKMULTILABEL_EXPORT void TransferLabelContent(const Image* sourceImage, Image* destinationImage, const mitk::LabelSet* destinationLabelSet,
410  mitk::Label::PixelType sourceBackground = 0, mitk::Label::PixelType destinationBackground = 0, bool destinationBackgroundLocked = false,
411  std::vector<std::pair<Label::PixelType, Label::PixelType> > labelMapping = { {1,1} },
414  const TimeStepType timeStep = 0);
415 } // namespace mitk
416 
417 #endif // __mitkLabelSetImage_H_
mitk::eps
const MITKCORE_EXPORT ScalarType eps
mitk::MultiLabelSegmentation::OverwriteStyle::IgnoreLocks
@ IgnoreLocks
MITKMULTILABEL_EXPORT
#define MITKMULTILABEL_EXPORT
Definition: MitkMultilabelExports.h:15
mitk::LabelSetImage::BeforeChangeLayerEvent
Message BeforeChangeLayerEvent
BeforeChangeLayerEvent (e.g. used for GUI integration) As soon as active labelset should be changed,...
Definition: mitkLabelSetImage.h:42
mitkImage.h
mitk::MultiLabelSegmentation::OverwriteStyle::RegardLocks
@ RegardLocks
mitkLabelSet.h
mitk::LabelSet
Definition: mitkLabelSet.h:33
mitk::Image
Image class for storing images.
Definition: mitkImage.h:69
mitk::Equal
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.
mitk::LabelSetImage::m_activeLayerInvalid
bool m_activeLayerInvalid
Definition: mitkLabelSetImage.h:310
itk::SmartPointer< Self >
mitk::LabelSetImage::AfterChangeLayerEvent
Message AfterChangeLayerEvent
AfterchangeLayerEvent (e.g. used for GUI integration) As soon as active labelset was changed,...
Definition: mitkLabelSetImage.h:49
mitk::Label::PixelType
unsigned short PixelType
Definition: mitkLabel.h:33
mitk::PropertyList::Pointer
itk::SmartPointer< Self > Pointer
Definition: mitkPropertyList.h:67
mitk
DataCollection - Class to facilitate loading/accessing structured data.
Definition: RenderingTests.dox:1
mitk::Label
A data structure describing a label.
Definition: mitkLabel.h:28
mitk::TransferLabelContent
MITKMULTILABEL_EXPORT void TransferLabelContent(const LabelSetImage *sourceImage, LabelSetImage *destinationImage, std::vector< std::pair< Label::PixelType, Label::PixelType > > labelMapping={ {1, 1} }, MultiLabelSegmentation::MergeStyle mergeStyle=MultiLabelSegmentation::MergeStyle::Replace, MultiLabelSegmentation::OverwriteStyle overwriteStlye=MultiLabelSegmentation::OverwriteStyle::RegardLocks, const TimeStepType timeStep=0)
mitk::MultiLabelSegmentation::MergeStyle::Replace
@ Replace
mitk::MultiLabelSegmentation::MergeStyle
MergeStyle
Definition: mitkLabelSetImage.h:343
mitk::LabelSetImage::m_ActiveLayer
int m_ActiveLayer
Definition: mitkLabelSetImage.h:308
mitk::LabelSetImage::m_LayerContainer
std::vector< Image::Pointer > m_LayerContainer
Definition: mitkLabelSetImage.h:306
mitk::BaseData
Base of all data objects.
Definition: mitkBaseData.h:42
mitk::MultiLabelSegmentation::OverwriteStyle
OverwriteStyle
Definition: mitkLabelSetImage.h:351
mitk::MultiLabelSegmentation::MergeStyle::Merge
@ Merge
mitk::LabelSetImage::m_ExteriorLabel
mitk::Label::Pointer m_ExteriorLabel
Definition: mitkLabelSetImage.h:312
mitk::TimeStepType
std::size_t TimeStepType
Definition: mitkTimeGeometry.h:27
mitkCloneMacro
#define mitkCloneMacro(classname)
Definition: mitkCommon.h:154
mitkClassMacro
#define mitkClassMacro(className, SuperClassName)
Definition: mitkCommon.h:36
itk::Image
class ITK_EXPORT Image
Definition: mitkGeometryClipImageFilter.h:25
mitk::Image::Initialize
void Initialize() override
mitk::LabelSetImage::m_LabelSetContainer
std::vector< LabelSet::Pointer > m_LabelSetContainer
Definition: mitkLabelSetImage.h:305
mitk::LabelSetImage::PixelType
mitk::Label::PixelType PixelType
Definition: mitkLabelSetImage.h:33
mitk::Message
Event/message/notification class.
Definition: mitkMessage.h:452
mitk::LabelSetImage
LabelSetImage class for handling labels and layers in a segmentation session.
Definition: mitkLabelSetImage.h:29
mitk::ScalarType
double ScalarType
Definition: mitkNumericConstants.h:20
MitkMultilabelExports.h