ITK
6.0.0
Insight Toolkit
|
#include <itkLabelMap.h>
Templated n-dimensional image to store labeled objects.
LabelMap is an image class specialized in storing the labeled images. It represent the image in a different way than itk::Image. Instead of storing the content of the image in an array of pixels values, it store the a collection of labeled objects, and a background value. This way of storing the content of the image allow an easy and efficient manipulation of the objects in the image.
The LabelMap shares a lot of methods with the itk::Image class. it make it usable as input or output of the itk::ImageToImageFilter for example. However the methods don't have the same complexity in the 2 classes, because of the different way to store the data. GetPixel() is run in constant time for example in itk::Image, but have a worst case complexity of O(L), where L is the number of lines in the image (imageSize[1] * imageSize[2] for a 3D image).
To iterate over the LabelObjects in the map, use:
This implementation was taken from the Insight Journal paper: https://doi.org/10.54294/q6auw4
Definition at line 70 of file itkLabelMap.h.
Classes | |
class | ConstIterator |
class | Iterator |
Public Member Functions | |
void | AddLabelObject (LabelObjectType *labelObject) |
void | AddPixel (const IndexType &idx, const LabelType &label) |
void | Allocate (bool initialize=false) override |
void | ClearLabels () |
LabelObjectType * | GetLabelObject (const IndexType &idx) const |
LabelObjectVectorType | GetLabelObjects () const |
LabelVectorType | GetLabels () const |
const char * | GetNameOfClass () const override |
Self::SizeValueType | GetNumberOfLabelObjects () const |
const LabelType & | GetPixel (const IndexType &idx) const |
virtual void | Graft (const Self *imgData) |
bool | HasLabel (const LabelType label) const |
void | Initialize () override |
void | Optimize () |
void | PrintLabelObjects () const |
void | PrintLabelObjects (std::ostream &os) const |
void | PushLabelObject (LabelObjectType *labelObject) |
void | RemoveLabel (const LabelType &label) |
void | RemoveLabelObject (LabelObjectType *labelObject) |
void | RemovePixel (const IndexType &idx, const LabelType &label) |
void | SetLine (const IndexType &idx, const LengthType &length, const LabelType &label) |
void | SetPixel (const IndexType &idx, const LabelType &iLabel) |
LabelObjectType * | GetLabelObject (const LabelType &label) |
const LabelObjectType * | GetLabelObject (const LabelType &label) const |
LabelObjectType * | GetNthLabelObject (const SizeValueType &pos) |
const LabelObjectType * | GetNthLabelObject (const SizeValueType &pos) const |
virtual LabelType | GetBackgroundValue () const |
virtual void | SetBackgroundValue (LabelType _arg) |
Public Member Functions inherited from itk::ImageBase< TLabelObject::ImageDimension > | |
void | AllocateInitialized () |
OffsetValueType | ComputeOffset (const IndexType &ind) const |
void | CopyInformation (const DataObject *data) override |
virtual const RegionType & | GetBufferedRegion () const |
virtual const DirectionType & | GetDirection () const |
virtual const DirectionType & | GetInverseDirection () const |
virtual const RegionType & | GetLargestPossibleRegion () const |
const char * | GetNameOfClass () const override |
virtual const PointType & | GetOrigin () const |
virtual const RegionType & | GetRequestedRegion () const |
virtual const SpacingType & | GetSpacing () const |
void | Initialize () override |
bool | IsCongruentImageGeometry (const ImageBase *otherImage, double coordinateTolerance, double directionTolerance) const |
bool | IsSameImageGeometryAs (const ImageBase *otherImage, double coordinateTolerance=DefaultImageCoordinateTolerance, double directionTolerance=DefaultImageDirectionTolerance) const |
bool | RequestedRegionIsOutsideOfTheBufferedRegion () override |
virtual void | SetBufferedRegion (const RegionType ®ion) |
virtual void | SetDirection (const DirectionType &direction) |
virtual void | SetLargestPossibleRegion (const RegionType ®ion) |
virtual void | SetRegions (const SizeType &size) |
void | SetRequestedRegion (const DataObject *data) override |
virtual void | SetRequestedRegion (const RegionType ®ion) |
void | SetRequestedRegionToLargestPossibleRegion () override |
void | TransformLocalVectorToPhysicalVector (const FixedArray< TCoordinate, VImageDimension > &inputGradient, FixedArray< TCoordinate, VImageDimension > &outputGradient) const |
ContinuousIndex< TIndexRep, VImageDimension > | TransformPhysicalPointToContinuousIndex (const Point< TCoordinate, VImageDimension > &point) const |
bool | TransformPhysicalPointToContinuousIndex (const Point< TCoordinate, VImageDimension > &point, ContinuousIndex< TIndexRep, VImageDimension > &index) const |
bool | TransformPhysicalPointToIndex (const Point< TCoordinate, VImageDimension > &point, IndexType &index) const |
void | TransformPhysicalVectorToLocalVector (const FixedArray< TCoordinate, VImageDimension > &inputGradient, FixedArray< TCoordinate, VImageDimension > &outputGradient) const |
void | UpdateOutputData () override |
void | UpdateOutputInformation () override |
bool | VerifyRequestedRegion () override |
virtual void | SetOrigin (PointType _arg) |
virtual void | SetOrigin (const double origin[VImageDimension]) |
virtual void | SetOrigin (const float origin[VImageDimension]) |
virtual void | SetRegions (const RegionType ®ion) |
const OffsetValueType * | GetOffsetTable () const |
IndexType | ComputeIndex (OffsetValueType offset) const |
virtual void | SetSpacing (const SpacingType &spacing) |
virtual void | SetSpacing (const double spacing[VImageDimension]) |
virtual void | SetSpacing (const float spacing[VImageDimension]) |
IndexType | TransformPhysicalPointToIndex (const Point< TCoordinate, VImageDimension > &point) const |
void | TransformContinuousIndexToPhysicalPoint (const ContinuousIndex< TIndexRep, VImageDimension > &index, Point< TCoordinate, VImageDimension > &point) const |
Point< TCoordinate, VImageDimension > | TransformContinuousIndexToPhysicalPoint (const ContinuousIndex< TIndexRep, VImageDimension > &index) const |
void | TransformIndexToPhysicalPoint (const IndexType &index, Point< TCoordinate, VImageDimension > &point) const |
Point< TCoordinate, VImageDimension > | TransformIndexToPhysicalPoint (const IndexType &index) const |
TVector | TransformLocalVectorToPhysicalVector (const TVector &inputGradient) const |
TVector | TransformPhysicalVectorToLocalVector (const TVector &inputGradient) const |
virtual unsigned int | GetNumberOfComponentsPerPixel () const |
virtual void | SetNumberOfComponentsPerPixel (unsigned int) |
Public Member Functions inherited from itk::DataObject | |
virtual void | DataHasBeenGenerated () |
void | DisconnectPipeline () |
bool | GetDataReleased () const |
virtual const bool & | GetReleaseDataFlag () const |
SmartPointer< ProcessObject > | GetSource () const |
DataObjectPointerArraySizeType | GetSourceOutputIndex () const |
const DataObjectIdentifierType & | GetSourceOutputName () const |
virtual ModifiedTimeType | GetUpdateMTime () const |
virtual void | PrepareForNewData () |
virtual void | PropagateRequestedRegion () |
void | ReleaseData () |
virtual void | ReleaseDataFlagOn () |
virtual void | ResetPipeline () |
void | SetReleaseDataFlag (bool flag) |
bool | ShouldIReleaseData () const |
virtual void | Update () |
void | UpdateSource () const |
void | SetPipelineMTime (ModifiedTimeType time) |
virtual const ModifiedTimeType & | GetPipelineMTime () const |
virtual void | SetRealTimeStamp (RealTimeStamp _arg) |
virtual const RealTimeStamp & | GetRealTimeStamp () const |
Public Member Functions inherited from itk::Object | |
unsigned long | AddObserver (const EventObject &event, Command *cmd) const |
unsigned long | AddObserver (const EventObject &event, std::function< void(const EventObject &)> function) const |
LightObject::Pointer | CreateAnother () const override |
virtual void | DebugOff () const |
virtual void | DebugOn () const |
Command * | GetCommand (unsigned long tag) |
bool | GetDebug () const |
MetaDataDictionary & | GetMetaDataDictionary () |
const MetaDataDictionary & | GetMetaDataDictionary () const |
virtual ModifiedTimeType | GetMTime () const |
virtual const TimeStamp & | GetTimeStamp () const |
bool | HasObserver (const EventObject &event) const |
void | InvokeEvent (const EventObject &) |
void | InvokeEvent (const EventObject &) const |
virtual void | Modified () const |
void | Register () const override |
void | RemoveAllObservers () |
void | RemoveObserver (unsigned long tag) const |
void | SetDebug (bool debugFlag) const |
void | SetReferenceCount (int) override |
void | UnRegister () const noexcept override |
void | SetMetaDataDictionary (const MetaDataDictionary &rhs) |
void | SetMetaDataDictionary (MetaDataDictionary &&rrhs) |
virtual void | SetObjectName (std::string _arg) |
virtual const std::string & | GetObjectName () const |
Public Member Functions inherited from itk::LightObject | |
Pointer | Clone () const |
virtual void | Delete () |
virtual int | GetReferenceCount () const |
void | Print (std::ostream &os, Indent indent=0) const |
Static Public Member Functions | |
static Pointer | New () |
Static Public Member Functions inherited from itk::ImageBase< TLabelObject::ImageDimension > | |
static constexpr unsigned int | GetImageDimension () |
static Pointer | New () |
Static Public Member Functions inherited from itk::DataObject | |
static bool | GetGlobalReleaseDataFlag () |
static void | GlobalReleaseDataFlagOff () |
static void | GlobalReleaseDataFlagOn () |
static Pointer | New () |
static void | SetGlobalReleaseDataFlag (bool val) |
Static Public Member Functions inherited from itk::Object | |
static bool | GetGlobalWarningDisplay () |
static void | GlobalWarningDisplayOff () |
static void | GlobalWarningDisplayOn () |
static Pointer | New () |
static void | SetGlobalWarningDisplay (bool val) |
Static Public Member Functions inherited from itk::LightObject | |
static void | BreakOnError () |
static Pointer | New () |
Static Public Attributes | |
static constexpr unsigned int | ImageDimension = LabelObjectType::ImageDimension |
Static Public Attributes inherited from itk::ImageBase< TLabelObject::ImageDimension > | |
static constexpr ImageDimensionType | ImageDimension |
Protected Member Functions | |
void | Graft (const DataObject *data) override |
LabelMap ()=default | |
void | PrintSelf (std::ostream &os, Indent indent) const override |
~LabelMap () override=default | |
Protected Member Functions inherited from itk::ImageBase< TLabelObject::ImageDimension > | |
virtual void | ComputeIndexToPhysicalPointMatrices () |
void | ComputeOffsetTable () |
void | Graft (const DataObject *data) override |
ImageBase ()=default | |
virtual void | InitializeBufferedRegion () |
void | PrintSelf (std::ostream &os, Indent indent) const override |
~ImageBase () override=default | |
OffsetValueType | FastComputeOffset (const IndexType &ind) const |
IndexType | FastComputeIndex (OffsetValueType offset) const |
Protected Member Functions inherited from itk::DataObject | |
DataObject () | |
virtual void | PropagateResetPipeline () |
~DataObject () override | |
Protected Member Functions inherited from itk::Object | |
Object () | |
bool | PrintObservers (std::ostream &os, Indent indent) const |
virtual void | SetTimeStamp (const TimeStamp &timeStamp) |
~Object () override | |
Protected Member Functions inherited from itk::LightObject | |
virtual LightObject::Pointer | InternalClone () const |
LightObject () | |
virtual void | PrintHeader (std::ostream &os, Indent indent) const |
virtual void | PrintTrailer (std::ostream &os, Indent indent) const |
virtual | ~LightObject () |
Private Types | |
using | LabelObjectContainerConstIterator = typename LabelObjectContainerType::const_iterator |
using | LabelObjectContainerIterator = typename LabelObjectContainerType::iterator |
using | LabelObjectContainerType = std::map< LabelType, LabelObjectPointerType > |
Private Member Functions | |
void | AddPixel (const LabelObjectContainerIterator &it, const IndexType &idx, const LabelType &label) |
void | RemovePixel (const LabelObjectContainerIterator &it, const IndexType &idx, bool iEmitModifiedEvent) |
Private Attributes | |
LabelType | m_BackgroundValue {} |
LabelObjectContainerType | m_LabelObjectContainer {} |
Additional Inherited Members | |
Protected Attributes inherited from itk::ImageBase< TLabelObject::ImageDimension > | |
SpacingType | m_Spacing |
PointType | m_Origin |
DirectionType | m_Direction |
DirectionType | m_InverseDirection |
DirectionType | m_IndexToPhysicalPoint |
DirectionType | m_PhysicalPointToIndex |
Protected Attributes inherited from itk::LightObject | |
std::atomic< int > | m_ReferenceCount {} |
using itk::LabelMap< TLabelObject >::ConstPointer = SmartPointer<const Self> |
Definition at line 80 of file itkLabelMap.h.
using itk::LabelMap< TLabelObject >::ConstWeakPointer = WeakPointer<const Self> |
Definition at line 81 of file itkLabelMap.h.
|
private |
Definition at line 473 of file itkLabelMap.h.
|
private |
Definition at line 472 of file itkLabelMap.h.
|
private |
the LabelObject container type
Definition at line 471 of file itkLabelMap.h.
using itk::LabelMap< TLabelObject >::LabelObjectPointerType = typename LabelObjectType::Pointer |
Definition at line 91 of file itkLabelMap.h.
using itk::LabelMap< TLabelObject >::LabelObjectType = TLabelObject |
Definition at line 89 of file itkLabelMap.h.
using itk::LabelMap< TLabelObject >::LabelObjectVectorType = std::vector<LabelObjectPointerType> |
Definition at line 108 of file itkLabelMap.h.
using itk::LabelMap< TLabelObject >::LabelType = typename LabelObjectType::LabelType |
Label type alias support
Definition at line 103 of file itkLabelMap.h.
using itk::LabelMap< TLabelObject >::LabelVectorType = std::vector<LabelType> |
types used to expose labels only and label objects only
Definition at line 107 of file itkLabelMap.h.
using itk::LabelMap< TLabelObject >::LengthType = SizeValueType |
Definition at line 94 of file itkLabelMap.h.
using itk::LabelMap< TLabelObject >::PixelType = LabelType |
Definition at line 104 of file itkLabelMap.h.
using itk::LabelMap< TLabelObject >::Pointer = SmartPointer<Self> |
Definition at line 79 of file itkLabelMap.h.
using itk::LabelMap< TLabelObject >::Self = LabelMap |
Standard class type aliases
Definition at line 77 of file itkLabelMap.h.
using itk::LabelMap< TLabelObject >::Superclass = ImageBase<TLabelObject::ImageDimension> |
Definition at line 78 of file itkLabelMap.h.
|
protecteddefault |
|
overrideprotecteddefault |
void itk::LabelMap< TLabelObject >::AddLabelObject | ( | LabelObjectType * | labelObject | ) |
Add a label object to the image. If a label object already has the label, it is overridden.
void itk::LabelMap< TLabelObject >::AddPixel | ( | const IndexType & | idx, |
const LabelType & | label | ||
) |
Add index idx
to the label object whose label is label
. If no label object has the label label
, the corresponding label object is created. The worst case complexity of this method is O(L) where L is the number of lines in the image. However, the execution time will be quite low if the pixels are set in the image in raster mode.
|
private |
|
overridevirtual |
Allocate the image memory. The size of the image must already be set, e.g. by calling SetRegions() or SetBufferedRegion().
This method should be pure virtual, if backwards compatibility was not required.
Reimplemented from itk::ImageBase< TLabelObject::ImageDimension >.
void itk::LabelMap< TLabelObject >::ClearLabels | ( | ) |
Remove all the labels in the image
|
virtual |
Set/Get the background label
LabelObjectType* itk::LabelMap< TLabelObject >::GetLabelObject | ( | const IndexType & | idx | ) | const |
Return the label object at a given index. This method has a worst case complexity of O(L) where L is the number of lines in the image - use it with care.
LabelObjectType* itk::LabelMap< TLabelObject >::GetLabelObject | ( | const LabelType & | label | ) |
Return the LabelObject with the label given in parameter. This method throws an exception if the label doesn't exist in this image, or if the label is the background one.
const LabelObjectType* itk::LabelMap< TLabelObject >::GetLabelObject | ( | const LabelType & | label | ) | const |
Return the LabelObject with the label given in parameter. This method throws an exception if the label doesn't exist in this image, or if the label is the background one.
LabelObjectVectorType itk::LabelMap< TLabelObject >::GetLabelObjects | ( | ) | const |
Return the label objects available in the label map
LabelVectorType itk::LabelMap< TLabelObject >::GetLabels | ( | ) | const |
Return the labels of the label objects available in the label map
|
overridevirtual |
Reimplemented from itk::DataObject.
LabelObjectType* itk::LabelMap< TLabelObject >::GetNthLabelObject | ( | const SizeValueType & | pos | ) |
Return the LabelObject with at the position given in parameter. This method can be useful when the labels are not consecutive, but is quite inefficient. This method throws an exception if the index doesn't exist in this image.
const LabelObjectType* itk::LabelMap< TLabelObject >::GetNthLabelObject | ( | const SizeValueType & | pos | ) | const |
Return the LabelObject with at the position given in parameter. This method can be useful when the labels are not consecutive, but is quite inefficient. This method throws an exception if the index doesn't exist in this image.
|
inline |
Return the number of label objects in the image
Definition at line 273 of file itkLabelMap.h.
const LabelType& itk::LabelMap< TLabelObject >::GetPixel | ( | const IndexType & | idx | ) | const |
Return the pixel value at a given index in the image. If the given index is contained in several objects, only the smallest label of those objects is returned. This method has a worst case complexity of O(L) where L is the number of lines in the image - use it with care.
|
overrideprotectedvirtual |
Graft the data and information from one image to another. This is a convenience method to setup a second image with all the meta information of another image and use the same pixel container. Note that this method is different than just using two SmartPointers to the same image since separate DataObjects are still maintained. This method is similar to ImageSource::GraftOutput(). The implementation in ImageBase simply calls CopyInformation() and copies the region ivars. Subclasses of ImageBase are responsible for copying the pixel container.
Reimplemented from itk::ImageBase< TLabelObject::ImageDimension >.
|
virtual |
Graft the data and information from one image to another. This is a convenience method to setup a second image with all the meta information of another image and use the same pixel container. Note that this method is different than just using two SmartPointers to the same image since separate DataObjects are still maintained. This method is similar to ImageSource::GraftOutput(). The implementation in ImageBase simply calls CopyInformation() and copies the region ivars. Subclasses of ImageBase are responsible for copying the pixel container.
Reimplemented from itk::ImageBase< TLabelObject::ImageDimension >.
bool itk::LabelMap< TLabelObject >::HasLabel | ( | const LabelType | label | ) | const |
Return true is the image contains the label given in parameter and false otherwise. If the label is the background one, true is also returned, so this method may not be a good enough test before calling GetLabelObject().
|
overridevirtual |
Restore the data object to its initial state. This means releasing memory.
Reimplemented from itk::DataObject.
|
static |
Method for creation through the object factory.
void itk::LabelMap< TLabelObject >::Optimize | ( | ) |
Optimize the line representation of all the label objects referenced in the LabelMap
|
inline |
Definition at line 305 of file itkLabelMap.h.
void itk::LabelMap< TLabelObject >::PrintLabelObjects | ( | std::ostream & | os | ) | const |
Print all the objects stored in that collection - a convenient method for prototyping.
|
overrideprotectedvirtual |
Methods invoked by Print() to print information about the object including superclasses. Typically not called by the user (use Print() instead) but used in the hierarchical print process to combine the output of several classes.
Reimplemented from itk::DataObject.
void itk::LabelMap< TLabelObject >::PushLabelObject | ( | LabelObjectType * | labelObject | ) |
Add a label object to the image. The label of the label object is ignored, and a new label is given to the label object.
void itk::LabelMap< TLabelObject >::RemoveLabel | ( | const LabelType & | label | ) |
Remove a label object.
void itk::LabelMap< TLabelObject >::RemoveLabelObject | ( | LabelObjectType * | labelObject | ) |
Remove a label object.
void itk::LabelMap< TLabelObject >::RemovePixel | ( | const IndexType & | idx, |
const LabelType & | label | ||
) |
Remove index idx
from the label object which has the label label
. If the label object gets empty, it is being removed from the container.
|
private |
|
virtual |
Set/Get the background label
void itk::LabelMap< TLabelObject >::SetLine | ( | const IndexType & | idx, |
const LengthType & | length, | ||
const LabelType & | label | ||
) |
Set a full line in the image. If no label object has this label in the image, a new object is created. If a label object already exist with that label, the line is added to it WITHOUT any check - it means that if the label object may contain several time the same pixel after have run that method. This method runs in constant time.
void itk::LabelMap< TLabelObject >::SetPixel | ( | const IndexType & | idx, |
const LabelType & | iLabel | ||
) |
Set the pixel value at a given index in the image.
As for itk::Image, this method ensure that the pixel at the position idx
has a unique value.
The complexity of this method is at best O(L) where L is the number of lines in the image - use it with care.
|
staticconstexpr |
Dimension of the image. This constant is used by functions that are templated over image type (as opposed to being templated over pixel type and dimension) when they need compile time access to the dimension of the image.
Definition at line 100 of file itkLabelMap.h.
|
private |
Definition at line 476 of file itkLabelMap.h.
|
private |
Definition at line 475 of file itkLabelMap.h.