]> Creatis software - clitk.git/blob - common/clitkImageUtilities.txx
added the new headers
[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://oncora1.lyon.fnclcc.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   // Check size
72   if (input->GetLargestPossibleRegion() != mask->GetLargestPossibleRegion()) {
73         itkGenericExceptionMacro(<< "Input and mask images have not the same size"
74                                                          << std::endl
75                                                          << "Input = " << input->GetLargestPossibleRegion()
76                                                          << std::endl
77                                                          << "Mask = " << mask->GetLargestPossibleRegion());
78   }
79
80   // reset weights list
81   mapOfLabelsAndWeights.clear();
82
83   // loop
84   typedef itk::ImageRegionConstIterator<InputImageType> ConstInputIteratorType;
85   ConstInputIteratorType pi(input, input->GetLargestPossibleRegion());
86   typedef itk::ImageRegionConstIterator<MaskImageType> ConstMaskIteratorType;
87   ConstMaskIteratorType pm(mask, mask->GetLargestPossibleRegion());
88   pi.Begin();
89   pm.Begin();
90   while (!pi.IsAtEnd()) {
91         mapOfLabelsAndWeights[pm.Get()][pi.Get()]++;
92         ++pi;
93         ++pm;
94   }
95 }
96 //====================================================================
97
98 // //====================================================================
99 // template<class ImageType>
100 // typename ImageType::Pointer NewImage3D(int x, int y, int z, float dx, float dy, float dz) {  
101 //   typename ImageType::Pointer output = ImageType::New();
102 //   typename ImageType::RegionType region;
103 //   typename ImageType::SizeType size;
104 //   size[0] = x;
105 //   size[1] = y;
106 //   size[2] = z;
107 //   region.SetSize(size);
108 //   output->SetRegions(region);
109 //   output->Allocate();
110 //   typename ImageType::SpacingType spacing;  
111 //   spacing[0] = dx;
112 //   spacing[1] = dy;
113 //   spacing[2] = dz;
114 //   output->SetSpacing(spacing);
115 //   return output;
116 // }
117 // //====================================================================
118
119
120 #endif /* end #define CLITKIMAGEUTILITIES_TXX */
121