]> Creatis software - clitk.git/blob - common/clitkImageUtilities.txx
changes in license header
[clitk.git] / common / clitkImageUtilities.txx
1 /*=========================================================================
2   Program:   vv                     http://www.creatis.insa-lyon.fr/rio/vv
3
4   Authors belong to:
5   - University of LYON              http://www.universite-lyon.fr/
6   - Léon Bérard cancer center       http://www.centreleonberard.fr
7   - CREATIS CNRS laboratory         http://www.creatis.insa-lyon.fr
8
9   This software is distributed WITHOUT ANY WARRANTY; without even
10   the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
11   PURPOSE.  See the copyright notices for more information.
12
13   It is distributed under dual licence
14
15   - BSD        See included LICENSE.txt file
16   - CeCILL-B   http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
17 ===========================================================================**/
18 #ifndef CLITKIMAGEUTILITIES_TXX
19 #define CLITKIMAGEUTILITIES_TXX
20 /**
21  =================================================
22  * @file   clitkImageUtilities.txx
23  * @author David Sarrut <david.sarrut@creatis.insa-lyon.fr>
24  * @date   22 Sep 2006 10:39:48
25  *
26  * @brief
27  *
28  *
29  =================================================*/
30
31 //====================================================================
32 // Compute the number of different intensities in an image
33 template<class ImageType>
34 int ComputeHowManyDifferentIntensity(const typename ImageType::Pointer & image,
35                                      std::vector<typename ImageType::PixelType> & l)
36 {
37   //std::set<typename ImageType::PixelType> listOfIntensities;
38   std::map<typename ImageType::PixelType, bool> listOfIntensities;
39   //  listOfIntensities.resize(0);
40   typedef itk::ImageRegionConstIterator<ImageType> ConstIteratorType;
41   ConstIteratorType pi(image, image->GetLargestPossibleRegion());
42   pi.Begin();
43   while (!pi.IsAtEnd()) {
44     if (!listOfIntensities[pi.Get()]) listOfIntensities[pi.Get()] = true;
45     // if (std::find(listOfIntensities.begin(),
46 //                                listOfIntensities.end(),
47 //                                pi.Get()) == listOfIntensities.end()) {
48 //        listOfIntensities.insert(pi.Get());
49 //      }
50     ++pi;
51   }
52
53   //typename std::set<typename ImageType::PixelType>::const_iterator ppi = listOfIntensities.begin();
54   typename std::map<typename ImageType::PixelType, bool>::const_iterator ppi = listOfIntensities.begin();
55   while (ppi != listOfIntensities.end()) {
56     l.push_back(ppi->first);
57     ++ppi;
58   }
59
60   return listOfIntensities.size();
61 }
62 //====================================================================
63
64 //====================================================================
65 template<class InputImageType, class MaskImageType>
66 void ComputeWeightsOfEachClasses(const typename InputImageType::Pointer & input,
67                                  const typename MaskImageType::Pointer & mask,
68                                  const std::vector<typename MaskImageType::PixelType> & listOfIntensities,
69                                  std::map<typename MaskImageType::PixelType,
70                                  std::map<typename InputImageType::PixelType, double> > & mapOfLabelsAndWeights)
71 {
72   // Check size
73   if (input->GetLargestPossibleRegion() != mask->GetLargestPossibleRegion()) {
74     itkGenericExceptionMacro(<< "Input and mask images have not the same size"
75                              << std::endl
76                              << "Input = " << input->GetLargestPossibleRegion()
77                              << std::endl
78                              << "Mask = " << mask->GetLargestPossibleRegion());
79   }
80
81   // reset weights list
82   mapOfLabelsAndWeights.clear();
83
84   // loop
85   typedef itk::ImageRegionConstIterator<InputImageType> ConstInputIteratorType;
86   ConstInputIteratorType pi(input, input->GetLargestPossibleRegion());
87   typedef itk::ImageRegionConstIterator<MaskImageType> ConstMaskIteratorType;
88   ConstMaskIteratorType pm(mask, mask->GetLargestPossibleRegion());
89   pi.Begin();
90   pm.Begin();
91   while (!pi.IsAtEnd()) {
92     mapOfLabelsAndWeights[pm.Get()][pi.Get()]++;
93     ++pi;
94     ++pm;
95   }
96 }
97 //====================================================================
98
99 // //====================================================================
100 // template<class ImageType>
101 // typename ImageType::Pointer NewImage3D(int x, int y, int z, float dx, float dy, float dz) {
102 //   typename ImageType::Pointer output = ImageType::New();
103 //   typename ImageType::RegionType region;
104 //   typename ImageType::SizeType size;
105 //   size[0] = x;
106 //   size[1] = y;
107 //   size[2] = z;
108 //   region.SetSize(size);
109 //   output->SetRegions(region);
110 //   output->Allocate();
111 //   typename ImageType::SpacingType spacing;
112 //   spacing[0] = dx;
113 //   spacing[1] = dy;
114 //   spacing[2] = dz;
115 //   output->SetSpacing(spacing);
116 //   return output;
117 // }
118 // //====================================================================
119
120
121 #endif /* end #define CLITKIMAGEUTILITIES_TXX */
122