20 #include <itkNeighborhoodIterator.h>
21 #include <itkImageRegionIterator.h>
24 template <
typename TPixel,
unsigned int VImageDimension>
27 m_RegionPair = regionPair;
30 template <
typename TPixel,
unsigned int VImageDimension>
37 template <
typename TPixel,
unsigned int VImageDimension >
41 itk::Size<3> size = m_RegionPair.first.GetSize();
42 double volume = size[0] * size[1] * size[2];
44 typedef itk::Image< int, VImageDimension > IntegerImageType;
45 itk::ImageRegionIterator<IntegerImageType> it_region(m_Image, m_RegionPair.first);
47 double voxelsWithRegionValue(1);
48 double voxelsWithValueZero(0);
50 for(it_region.GoToBegin(); !it_region.IsAtEnd(); ++it_region)
52 if (it_region.Value() == m_RegionPair.second)
54 voxelsWithRegionValue++;
56 if (it_region.Value() == 0)
58 voxelsWithValueZero++;
62 double measurement = voxelsWithRegionValue / (volume - voxelsWithValueZero);
64 if (measurement > 0.3)
71 template <
typename TPixel,
unsigned int VImageDimension >
74 itk::Size<3> size = m_RegionPair.first.GetSize();
76 if (size[0] < size[1] + size[2] + 1 && size[1] < size[0] + size[2] + 1 && size[2] < size[0] + size[1] + 1)
83 template <
typename TPixel,
unsigned int VImageDimension >
86 std::pair<RegionType, int> chosenRegion = m_RegionPair;
88 typedef itk::Image< int, VImageDimension > IntegerImageType;
89 itk::ImageRegionIterator<IntegerImageType> it_region(m_Image, chosenRegion.first);
90 std::vector<double> centerOfMass;
91 centerOfMass = this->GetCenterOfMass();
92 typename IntegerImageType::IndexType indexCenterOfMass;
93 indexCenterOfMass.SetElement(0, centerOfMass[0] + 0.5);
94 indexCenterOfMass.SetElement(1, centerOfMass[1] + 0.5);
95 indexCenterOfMass.SetElement(2, centerOfMass[2] + 0.5);
96 it_region.SetIndex(indexCenterOfMass);
97 int value = it_region.Value();
99 if (it_region.Value() == chosenRegion.second || it_region.Value() == 0)
106 template <
typename TPixel,
unsigned int VImageDimension >
109 int costFunctionValue(0);
110 std::vector<int> costVector;
111 costVector.push_back(this->RegionIsFullEnough());
112 costVector.push_back(this->SidesAreNotTooLong());
113 costVector.push_back(this->COMLiesWithinParcel());
116 m_weight.push_back(1);
117 m_weight.push_back(1);
118 m_weight.push_back(0);
121 for (
int i = 0; i < costVector.size(); i++)
123 costFunctionValue += costVector[i]*m_weight[i];
126 return costFunctionValue;
129 template <
typename TPixel,
unsigned int VImageDimension>
133 itk::ImageRegionIterator<ImageType> it_region(m_Image, m_RegionPair.first);
135 typedef itk::Image< TPixel, VImageDimension >
ImageType;
136 int currentSizeOfRegion (0);
137 std::vector<typename ImageType::IndexType> indexVoxel;
138 std::vector<double> centerOfMass;
143 for (it_region.GoToBegin(); !it_region.IsAtEnd(); ++it_region)
145 if(it_region.Value() == m_RegionPair.second)
147 indexVoxel.push_back(it_region.GetIndex());
148 currentSizeOfRegion++;
156 for (
int i = 0; i < currentSizeOfRegion; i++)
158 xValue += indexVoxel[i][0];
159 yValue += indexVoxel[i][1];
160 zValue += indexVoxel[i][2];
163 centerOfMass.push_back(xValue/currentSizeOfRegion);
164 centerOfMass.push_back(yValue/currentSizeOfRegion);
165 centerOfMass.push_back(zValue/currentSizeOfRegion);
170 template <
typename TPixel,
unsigned int VImageDimension>
174 for (
int i = 0; i < m_weight.size(); i++)
176 maximalValue += m_weight[i];
void SetImage(itk::Image< TPixel, VImageDimension > *)
void SetRegion(std::pair< RegionType, int >)
itk::Image< unsigned char, 3 > ImageType
int CalculateCost()
Checks if the functions RegionIsFullEnough, SidesAreNotTooLong and COMLiesWithinParcel all return val...
int MaximalValue()
Calculates the maximal possible value of the cost function.