Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
mitkRegionVoxelCounter.cpp
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 //#include <mitkRegionVoxelCounter.h>
18 
19 //Itk Iterators
20 #include <itkNeighborhoodIterator.h>
21 #include <itkImageRegionIterator.h>
22 
23 //Set Functions
24 template <typename TPixel, unsigned int VImageDimension>
25 void mitk::RegionVoxelCounter<TPixel, VImageDimension>::SetRegion(typename ImageType::RegionType region)
26 {
27  m_Region = region;
28 }
29 
30 template <typename TPixel, unsigned int VImageDimension>
31 void mitk::RegionVoxelCounter<TPixel, VImageDimension>::SetImage(itk::Image<TPixel, VImageDimension> * image)
32 {
33  m_Image = image;
34 }
35 
36 //Other Functions
37 template <typename TPixel, unsigned int VImageDimension>
39 {
40  itk::ImageRegionIterator<ImageType> it_region(m_Image, m_Region);
41  int counter(0);
42 
43  for (it_region.GoToBegin(); !it_region.IsAtEnd(); ++it_region)
44  {
45  if (it_region.Value() == value) //Found Voxel with chosen value
46  {
47  counter++;
48  }
49  }
50  return counter;
51 }
52 
53 template <typename TPixel, unsigned int VImageDimension>
55 {
56  itk::Size<3> regionSize = m_Region.GetSize();
57  double volume = regionSize[0] * regionSize[1] * regionSize[2];
58 
59  double measurement = this->VoxelWithValue(value) / (volume - this->VoxelWithValue(0));
60  return measurement;
61 }
void SetImage(itk::Image< TPixel, VImageDimension > *)
double PercentageVoxelWithValueZeroExcluded(int value)
Gives back the percentage of the number of voxels with the chosen value in comparison to the number o...
void SetRegion(typename ImageType::RegionType)
int VoxelWithValue(int value)
Counts all voxels with the chosen value in the set region.