1 /*=========================================================================
2 Program: vv http://www.creatis.insa-lyon.fr/rio/vv
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
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.
13 It is distributed under dual licence
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
21 =================================================
22 * @file clitkImageUtilities.txx
23 * @author David Sarrut <david.sarrut@creatis.insa-lyon.fr>
24 * @date 22 Sep 2006 10:39:48
29 =================================================*/
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)
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());
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());
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);
60 return listOfIntensities.size();
62 //====================================================================
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)
73 if (input->GetLargestPossibleRegion() != mask->GetLargestPossibleRegion()) {
74 itkGenericExceptionMacro(<< "Input and mask images have not the same size"
76 << "Input = " << input->GetLargestPossibleRegion()
78 << "Mask = " << mask->GetLargestPossibleRegion());
82 mapOfLabelsAndWeights.clear();
85 typedef itk::ImageRegionConstIterator<InputImageType> ConstInputIteratorType;
86 ConstInputIteratorType pi(input, input->GetLargestPossibleRegion());
87 typedef itk::ImageRegionConstIterator<MaskImageType> ConstMaskIteratorType;
88 ConstMaskIteratorType pm(mask, mask->GetLargestPossibleRegion());
91 while (!pi.IsAtEnd()) {
92 mapOfLabelsAndWeights[pm.Get()][pi.Get()]++;
97 //====================================================================
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;
108 // region.SetSize(size);
109 // output->SetRegions(region);
110 // output->Allocate();
111 // typename ImageType::SpacingType spacing;
115 // output->SetSpacing(spacing);
118 // //====================================================================
121 #endif /* end #define CLITKIMAGEUTILITIES_TXX */