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 clitkProfileImageGenericFilter_cxx
19 #define clitkProfileImageGenericFilter_cxx
21 /* =================================================
22 * @file clitkProfileImageGenericFilter.cxx
23 * @author Thomas Baudier <thomas.baudier@creatis.insa-lyon.fr>
28 ===================================================*/
30 #include "clitkProfileImageGenericFilter.h"
33 #include <itkLineIterator.h>
35 #include <clitkCommon.h>
40 //--------------------------------------------------------------------
41 ProfileImageGenericFilter::ProfileImageGenericFilter():
42 ImageToImageGenericFilter<Self>("ProfileImage")
44 InitializeImageType<2>();
45 InitializeImageType<3>();
46 InitializeImageType<4>();
48 //--------------------------------------------------------------------
51 //--------------------------------------------------------------------
52 template<unsigned int Dim>
53 void ProfileImageGenericFilter::InitializeImageType()
55 ADD_DEFAULT_IMAGE_TYPES(Dim);
57 //--------------------------------------------------------------------
60 //--------------------------------------------------------------------
61 void ProfileImageGenericFilter::SetArgsInfo(const args_info_type & a)
64 if (mArgsInfo.verbose_given)
65 SetIOVerbose(mArgsInfo.verbose_flag);
66 if (mArgsInfo.imagetypes_given && mArgsInfo.imagetypes_flag)
67 this->PrintAvailableImageTypes();
69 if (mArgsInfo.input_given) {
70 SetInputFilename(mArgsInfo.input_arg);
72 if (mArgsInfo.output_given) {
73 SetOutputFilename(mArgsInfo.output_arg);
76 //--------------------------------------------------------------------
79 //--------------------------------------------------------------------
80 // Update with the number of dimensions and the pixeltype
81 //--------------------------------------------------------------------
82 template<class InputImageType>
84 ProfileImageGenericFilter::UpdateWithInputImageType()
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;
94 IndexType pointBegin, pointEnd;
96 for (int i = 0; i < mArgsInfo.point1_given; ++i) {
97 pointBegin[i] = mArgsInfo.point1_arg[i];
98 pointEnd[i] = mArgsInfo.point2_arg[i];
101 itk::LineConstIterator<InputImageType> itProfile(input, pointBegin, pointEnd);
102 itProfile.GoToBegin();
103 while (!itProfile.IsAtEnd())
110 //typedef itk::BinaryThresholdImageFilter<InputImageType, OutputImageType> BinaryThresholdImageFilterType;
111 //typename BinaryThresholdImageFilterType::Pointer thresholdFilter=BinaryThresholdImageFilterType::New();
112 //thresholdFilter->SetInput(input);
113 /*thresholdFilter->SetInsideValue(mArgsInfo.fg_arg);
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));
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)
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);
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();
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();
148 // Write/Save results
149 this->template SetNextOutput<InputImageType>(outputImage);
152 //--------------------------------------------------------------------
157 #endif //#define clitkProfileImageGenericFilter_cxx