]> Creatis software - clitk.git/blob - clitkProfileImageGenericFilter.cxx
3c6d6b79ff1f1d4084ddf5cb46a1639b77d73819
[clitk.git] / clitkProfileImageGenericFilter.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 clitkProfileImageGenericFilter_cxx
19 #define clitkProfileImageGenericFilter_cxx
20
21 /* =================================================
22  * @file   clitkProfileImageGenericFilter.cxx
23  * @author Thomas Baudier <thomas.baudier@creatis.insa-lyon.fr>
24  * @date   22 dec 2015
25  *
26  * @brief
27  *
28  ===================================================*/
29
30 #include "clitkProfileImageGenericFilter.h"
31
32 // itk include
33 #include <itkLineIterator.h>
34
35 #include <clitkCommon.h>
36
37 namespace clitk
38 {
39
40 //--------------------------------------------------------------------
41 ProfileImageGenericFilter::ProfileImageGenericFilter():
42   ImageToImageGenericFilter<Self>("ProfileImage")
43 {
44   InitializeImageType<2>();
45   InitializeImageType<3>();
46   InitializeImageType<4>();
47 }
48 //--------------------------------------------------------------------
49
50
51 //--------------------------------------------------------------------
52 template<unsigned int Dim>
53 void ProfileImageGenericFilter::InitializeImageType()
54 {
55   ADD_DEFAULT_IMAGE_TYPES(Dim);
56 }
57 //--------------------------------------------------------------------
58
59
60 //--------------------------------------------------------------------
61 void ProfileImageGenericFilter::SetArgsInfo(const args_info_type & a)
62 {
63   mArgsInfo=a;
64   if (mArgsInfo.verbose_given)
65     SetIOVerbose(mArgsInfo.verbose_flag);
66   if (mArgsInfo.imagetypes_given && mArgsInfo.imagetypes_flag)
67     this->PrintAvailableImageTypes();
68
69   if (mArgsInfo.input_given) {
70     SetInputFilename(mArgsInfo.input_arg);
71   }
72   if (mArgsInfo.output_given) {
73     SetOutputFilename(mArgsInfo.output_arg);
74   }
75 }
76 //--------------------------------------------------------------------
77
78
79 //--------------------------------------------------------------------
80 // Update with the number of dimensions and the pixeltype
81 //--------------------------------------------------------------------
82 template<class InputImageType>
83 void
84 ProfileImageGenericFilter::UpdateWithInputImageType()
85 {
86
87   // Reading input
88   typename InputImageType::Pointer input = this->template GetInput<InputImageType>(0);
89   typedef typename InputImageType::PixelType PixelType;
90   typedef typename InputImageType::IndexType IndexType;
91   typedef itk::Image<uchar, InputImageType::ImageDimension> OutputImageType;
92   
93   //Iterator
94   IndexType pointBegin, pointEnd;
95   
96   for (int i = 0; i < mArgsInfo.point1_given; ++i) {
97     pointBegin[i] = mArgsInfo.point1_arg[i];
98     pointEnd[i] = mArgsInfo.point2_arg[i];
99   }
100   
101   itk::LineConstIterator<InputImageType> itProfile(input, pointBegin, pointEnd);
102   itProfile.GoToBegin();
103   while (!itProfile.IsAtEnd())
104   {
105     
106     ++itProfile;
107   }
108
109   // Filter
110   //typedef itk::BinaryThresholdImageFilter<InputImageType, OutputImageType> BinaryThresholdImageFilterType;
111   //typename BinaryThresholdImageFilterType::Pointer thresholdFilter=BinaryThresholdImageFilterType::New();
112   //thresholdFilter->SetInput(input);
113   /*thresholdFilter->SetInsideValue(mArgsInfo.fg_arg);
114
115   if (mArgsInfo.lower_given) thresholdFilter->SetLowerThreshold(static_cast<PixelType>(mArgsInfo.lower_arg));
116   if (mArgsInfo.upper_given) thresholdFilter->SetUpperThreshold(static_cast<PixelType>(mArgsInfo.upper_arg));
117
118    Three modes :
119      - FG -> only use FG value for pixel in the Foreground (or Inside), keep input values for outside
120      - BG -> only use BG value for pixel in the Background (or Outside), keep input values for inside
121      - both -> use FG and BG (real binary image)
122   
123   if (mArgsInfo.mode_arg == std::string("both")) {
124     thresholdFilter->SetOutsideValue(mArgsInfo.bg_arg);
125     thresholdFilter->Update();
126     typename OutputImageType::Pointer outputImage = thresholdFilter->GetOutput();
127     this->template SetNextOutput<OutputImageType>(outputImage);
128   } else {
129     typename InputImageType::Pointer outputImage;
130     thresholdFilter->SetOutsideValue(0);
131     if (mArgsInfo.mode_arg == std::string("BG")) {
132       typedef itk::MaskImageFilter<InputImageType,OutputImageType> maskFilterType;
133       typename maskFilterType::Pointer maskFilter = maskFilterType::New();
134       maskFilter->SetInput1(input);
135       maskFilter->SetInput2(thresholdFilter->GetOutput());
136       maskFilter->SetOutsideValue(mArgsInfo.bg_arg);
137       maskFilter->Update();
138       outputImage = maskFilter->GetOutput();
139     } else {
140       typedef itk::MaskNegatedImageFilter<InputImageType,OutputImageType> maskFilterType;
141       typename maskFilterType::Pointer maskFilter = maskFilterType::New();
142       maskFilter->SetInput1(input);
143       maskFilter->SetInput2(thresholdFilter->GetOutput());
144       maskFilter->SetOutsideValue(mArgsInfo.fg_arg);
145       maskFilter->Update();
146       outputImage = maskFilter->GetOutput();
147     }
148     // Write/Save results
149     this->template SetNextOutput<InputImageType>(outputImage);
150   }*/
151 }
152 //--------------------------------------------------------------------
153
154
155 }//end clitk
156
157 #endif  //#define clitkProfileImageGenericFilter_cxx