13 #ifndef mitkMultiLabelSegmentation_h
14 #define mitkMultiLabelSegmentation_h
16 #include <shared_mutex>
85 bool IsSliceSet(
int s = 0,
int t = 0,
int n = 0)
const override;
403 std::optional<GroupIndexType> index = std::make_optional<GroupIndexType>())
const;
422 itkGetConstMacro(UnlabeledLabelLock,
bool);
423 itkSetMacro(UnlabeledLabelLock,
bool);
424 itkBooleanMacro(UnlabeledLabelLock);
488 void ReplaceGroupLabels(std::map<MultiLabelSegmentation::GroupIndexType, MultiLabelSegmentation::ConstLabelVectorType> newGroupLabels);
676 template <
typename ImageType>
679 template <
typename ImageType>
682 template <
typename MultiLabelSegmentationType,
typename ImageType>
694 std::vector<Image::Pointer> m_GroupContainer;
696 using LabelMapType = std::map<LabelValueType, Label::Pointer>;
698 LabelMapType m_LabelMap;
700 using GroupNameVectorType = std::vector<std::string>;
702 GroupNameVectorType m_Groups;
706 using GroupToLabelMapType = std::vector<LabelValueVectorType>;
708 GroupToLabelMapType m_GroupToLabelMap;
709 using LabelToGroupMapType = std::map<LabelValueType, GroupIndexType>;
711 LabelToGroupMapType m_LabelToGroupMap;
713 using LabelEventGuardMapType = std::map<LabelValueType, ITKEventObserverGuard>;
714 LabelEventGuardMapType m_LabelModEventGuardMap;
719 bool m_UnlabeledLabelLock;
722 std::shared_mutex m_LabelNGroupMapsMutex;
786 bool orderIsRelevant =
false);
860 bool destinationBackgroundLocked =
false,
872 bool destinationBackgroundLocked =
false,
#define MITKMULTILABEL_EXPORT
virtual bool IsEmpty() const
Check whether object contains data (at least at one point in time), e.g., a set of points may be empt...
Image class for storing images.
A data structure describing a label.
The LookupTable class mitk wrapper for a vtkLookupTable.
Event/message/notification class.
MultiLabelSegmentation class for handling labels and layers in a segmentation session.
LabelValueType m_ActiveLabelValue
void ClearGroupImage(GroupIndexType groupID, TimeStepType timestep)
clears all label pixel content from the indicated group.
itkGetModifiableObjectMacro(LookupTable, mitk::LookupTable)
void InsertGroup(GroupIndexType groupID, ConstLabelVector labels={}, std::string name="")
Inserts a new group to the MultiLabelSegmentation. The new group will be set as the active one,...
@ RegardLocks
Locked labels in the same spatial group will not be overwritten/changed.
void RemoveGroup(GroupIndexType group)
Removes a whole group including all its labels.
void RemoveLabels(const LabelValueVectorType &vectorOfLabelPixelValues)
Removes labels from the mitk::MultiLabelSegmentation. The label is removed from the labelset and the ...
void ClearGroupImage(GroupIndexType groupID)
clears all label pixel content from the indicated group.
void SetAllLabelsLocked(bool locked)
bool ExistGroup(GroupIndexType index) const
Returns true if the spatial group exists in the MultiLabelSegmentation instance.
void ReplaceGroupLabels(const GroupIndexType groupID, const LabelVectorType &newLabels)
bool IsEmpty(LabelValueType pixelValue, TimeStepType t=0) const
static PixelType GetPixelType()
void RenameLabel(LabelValueType labelValue, const std::string &name, const Color &color)
allows to adapt name and color of a certain label
void EraseLabelProcessing(ImageType *input, LabelValueType index)
void CalculateCenterOfMassProcessing(ImageType *input, LabelValueType index)
static const LabelValueType UNLABELED_VALUE
std::size_t GroupIndexType
const std::string & GetGroupName(GroupIndexType groupID) const
const GroupImageDimensionVectorType & GetDimensions() const
Returns a vector of that contains the size (in pixel) for all dimensions of the MultiLabelSegmentatio...
void RemoveLabel(LabelValueType labelValue)
Removes the label with the given value. The label is removed from the labelset and the pixel with the...
ConstLabelVector ConstLabelVectorType
static LabelValueVectorType ExtractLabelValuesFromLabelVector(const LabelVectorType &labels)
void ReplaceGroupLabels(const GroupIndexType groupID, const ConstLabelVectorType &newLabels)
Replaces the labels of a group with a given vector of labels.
const LabelValueVectorType GetLabelValuesByGroup(GroupIndexType index) const
Returns a vector of all label values located on the specified group.
void RemoveLabelFromMap(LabelValueType labelValue)
LabelValueType GetUnusedLabelValue() const
std::vector< LabelValueType > LabelValueVectorType
LabelValueVectorType GetUsedLabelValues() const
mitk::Label * AddLabel(const std::string &name, const Color &color, GroupIndexType groupID)
Adds a new label to a group of the image by providing name and color.
mitk::Label::PixelType LabelValueType
bool IsVolumeSet(int t=0, int n=0) const override
Check whether volume at time t in channel n is set.
GroupIndexType AddGroup(ConstLabelVector labels={})
Adds a new group to the MultiLabelSegmentation. The new group will be set as the active one,...
void SetAllLabelsVisibleByName(GroupIndexType group, const std::string_view name, bool visible)
static LabelValueVectorType ExtractLabelValuesFromLabelVector(const ConstLabelVectorType &labels)
GroupIndexType GetGroupIndexOfLabel(LabelValueType value) const
mitk::Label::Pointer GetLabel(LabelValueType value)
void UpdateGroupImage(GroupIndexType groupID, const mitk::Image *sourceImage, TimeStepType timestep, TimeStepType sourceTimestep=0)
Message AfterChangeLayerEvent
AfterchangeLayerEvent (e.g. used for GUI integration) As soon as active labelset was changed,...
const LabelValueVectorType GetAllLabelValues() const
void Initialize(const mitk::Image *templateImage, bool resetLabels=true, bool ensure1stGroup=true)
Initialize new (or re-initialize) the segmentation based on the properties and geometric information ...
void VisitLabels(const LabelValueVectorType &values, std::function< void(const Label *)> &&lambda) const
const LabelVectorType GetLabels()
void InitializeByLabeledImageProcessing(MultiLabelSegmentationType *input, const ImageType *other)
std::vector< unsigned int > GroupImageDimensionVectorType
void Initialize(const mitk::TimeGeometry *geometry, bool resetLabels=true, bool ensure1stGroup=true)
Initialize new (or re-initialize) the segmentation based on the passed time geometry information....
void InitializeByLabeledImage(const mitk::Image *image)
Initialize a new mitk::MultiLabelSegmentation by a given image. For all distinct pixel values of the ...
bool ExistLabel(LabelValueType value) const
Returns true if the value exists in the MultiLabelSegmentation instance.
static ConstLabelVectorType ConvertLabelVectorConst(const LabelVectorType &labels)
unsigned int GetDimension() const
Get dimension of the MultiLabelSegmentation instance.
unsigned int GetActiveLayer() const
Gets the ID of the currently active group.
const ConstLabelVectorType GetLabels() const
const mitk::Image * GetGroupImage(GroupIndexType groupID) const
void UpdateLookupTable(LabelValueType pixelValue)
void ReplaceLabels(const ConstLabelVectorType &labelsUpdates)
Replaces the labels in the segmentation by their passed counterparts.
void UpdateCenterOfMass(LabelValueType pixelValue)
void MergeLabels(LabelValueType targetLabelValue, const LabelValueVectorType &sourceLabelValues, OverwriteStyle overwriteStyle=OverwriteStyle::RegardLocks)
Merges the content of a source labels into the target label.
unsigned int GetTotalNumberOfLabels() const
Returns the number of all labels summed up across all layers.
void EraseLabel(LabelValueType labelValue)
Erases the label with the given value from the labelset image. The label itself will not be erased fr...
void Initialize() override
~MultiLabelSegmentation() override
MultiLabelSegmentation(const MultiLabelSegmentation &other)
void SetAllLabelsLockedByName(GroupIndexType group, const std::string_view name, bool locked)
void MergeLabel(LabelValueType targetLabelValue, LabelValueType sourceLabelValue, OverwriteStyle overwriteStyle=OverwriteStyle::RegardLocks)
Merges the content of a source label into the target label.
void ClearGroupImages(TimeStepType timestep)
clears all label pixel content of all groups in one time step.
mitk::Label::ConstPointer GetLabel(LabelValueType value) const
Returns the mitk::Label with the given value.
const LabelValueVectorType GetLabelValuesByCoordinates(const Point3D &coordinates, TimeStepType timeStep=0, std::optional< GroupIndexType > index=std::make_optional< GroupIndexType >()) const
Returns a vector of all label values that are covering passed position in world coordinates.
void AddLabelToMap(LabelValueType labelValue, Label *label, GroupIndexType groupID)
void InsertGroup(GroupIndexType groupID, mitk::Image *layerImage, ConstLabelVector labels={}, std::string name="")
Inserts a new group to the MultiLabelSegmentation. The new group will be set as the active one,...
void ApplyToLabels(const LabelValueVectorType &values, std::function< void(Label *)> &&lambda)
std::vector< std::string > GetLabelClassNamesByGroup(GroupIndexType index) const
bool IsEmpty(const Label *label, TimeStepType t=0) const
Checks if a label is empty at a given time step (does not contain any pixels).
bool IsChannelSet(int n=0) const override
Check whether the channel n is set.
mitkClassMacro(MultiLabelSegmentation, SlicedData)
bool ExistLabel(LabelValueType value, GroupIndexType groupIndex) const
Checks if a label belongs in a certain spatial group.
void OnLabelModified(const Object *sender, const itk::EventObject &)
LabelVector LabelVectorType
void EraseLabels(const LabelValueVectorType &labelValues)
Erases a list of labels with the given values from the labelset image.
unsigned int GetNumberOfLabels(unsigned int group) const
Get the number of all existing mitk::Labels for a given group.
std::vector< std::string > GetLabelClassNames() const
void ReplaceGroupLabels(std::map< MultiLabelSegmentation::GroupIndexType, MultiLabelSegmentation::ConstLabelVectorType > newGroupLabels)
Replaces the labels of all passed group IDs (map key) with a given vector of labels (map value).
void SetActiveLabel(LabelValueType label)
void ClearGroupImages()
clears all label pixel content of all groups.
const Label * GetActiveLabel() const
void SetAllLabelsVisibleByGroup(GroupIndexType group, bool visible)
void UpdateLabel(LabelValueType labelValue, const Label *templateLabel)
allows to update the properties of a certain label If a property exists in the destination label only...
itk::ModifiedTimeType GetMTime() const override
const LabelValueVectorType GetLabelValuesByName(const std::string_view name) const
Returns a vector of all label values of the segmentation having a certain name.
void ReplaceLabels(const LabelVectorType &newLabels)
const ConstLabelVectorType GetConstLabelsByValue(const LabelValueVectorType &labelValues, bool ignoreMissing=false) const
Returns a vector with const pointers to all labels in the MultiLabelSegmentation indicated by the pas...
mitk::Image * GetGroupImage(GroupIndexType groupID)
void ReleaseLabel(Label *label)
bool IsLabelLocked(LabelValueType value) const
bool IsSliceSet(int s=0, int t=0, int n=0) const override
Check whether slice s at time t in channel n is set.
unsigned int GetNumberOfGroups() const
GroupIndexType AddGroup(mitk::Image *layerImage, ConstLabelVector labels={})
Adds a group based on a provided mitk::Image.
void RegisterLabel(Label *label)
const LabelValueVectorType GetLabelValuesByName(GroupIndexType index, const std::string_view name) const
Returns a vector of all label values located on the specified group having a certain name.
mitk::Label * AddLabelWithContent(Label *label, const Image *labelContent, GroupIndexType groupID, LabelValueType contentLabelValue, bool addAsClone=true, bool correctLabelValue=true)
Adds a label instance to a group of the multi label image including its pixel content.
mitk::Label * AddLabel(Label *label, GroupIndexType groupID, bool addAsClone=true, bool correctLabelValue=true)
Adds a label instance to a group of the multi label image.
void SetLookupTable(LookupTable *lut)
const LabelVectorType GetLabelsByValue(const LabelValueVectorType &labelValues, bool ignoreMissing=true)
Returns a vector with pointers to all labels in the MultiLabelSegmentation indicated by the passed la...
void SetAllLabelsVisible(bool visible)
void SetGroupName(GroupIndexType groupID, const std::string &name)
void SetAllLabelsLockedByGroup(GroupIndexType group, bool locked)
Class for defining the data type of pixels.
Super class of data objects consisting of slices.
Find image slices visible on a given plane.
std::vector< std::pair< Label::PixelType, Label::PixelType > > LabelValueMappingVector
std::vector< Label::ConstPointer > ConstLabelVector
MITKCORE_EXPORT const ScalarType eps
MITKMULTILABEL_EXPORT void TransferLabelContentAtTimeStep(const MultiLabelSegmentation *sourceImage, MultiLabelSegmentation *destinationImage, const TimeStepType timeStep, LabelValueMappingVector labelMapping={ {1, 1} }, MultiLabelSegmentation::MergeStyle mergeStyle=MultiLabelSegmentation::MergeStyle::Replace, MultiLabelSegmentation::OverwriteStyle overwriteStlye=MultiLabelSegmentation::OverwriteStyle::RegardLocks)
std::vector< Label::Pointer > LabelVector
itk::RGBPixel< float > Color
Color Standard RGB color typedef (float)
MITKMULTILABEL_EXPORT void TransferLabelContent(const MultiLabelSegmentation *sourceImage, MultiLabelSegmentation *destinationImage, LabelValueMappingVector labelMapping={ {1, 1} }, MultiLabelSegmentation::MergeStyle mergeStyle=MultiLabelSegmentation::MergeStyle::Replace, MultiLabelSegmentation::OverwriteStyle overwriteStlye=MultiLabelSegmentation::OverwriteStyle::RegardLocks)
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.