]> Creatis software - clitk.git/blob - tools/clitkImageLog.cxx
itk4 migration
[clitk.git] / tools / clitkImageLog.cxx
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 CLITKIMAGELOG_CXX
19 #define CLITKIMAGELOG_CXX
20 /**
21  =================================================
22  * @file   clitkImageLog.cxx
23  * @author Jef Vandemeulebroucke <Jef@creatis.insa-lyon.fr>
24  * @date   04 April 2008 15:28:32
25  * 
26  * @brief  
27  * 
28  * Take an inverse normalized log of the image intensity
29  =================================================*/
30
31 // clitk include
32 #include "clitkImageLog_ggo.h"
33 #include "clitkIO.h"
34 #include "clitkCommon.h"
35
36 // itk include
37 #include "itkImageFileReader.h"
38 #include "itkImageFileWriter.h"
39 #include "itkImageRegionIterator.h"
40
41 int main(int argc, char * argv[]) {
42
43   // init command line
44   GGO(clitkImageLog, args_info);
45   CLITK_INIT;
46
47   typedef float PixelType;
48   const  unsigned int Dimension=3;
49   typedef itk::Image<PixelType, Dimension> ImageType;
50   typedef itk::ImageFileReader<ImageType> ImageReaderType;  
51   typedef itk::ImageFileWriter<ImageType> ImageWriterType;  
52   typedef itk::ImageRegionIterator<ImageType> IteratorType;  
53
54   //Read input
55   ImageReaderType::Pointer reader= ImageReaderType::New();
56   reader->SetFileName(args_info.input_arg);
57   reader->Update();
58   ImageType::Pointer input = reader->GetOutput();
59   
60   //Create iterators
61   IteratorType pi (input, input->GetLargestPossibleRegion());
62   pi.GoToBegin();
63   
64   PixelType max=std::numeric_limits<unsigned short>::max();
65   
66   //Create output
67   while(!pi.IsAtEnd())
68     {
69       if (pi.Get()< 0)
70         {
71           pi.Set(0.);
72         }
73       else
74         {
75           pi.Set(-log((PixelType)(max-pi.Get()+1)/(PixelType)max));
76         }
77       ++pi;
78     }
79   
80   ImageWriterType::Pointer writer= ImageWriterType::New();
81   writer->SetFileName(args_info.output_arg);
82   writer->SetInput(input);
83   writer->Update();
84   return 0;
85 }
86
87
88
89 #endif /* end #define CLITKIMAGELOG_CXX */