1 /*=========================================================================
3 Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
4 l'Image). All rights reserved. See Doc/License.txt or
5 http://www.creatis.insa-lyon.fr/Public/Gdcm/License.html for details.
7 This software is distributed WITHOUT ANY WARRANTY; without even
8 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
9 PURPOSE. See the above copyright notices for more information.
11 =========================================================================*/
14 -------------------------------------------------------------------
15 * @file clitkGuerreroVentilationGenericFilter.cxx
16 * @author Joël Schaerer
20 -------------------------------------------------------------------*/
22 #include "clitkGuerreroVentilationGenericFilter.h"
23 #include <itkBinaryGuerreroFilter.h>
24 #include <itkImageDuplicator.h>
25 //--------------------------------------------------------------------
26 clitk::GuerreroVentilationGenericFilter::GuerreroVentilationGenericFilter()
30 //--------------------------------------------------------------------
32 //--------------------------------------------------------------------
33 void clitk::GuerreroVentilationGenericFilter::Update () {
35 // Determine dim, pixel type, number of components
36 this->GetInputImageDimensionAndPixelType(mDim,mPixelTypeName,mNbOfComponents);
38 // Switch by dimension
39 if (mDim == 3) { Update_WithDim<3>(); return; }
40 if (mDim == 2) { Update_WithDim<2>(); return; }
41 std::cerr << "Error, dimension of input image is " << mDim << ", but I only work with 2 or 3." << std::endl;
44 //--------------------------------------------------------------------
46 //This is where you put the actual implementation
49 #include <itkExtractImageFilter.h>
52 //--------------------------------------------------------------------
53 template<unsigned int Dim>
54 void clitk::GuerreroVentilationGenericFilter::Update_WithDim() {
55 #define TRY_TYPE(TYPE) \
56 if (IsSameType<TYPE>(mPixelTypeName)) { Update_WithDimAndPixelType<Dim, TYPE>(); return; }
57 // TRY_TYPE(signed char);
62 // TRY_TYPE(unsigned int);
67 std::string list = CreateListOfTypes<uchar, short, ushort, int, uint, float, double>();
68 std::cerr << "Error, I don't know the type '" << mPixelTypeName << "' for the input image '"
69 << mInputFilenames[0] << "'." << std::endl << "Known types are " << list << std::endl;
72 //--------------------------------------------------------------------
74 //--------------------------------------------------------------------
75 template<unsigned int Dim, class PixelType>
76 void clitk::GuerreroVentilationGenericFilter::Update_WithDimAndPixelType() {
79 assert(mInputFilenames.size() == 2);
80 typedef itk::Image<PixelType,Dim> ImageType;
81 typedef itk::Image<float,Dim> OutputImageType;
82 typename ImageType::Pointer input = clitk::readImage<ImageType>(mInputFilenames[0], mIOVerbose);
83 typename ImageType::Pointer ref = clitk::readImage<ImageType>(mInputFilenames[1], mIOVerbose);
86 typedef itk::BinaryGuerreroFilter<ImageType,ImageType,OutputImageType> GFilterType;
87 typename GFilterType::Pointer filter = GFilterType::New();
88 filter->SetInput1(ref);
89 filter->SetInput2(input);
90 filter->SetBloodCorrectionFactor(blood_mass_factor);
91 filter->SetUseCorrectFormula(use_correct_formula);
93 this->SetNextOutput<OutputImageType>(filter->GetOutput());
94 //clitk::writeImage<OutputImageType>(filter->GetOutput(), mOutputFilename, mIOVerbose);
95 //std::cout << "Warning: removed " << filter->GetFunctor().aberant_voxels << " aberant voxels from the ventilation image"