1 #ifndef CLITKIMAGEUTILITIES_TXX
2 #define CLITKIMAGEUTILITIES_TXX
5 =================================================
6 * @file clitkImageUtilities.txx
7 * @author David Sarrut <david.sarrut@creatis.insa-lyon.fr>
8 * @date 22 Sep 2006 10:39:48
13 =================================================*/
15 //====================================================================
16 // Compute the number of different intensities in an image
17 template<class ImageType>
18 int ComputeHowManyDifferentIntensity(const typename ImageType::Pointer & image,
19 std::vector<typename ImageType::PixelType> & l)
21 //std::set<typename ImageType::PixelType> listOfIntensities;
22 std::map<typename ImageType::PixelType, bool> listOfIntensities;
23 // listOfIntensities.resize(0);
24 typedef itk::ImageRegionConstIterator<ImageType> ConstIteratorType;
25 ConstIteratorType pi(image, image->GetLargestPossibleRegion());
27 while (!pi.IsAtEnd()) {
28 if (!listOfIntensities[pi.Get()]) listOfIntensities[pi.Get()] = true;
29 // if (std::find(listOfIntensities.begin(),
30 // listOfIntensities.end(),
31 // pi.Get()) == listOfIntensities.end()) {
32 // listOfIntensities.insert(pi.Get());
37 //typename std::set<typename ImageType::PixelType>::const_iterator ppi = listOfIntensities.begin();
38 typename std::map<typename ImageType::PixelType, bool>::const_iterator ppi = listOfIntensities.begin();
39 while (ppi != listOfIntensities.end()) {
40 l.push_back(ppi->first);
44 return listOfIntensities.size();
46 //====================================================================
48 //====================================================================
49 template<class InputImageType, class MaskImageType>
50 void ComputeWeightsOfEachClasses(const typename InputImageType::Pointer & input,
51 const typename MaskImageType::Pointer & mask,
52 const std::vector<typename MaskImageType::PixelType> & listOfIntensities,
53 std::map<typename MaskImageType::PixelType,
54 std::map<typename InputImageType::PixelType, double> > & mapOfLabelsAndWeights) {
56 if (input->GetLargestPossibleRegion() != mask->GetLargestPossibleRegion()) {
57 itkGenericExceptionMacro(<< "Input and mask images have not the same size"
59 << "Input = " << input->GetLargestPossibleRegion()
61 << "Mask = " << mask->GetLargestPossibleRegion());
65 mapOfLabelsAndWeights.clear();
68 typedef itk::ImageRegionConstIterator<InputImageType> ConstInputIteratorType;
69 ConstInputIteratorType pi(input, input->GetLargestPossibleRegion());
70 typedef itk::ImageRegionConstIterator<MaskImageType> ConstMaskIteratorType;
71 ConstMaskIteratorType pm(mask, mask->GetLargestPossibleRegion());
74 while (!pi.IsAtEnd()) {
75 mapOfLabelsAndWeights[pm.Get()][pi.Get()]++;
80 //====================================================================
82 // //====================================================================
83 // template<class ImageType>
84 // typename ImageType::Pointer NewImage3D(int x, int y, int z, float dx, float dy, float dz) {
85 // typename ImageType::Pointer output = ImageType::New();
86 // typename ImageType::RegionType region;
87 // typename ImageType::SizeType size;
91 // region.SetSize(size);
92 // output->SetRegions(region);
93 // output->Allocate();
94 // typename ImageType::SpacingType spacing;
98 // output->SetSpacing(spacing);
101 // //====================================================================
104 #endif /* end #define CLITKIMAGEUTILITIES_TXX */