]> Creatis software - clitk.git/blob - tools/clitkMinMaxMask.cxx
convert a DicomStruct into a binary image
[clitk.git] / tools / clitkMinMaxMask.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://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
19 // clitk
20 #include "clitkMinMaxMask_ggo.h"
21 #include "clitkIO.h"
22 #include "clitkImageCommon.h"
23 #include "itkConstSliceIterator.h"
24 #include "itkImageRegionIteratorWithIndex.h"
25
26 //--------------------------------------------------------------------
27 int main(int argc, char * argv[])
28 {
29
30   // Init command line
31   GGO(clitkMinMaxMask, args_info);
32   CLITK_INIT;
33
34   typedef short PixelType;
35   static const int Dim=3;
36   typedef itk::Image<PixelType, Dim> ImageType;
37
38   ImageType::Pointer input1;
39   ImageType::Pointer input2;
40   input1 = clitk::readImage<ImageType>(args_info.input1_arg, false);
41   input2 = clitk::readImage<ImageType>(args_info.input2_arg, false);
42   
43   typedef itk::ImageRegionIteratorWithIndex<ImageType> IteratorType;
44   IteratorType it = IteratorType(input1, input1->GetLargestPossibleRegion());
45   it.GoToBegin();
46   ImageType::IndexType first1=it.GetIndex();
47   ImageType::IndexType last1=it.GetIndex();
48   bool firstFound = false;
49   while (!it.IsAtEnd()) {
50     if (!firstFound) {
51       if (it.Get() == 1) {
52         firstFound = true;
53         first1 = it.GetIndex();
54       }
55     }
56     else {
57       if (it.Get() == 1) {
58         last1 = it.GetIndex();
59       }
60     }
61     ++it;
62   }
63   
64   // typedef itk::ImageRegionIteratorWithIndex<ImageType> IteratorType;
65   it = IteratorType(input2, input2->GetLargestPossibleRegion());
66   it.GoToBegin();
67   ImageType::IndexType first2=it.GetIndex();
68   ImageType::IndexType last2=it.GetIndex();
69   firstFound = false;
70   while (!it.IsAtEnd()) {
71     if (!firstFound) {
72       if (it.Get() == 1) {
73         firstFound = true;
74         first2 = it.GetIndex();
75       }
76     }
77     else {
78       if (it.Get() == 1) {
79         last2 = it.GetIndex();
80       }
81     }
82     ++it;
83   }
84   
85   std::cout << " --i1 " << first1[2] << " --f1 " << last1[2]
86             << " --i2 " << first2[2] << " --f2 " << last2[2] << std::endl;
87
88   return EXIT_SUCCESS;
89 } // This is the end, my friend
90 //--------------------------------------------------------------------