| 1 |
|
/*========================================================================= |
| 2 |
|
|
| 3 |
|
Program: Insight Segmentation & Registration Toolkit |
| 4 |
|
Module: $RCSfile: itkKLMSegmentationRegion.h.html,v $ |
| 5 |
|
Language: C++ |
| 6 |
|
Date: $Date: 2006/01/17 19:15:40 $ |
| 7 |
|
Version: $Revision: 1.4 $ |
| 8 |
|
|
| 9 |
|
Copyright (c) Insight Software Consortium. All rights reserved. |
| 10 |
|
See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details. |
| 11 |
|
|
| 12 |
|
This software is distributed WITHOUT ANY WARRANTY; without even |
| 13 |
|
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
| 14 |
|
PURPOSE. See the above copyright notices for more information. |
| 15 |
|
|
| 16 |
|
=========================================================================*/ |
| 17 |
DEF |
#ifndef _itkKLMSegmentationRegion_h |
| 18 |
DEF |
#define _itkKLMSegmentationRegion_h |
| 19 |
|
|
| 20 |
|
#include "itkObject.h" |
| 21 |
|
#include "itkKLMSegmentationBorder.h" |
| 22 |
|
#include "itkSegmentationRegion.h" |
| 23 |
|
|
| 24 |
|
#include "vnl/vnl_vector.h" |
| 25 |
|
|
| 26 |
|
namespace itk |
| 27 |
|
{ |
| 28 |
|
|
| 29 |
|
/** \class KLMSegmentationRegion |
| 30 |
|
* \brief Base class for KLMSegmentationRegion object |
| 31 |
|
* |
| 32 |
|
* itkKLMSegmentationRegion is the base class for the KLMSegmentationRegion |
| 33 |
|
* objects. It provides the basic function definitions that are inherent to |
| 34 |
|
* KLMSegmentationRegion objects. |
| 35 |
|
* |
| 36 |
|
* This object supports data handling of multiband images. The object |
| 37 |
|
* accepts images in vector format, where each pixel is a vector and each |
| 38 |
|
* element of the vector corresponds to an entry from 1 particular band of |
| 39 |
|
* a multiband dataset. |
| 40 |
|
* |
| 41 |
|
* We expect the user to provide the input to the routine in vector format. |
| 42 |
|
* A single band image is treated as a vector image with a single element |
| 43 |
|
* for every vector. |
| 44 |
|
* |
| 45 |
|
* Data structure for a region: |
| 46 |
|
* A region is defined as a closed area in the image that is surrounded |
| 47 |
|
* by a list of borders objects (see itkKLMSegmentationBorder class). |
| 48 |
|
* |
| 49 |
|
* Shown below is an initial two-dimensional 8x9 image with a 4x3 grid size |
| 50 |
|
* partition. The initial region blocks are labelled in hexadecimal. |
| 51 |
|
* Below the grid partition, the borders are shown as E, where C |
| 52 |
|
* is an image pixel from the initial image. Note that each border is |
| 53 |
|
* placed in between two regions. Each two-dimensional region is |
| 54 |
|
* surrounded by four borders. |
| 55 |
|
* |
| 56 |
|
* Initial regions of a 8 by 9 image with a 4 by 3 grid partition. |
| 57 |
|
* \f[\begin{tabular}{|c|c|c|c|c|c|c|c|c|} |
| 58 |
|
* \hline |
| 59 |
|
* 1 & 1 & 1 & 2 & 2 & 2 & 3 & 3 & 3 \\ \hline |
| 60 |
|
* 1 & 1 & 1 & 2 & 2 & 2 & 3 & 3 & 3 \\ \hline |
| 61 |
|
* 4 & 4 & 4 & 5 & 5 & 5 & 6 & 6 & 6 \\ \hline |
| 62 |
|
* 4 & 4 & 4 & 5 & 5 & 5 & 6 & 6 & 6 \\ \hline |
| 63 |
|
* 7 & 7 & 7 & 8 & 8 & 8 & 9 & 9 & 9 \\ \hline |
| 64 |
|
* 7 & 7 & 7 & 8 & 8 & 8 & 9 & 9 & 9 \\ \hline |
| 65 |
|
* a & a & a & b & b & b & c & c & c \\ \hline |
| 66 |
|
* a & a & a & b & b & b & c & c & c \\ \hline |
| 67 |
|
* \end{tabular}\f] |
| 68 |
|
* |
| 69 |
|
* Region borders are shown as ``E''. |
| 70 |
|
* \f[\begin{tabular}{|c|c|c|c|c|c|c|c|c|c|} |
| 71 |
|
* \hline |
| 72 |
|
* C & C & C & & C & C & C & & C & C & C \\ \hline |
| 73 |
|
* C & C & C & E & C & C & C & E & C & C & C \\ \hline |
| 74 |
|
* & E & & & & E & & & & E & \\ \hline |
| 75 |
|
* C & C & C & & C & C & C & & C & C & C \\ \hline |
| 76 |
|
* C & C & C & E & C & C & C & E & C & C & C \\ \hline |
| 77 |
|
* & E & & & & E & & & & E & \\ \hline |
| 78 |
|
* C & C & C & & C & C & C & & C & C & C \\ \hline |
| 79 |
|
* C & C & C & E & C & C & C & E & C & C & C \\ \hline |
| 80 |
|
* & E & & & & E & & & & E & \\ \hline |
| 81 |
|
* C & C & C & & C & C & C & & C & C & C \\ \hline |
| 82 |
|
* C & C & C & E & C & C & C & E & C & C & C \\ \hline |
| 83 |
|
* \end{tabular}\f] |
| 84 |
|
* |
| 85 |
|
* \ingroup RegionGrowingSegmentation |
| 86 |
|
*/ |
| 87 |
|
class KLMSegmentationBorder; |
| 88 |
|
|
| 89 |
|
class ITKCommon_EXPORT KLMSegmentationRegion : public SegmentationRegion |
| 90 |
|
{ |
| 91 |
|
private: |
| 92 |
|
/** Type definition for an double vector. */ |
| 93 |
|
typedef vnl_vector<double> MeanRegionIntensityType; |
| 94 |
|
|
| 95 |
|
public: |
| 96 |
|
/** Standard class typedefs. */ |
| 97 |
|
typedef KLMSegmentationRegion Self; |
| 98 |
|
typedef SegmentationRegion Superclass; |
| 99 |
|
typedef SmartPointer<Self> Pointer; |
| 100 |
|
typedef SmartPointer<const Self> ConstPointer; |
| 101 |
|
|
| 102 |
|
/** Method for creation through the object factory. */ |
| 103 |
|
itkNewMacro(Self); |
| 104 |
|
|
| 105 |
|
/** Run-time type information (and related methods). */ |
| 106 |
|
itkTypeMacro(KLMSegmentationRegion,SegmentationRegion); |
| 107 |
|
|
| 108 |
|
/** Type definition for vector container that stores the borders |
| 109 |
|
* associated with a current region. */ |
| 110 |
|
typedef std::vector< KLMSegmentationBorder * > RegionBorderVectorType; |
| 111 |
|
|
| 112 |
|
/** Type definition for the region border vector iterators to be used. */ |
| 113 |
|
typedef RegionBorderVectorType::iterator RegionBorderVectorIterator; |
| 114 |
|
|
| 115 |
LEN |
/** Type definition for the const region border vector iterators to be used. */ |
| 116 |
LEN |
typedef RegionBorderVectorType::const_iterator RegionBorderVectorConstIterator; |
| 117 |
|
|
| 118 |
|
/** type definition for the region label type. */ |
| 119 |
|
typedef Superclass::RegionLabelType RegionLabelType; |
| 120 |
|
|
| 121 |
|
/** Get a head pointer to the vector container storing the borders |
| 122 |
|
* associated with a region. */ |
| 123 |
|
RegionBorderVectorIterator GetRegionBorderItBegin(); |
| 124 |
|
RegionBorderVectorConstIterator GetRegionBorderConstItBegin(); |
| 125 |
|
|
| 126 |
|
/** Get a tail pointer to the vector container storing the borders |
| 127 |
|
* associated with a region. */ |
| 128 |
|
RegionBorderVectorIterator GetRegionBorderItEnd(); |
| 129 |
|
RegionBorderVectorConstIterator GetRegionBorderConstItEnd(); |
| 130 |
|
|
| 131 |
|
/** Get the number of borders in the vector container storing the borders |
| 132 |
|
* associated with a region. */ |
| 133 |
|
int GetRegionBorderSize() const; |
| 134 |
|
|
| 135 |
|
/** Set/Get the mean pixel intensity in the region. */ |
| 136 |
|
itkSetMacro(MeanRegionIntensity, MeanRegionIntensityType) |
| 137 |
|
itkGetConstReferenceMacro(MeanRegionIntensity, MeanRegionIntensityType); |
| 138 |
|
|
| 139 |
|
/** Set the region with parameter values |
| 140 |
|
* defining the region. */ |
| 141 |
|
void SetRegionParameters(MeanRegionIntensityType meanRegionIntensity, |
| 142 |
|
double regionArea, |
| 143 |
|
RegionLabelType label); |
| 144 |
|
|
| 145 |
|
/** Function to print the region parameters using std::cout. */ |
| 146 |
|
void PrintRegionInfo(); |
| 147 |
|
|
| 148 |
|
/** Insert a region border to the front of the list. */ |
| 149 |
|
void PushFrontRegionBorder(KLMSegmentationBorder *pBorderCandidate); |
| 150 |
|
|
| 151 |
|
/** Insert a region border to the back of the list. */ |
| 152 |
|
void PushBackRegionBorder(KLMSegmentationBorder *pBorderCandidate); |
| 153 |
|
|
| 154 |
|
/** Insert a region border to the list, where position is unknown |
| 155 |
IND |
***** (sorting based on region labels is done to maintain consistency). */ |
| 156 |
|
void InsertRegionBorder(KLMSegmentationBorder *pBorderCandidate); |
| 157 |
|
|
| 158 |
|
/** Insert a region border into the border list at a given location. */ |
| 159 |
|
void InsertRegionBorder(RegionBorderVectorIterator it, |
| 160 |
|
KLMSegmentationBorder *pBorderCandidate); |
| 161 |
|
|
| 162 |
|
/** Delete a region border from the border list. */ |
| 163 |
|
void DeleteRegionBorder(KLMSegmentationBorder *pBorderCandidate); |
| 164 |
|
|
| 165 |
|
/** Delete all region borders in the border list. */ |
| 166 |
|
void DeleteAllRegionBorders(); |
| 167 |
|
|
| 168 |
|
/** Set the region with parameter values (mean and area) |
| 169 |
|
* defining the region when merged with the new region. */ |
| 170 |
|
void CombineRegionParameters(const Self *region); |
| 171 |
|
|
| 172 |
|
/** Compute the energy cost (mean squared difference scaled by area) |
| 173 |
|
* that would result if this region is merged with another region. */ |
| 174 |
|
double EnergyFunctional(const Self *region); |
| 175 |
|
|
| 176 |
|
/** Reset a region's label to that of the supplied region and update |
| 177 |
IND |
***** the regions borders to that of the supplied region. */ |
| 178 |
|
void ResetRegionLabelAndUpdateBorders(Self *region); |
| 179 |
|
|
| 180 |
|
/** Splice the regions borders from the new region into the current |
| 181 |
IND |
***** region. If duplicate borders are found, the duplicate border |
| 182 |
IND |
***** region is not inserted into the new region borders list, rather, |
| 183 |
IND |
***** it has its pointers to region1 and region2 set to NULL and |
| 184 |
IND |
***** Lambda set to -1.0. |
| 185 |
IND |
***** |
| 186 |
IND |
***** For example, take an image with 3 regions A, B, C |
| 187 |
IND |
***** \f[\begin{tabular}{|c|c|} |
| 188 |
IND |
***** \hline |
| 189 |
IND |
***** A & A \\ \hline |
| 190 |
IND |
***** B & C \\ \hline |
| 191 |
IND |
***** \end{tabular}\f] |
| 192 |
IND |
***** where region A has region borders A-B and A-C; |
| 193 |
IND |
***** region B has region borders A-B and B-C; and |
| 194 |
IND |
***** region C has region borders A-C and B-C. |
| 195 |
IND |
***** |
| 196 |
IND |
***** Suppose region border A-B has been removed, so that region B |
| 197 |
IND |
***** can be merged into region A. When splicing the region |
| 198 |
IND |
***** borders from A and B into the new region A, duplicate |
| 199 |
IND |
***** region borders A-C and A-C (one of which was formerly B-C) |
| 200 |
IND |
***** will be present. In this case, one of the region borders |
| 201 |
IND |
***** A-C is given the combined length of the two former borders |
| 202 |
IND |
***** and is put into the region borders list. The other is |
| 203 |
IND |
***** nullified by having its pointers to region1 and region2 set |
| 204 |
IND |
***** to NULL and its Lambda value set to -1.0. |
| 205 |
IND |
*****/ |
| 206 |
|
void SpliceRegionBorders(Self *region); |
| 207 |
|
|
| 208 |
|
/** Recalculate the Lambda values using EvaluateLambda() for all |
| 209 |
|
* the borders defining the region. */ |
| 210 |
|
void UpdateRegionBorderLambda(); |
| 211 |
|
|
| 212 |
|
protected: |
| 213 |
|
KLMSegmentationRegion(); |
| 214 |
|
~KLMSegmentationRegion(); |
| 215 |
|
void PrintSelf(std::ostream& os, Indent indent) const; |
| 216 |
|
|
| 217 |
|
private: |
| 218 |
|
KLMSegmentationRegion(const Self&); // purposely not implemented |
| 219 |
|
void operator=(const Self&); // purposely not implemented |
| 220 |
|
|
| 221 |
|
RegionBorderVectorType m_RegionBorderVector; |
| 222 |
|
MeanRegionIntensityType m_MeanRegionIntensity; |
| 223 |
|
|
| 224 |
|
}; // class SegmentationRegion |
| 225 |
|
|
| 226 |
|
|
| 227 |
|
} // namespace itk |
| 228 |
|
|
| 229 |
|
|
| 230 |
|
#endif |
| 231 |
|
|