Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
mitkRandomParcellationGenerator.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,
6 Division of Medical and Biological Informatics.
7 All rights reserved.
8 
9 This software is distributed WITHOUT ANY WARRANTY; without
10 even the implied warranty of MERCHANTABILITY or FITNESS FOR
11 A PARTICULAR PURPOSE.
12 
13 See LICENSE.txt or http://www.mitk.org for details.
14 
15 ===================================================================*/
16 
17 #ifndef mitkRandomParcellationGenerator_h
18 #define mitkRandomParcellationGenerator_h
19 
20 #include<itkImage.h>
21 
22 #include "mitkCommon.h"
23 #include "MitkConnectomicsExports.h"
24 
25 // mitk
26 #include <mitkCostFunctionBase.h>
27 #include <mitkRegionVoxelCounter.h>
28 
29 //Itk Iterators
30 #include <itkNeighborhoodIterator.h>
31 #include <itkImageRegionIterator.h>
32 
33 #include <vector>
34 
35 //To use pair
36 #include <utility>
37 
38 namespace mitk
39 {
40 
41  template <typename TPixel, unsigned int VImageDimension>
43  {
44  public:
45  typedef itk::Image< TPixel, VImageDimension > ImageType;
46 
47  //Set-Functions
48  void SetImage(itk::Image<TPixel, VImageDimension> *);
49  void SetNumberNodes(int inputNumberNodes);
50  void SetVariablesForMerging(int givenSizeOfSmallestRegion, int desiredNumberOfParcels, int givenSizeOfSmallestRegionBeginning);
51  void SetBoolsForMerging(bool mergingWithNumberParcels, bool mergingWithSmallestParcel, bool justMergeSmallParcels);
52 
53  //Main Functions
54 
59  void GetRandomSeedVoxels();
63  void ParcelGrowthOverFaces();
67  void FillOverEdgeOrVertex();
78  int MergeParcels();
80  void SetAppropriateValues();
82  void ShowSizeOfRegions();
83 
84  protected:
85  //Sub-Functions
87  std::vector<double> GetCenterOfMass( itk::ImageRegionIterator<ImageType> it_region, int valueOfRegion, bool getSizeOfRegions );
89  double GetDistance( std::vector<double> centerOfMass, typename ImageType::IndexType indexNewVoxel);
91  double GetDistanceVector( std::vector<double> centerOfMass, std::vector<double> indexNewVoxel);
93  int SmallestValue (std::vector<int> distance);
95  double SmallestValue (std::vector<double> distance);
97  typename ImageType::RegionType ExtendedRegion(typename ImageType::RegionType chosenRegion, typename ImageType::IndexType indexChosenVoxel);
99  typename ImageType::RegionType ExtendedRegionNotNeighbor(typename ImageType::RegionType chosenRegion, typename ImageType::RegionType smallestRegion);
101  bool IsUnique (int number, std::vector<int> vec);
103  void GetSizeOfRegions();
104 
105  typedef itk::ImageRegion<3> RegionType;
106  //Start the algorithm ParcelGrowthOverFaces with m_OddRegions and transfer them to m_EvenRegions or m_InvalidRegions respectively
107  std::vector<std::pair<RegionType, int> > m_EvenRegions;
108  std::vector<std::pair<RegionType, int> > m_OddRegions;
109  std::vector<std::pair<RegionType, int> > m_InvalidRegions;
110  std::vector<int> m_SizeOfRegions;
111  //For merging; regions that can't be merged any more
112  std::vector<int> m_SizeOfFinishedRegions;
113 
114  ImageType * m_Image;
122  };
123 }
124 
126 
127 #endif /* mitkRandomParcellationGenerator_h */
int MergeParcels()
Merge parcels according to a cost function Looks for the parcel with the smallest number of voxels...
bool IsUnique(int number, std::vector< int > vec)
Checks if a number is an element of the vector already.
DataCollection - Class to facilitate loading/accessing structured data.
double GetDistance(std::vector< double > centerOfMass, typename ImageType::IndexType indexNewVoxel)
Calculates the distance between two voxels, the position of the first one is given by an index and th...
std::vector< std::pair< RegionType, int > > m_EvenRegions
void SetImage(itk::Image< TPixel, VImageDimension > *)
void ShowSizeOfRegions()
Calculates and shows the size (number of voxels) of all regions on the console.
void SetBoolsForMerging(bool mergingWithNumberParcels, bool mergingWithSmallestParcel, bool justMergeSmallParcels)
itk::Image< TPixel, VImageDimension > ImageType
void SetVariablesForMerging(int givenSizeOfSmallestRegion, int desiredNumberOfParcels, int givenSizeOfSmallestRegionBeginning)
std::vector< double > GetCenterOfMass(itk::ImageRegionIterator< ImageType > it_region, int valueOfRegion, bool getSizeOfRegions)
Gives back the center of mass and -if wanted- the size (number of voxels) of a parcel.
void GetSizeOfRegions()
Calculates the size (number of voxels) of all regions.
void SetAppropriateValues()
Changes the values of the nodes, such that no gaps exist and it starts with value 1...
int SmallestValue(std::vector< int > distance)
Gives back the smallest value of an int-vector.
ImageType::RegionType ExtendedRegion(typename ImageType::RegionType chosenRegion, typename ImageType::IndexType indexChosenVoxel)
Extends the region if the chosen voxel lies outside.
void GetRandomSeedVoxels()
Sets randomly chosen seed voxels (1x1x1 regions) on the segmented image This is done by creating a ve...
double GetDistanceVector(std::vector< double > centerOfMass, std::vector< double > indexNewVoxel)
Calculates the distance between two voxels, both positions are given by vectors.
void AllocateIsolatedVoxels()
Add voxels of the segmented part to an appropriate region (no neighbors necessary) Checks which voxel...
ImageType::RegionType ExtendedRegionNotNeighbor(typename ImageType::RegionType chosenRegion, typename ImageType::RegionType smallestRegion)
Extends the region of a parcel such that the second region lies within.
void FillOverEdgeOrVertex()
Add voxels of the segmented part to an appropriate region (26-connected neighborhood) Checks which vo...
std::vector< std::pair< RegionType, int > > m_OddRegions
std::vector< std::pair< RegionType, int > > m_InvalidRegions
void ParcelGrowthOverFaces()
Add appropriate voxels of the segmented part to a region (just 6-connected neighborhood) A voxel is a...