+++ /dev/null
-/*=========================================================================
- Program: vv http://www.creatis.insa-lyon.fr/rio/vv
-
- Authors belong to:
- - University of LYON http://www.universite-lyon.fr/
- - Léon Bérard cancer center http://oncora1.lyon.fnclcc.fr
- - CREATIS CNRS laboratory http://www.creatis.insa-lyon.fr
-
- This software is distributed WITHOUT ANY WARRANTY; without even
- the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
- PURPOSE. See the copyright notices for more information.
-
- It is distributed under dual licence
-
- - BSD See included LICENSE.txt file
- - CeCILL-B http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
-======================================================================-====*/
-#ifndef CLITKIMAGERESAMPLE_CXX
-#define CLITKIMAGERESAMPLE_CXX
-/**
- ------------------------------------------------=
- * @file clitkImageResample.cxx
- * @author David Sarrut <David.Sarrut@creatis.insa-lyon.fr>
- * @date 23 Feb 2008 08:37:53
- ------------------------------------------------=*/
-
-// clitk
-#include "clitkImageResample_ggo.h"
-#include "clitkIO.h"
-#include "clitkImageResampleGenericFilter.h"
-
-//--------------------------------------------------------------------
-int main(int argc, char * argv[])
-{
-
- // Init command line
- GGO(clitkImageResample, args_info);
- CLITK_INIT;
-
- // Read input image header to check image dimension
- itk::ImageIOBase::Pointer header = clitk::readImageHeader(args_info.input_arg);
- unsigned int dim = header->GetNumberOfDimensions();
- std::string pixelTypeName = header->GetComponentTypeAsString(header->GetComponentType());
-
- // Print image info if verbose
- if (args_info.verbose_flag) {
- std::cout << "Input image <" << args_info.input_arg << "> is ";
- clitk::printImageHeader(header, std::cout);
- std::cout << std::endl;
- }
-
- // Get input size/spacing
- std::vector<int> inputSize;
- std::vector<double> inputSpacing;
- inputSize.resize(dim);
- inputSpacing.resize(dim);
- for(unsigned int i=0; i<dim; i++) {
- inputSpacing[i] = header->GetSpacing(i);
- inputSize[i] = header->GetDimensions(i);
- }
-
- // Get options
- std::vector<int> outputSize;
- std::vector<double> outputSpacing;
- outputSize.resize(dim);
- outputSpacing.resize(dim);
-
- // Check options
- if (!args_info.size_given && !args_info.spacing_given) {
- std::cerr << "Please indicate output size or spacing." << std::endl;
- exit(0);
- }
-
- // Check options
- if (args_info.size_given && args_info.spacing_given) {
- std::cerr << "Please indicate only output size or spacing, not both." << std::endl;
- exit(0);
- }
-
- // Size is given and not spacing
- if (args_info.size_given && !args_info.spacing_given) {
- if (args_info.size_given != dim) {
- std::cerr << "Input image is " << dim << "D, please give " << dim << " size numbers." << std::endl;
- exit(0);
- }
- for(unsigned int i=0; i<dim; i++) {
- if ((args_info.size_arg[i] == -1) || (args_info.size_arg[i]==0))
- outputSize[i] = inputSize[i];
- else
- outputSize[i] = args_info.size_arg[i];
- outputSpacing[i] = inputSize[i]*inputSpacing[i]/outputSize[i];
- }
- }
-
- // Spacing is given and not size
- if (!args_info.size_given && args_info.spacing_given) {
- if (args_info.spacing_given != dim) {
- if (args_info.spacing_given == 1) {
- for(unsigned int i=0; i<dim; i++) outputSpacing[i] = args_info.spacing_arg[0];
- } else {
- std::cerr << "Input image is " << dim << "D, please give " << dim << " spacing numbers." << std::endl;
- exit(0);
- }
- } else {
- for(unsigned int i=0; i<dim; i++) {
- if ((args_info.spacing_arg[i] == -1) || (args_info.spacing_arg[i]==0))
- outputSpacing[i] = inputSpacing[i];
- else
- outputSpacing[i] = args_info.spacing_arg[i];
-
- }
- }
- for(unsigned int i=0; i<dim; i++)
- outputSize[i] = (int)lrint(inputSize[i]*inputSpacing[i]/outputSpacing[i]);
- }
-
- if (args_info.verbose_flag) {
- std::cout << "Output image will be : " << std::endl;
- DDV(outputSize,dim);
- DDV(outputSpacing,dim);
- }
-
- // Get sigma option for Gaussian filter
- std::vector<double> sigma;
- sigma.resize(args_info.gauss_given);
- std::copy(args_info.gauss_arg, args_info.gauss_arg+args_info.gauss_given, sigma.begin());
- if (args_info.gauss_given) {
- if (args_info.gauss_given != dim) {
- if (args_info.gauss_given == 1) {
- sigma.resize(dim);
- for(unsigned int i=0; i<dim; i++) sigma[i] = args_info.gauss_arg[0];
- } else {
- std::cerr << "Input image is " << dim << "D, please give " << dim << " sigma numbers for gaussian filter." << std::endl;
- exit(0);
- }
- }
- }
-
- // Create a filter
- clitk::ImageResampleGenericFilter::Pointer filter = clitk::ImageResampleGenericFilter::New();
- filter->SetInputFilename(args_info.input_arg);
- filter->SetOutputSize(outputSize);
- filter->SetOutputSpacing(outputSpacing);
- filter->SetInterpolationName(args_info.interp_arg);
- filter->SetBSplineOrder(args_info.order_arg);
- filter->SetBLUTSampling(args_info.sampling_arg);
- if (args_info.gauss_given)
- filter->SetGaussianSigma(sigma);
- filter->SetOutputFilename(args_info.output_arg);
-
- // Go !
- filter->Update();
-
- // this is the end my friend
- return 0;
-}// end main
-//--------------------------------------------------------------------
-
-#endif /* end #define CLITKIMAGERESAMPLE_CXX */
+++ /dev/null
-#File clitkImageResample.ggo
-package "clitkImageResample"
-version "1.0"
-purpose "Resample an image. You can specify the interpolation, you can apply a Gaussian filter before."
-
-option "config" - "Config file" string no
-option "input" i "Input image filename" string yes
-option "output" o "Output image filename" string yes
-option "verbose" v "Verbose" flag off
-option "interp" - "Interpolation type: {nn, linear, bspline, blut}" string no default="nn"
-option "order" b "BSpline ordre (range 0-5)" int no default="3"
-option "sampling" s "BLUT sampling value" int no default="30"
-option "size" - "Number of pixels of each coordonate" int no multiple default="0"
-option "spacing" - "Spacing in mm between pixels" float no multiple default="0.0"
-option "gauss" g "Apply Gaussian before (sigma in mm) ; no Gaussian if not given" float no multiple default="1.0"
-option "default" d "Default pixel value" float no default = "0.0"
-
+++ /dev/null
-/*=========================================================================
- Program: vv http://www.creatis.insa-lyon.fr/rio/vv
-
- Authors belong to:
- - University of LYON http://www.universite-lyon.fr/
- - Léon Bérard cancer center http://oncora1.lyon.fnclcc.fr
- - CREATIS CNRS laboratory http://www.creatis.insa-lyon.fr
-
- This software is distributed WITHOUT ANY WARRANTY; without even
- the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
- PURPOSE. See the copyright notices for more information.
-
- It is distributed under dual licence
-
- - BSD See included LICENSE.txt file
- - CeCILL-B http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
-======================================================================-====*/
-#ifndef CLITKIMAGERESAMPLEGENERICFILTER2_CXX
-#define CLITKIMAGERESAMPLEGENERICFILTER2_CXX
-/**
- -------------------------------------------------------------------
- * @file clitkImageResampleGenericFilter.cxx
- * @author David Sarrut <David.Sarrut@creatis.insa-lyon.fr>
- * @date 23 Feb 2008 08:37:53
-
- * @brief
-
- -------------------------------------------------------------------*/
-
-#include "clitkImageResampleGenericFilter.h"
-
-// itk include
-#include "itkImage.h"
-#include "itkImageFileReader.h"
-#include "itkImageSeriesReader.h"
-#include "itkImageFileWriter.h"
-#include "itkRecursiveGaussianImageFilter.h"
-#include "itkResampleImageFilter.h"
-#include "itkAffineTransform.h"
-#include "itkNearestNeighborInterpolateImageFunction.h"
-#include "itkWindowedSincInterpolateImageFunction.h"
-#include "itkLinearInterpolateImageFunction.h"
-#include "itkBSplineInterpolateImageFunction.h"
-#include "itkBSplineInterpolateImageFunctionWithLUT.h"
-#include "itkCommand.h"
-
-//--------------------------------------------------------------------
-clitk::ImageResampleGenericFilter::ImageResampleGenericFilter():
- ImageToImageGenericFilter<Self>("ImageResample")
-{
- mApplyGaussianFilterBefore = false;
- mDefaultPixelValue = 0.0;
- mInterpolatorName = "NN";
- mBSplineOrder=3;
- InitializeImageTypeWithDim<2>();
- InitializeImageTypeWithDim<3>();
- InitializeImageTypeWithDim<4>();
-}
-//--------------------------------------------------------------------
-
-
-//--------------------------------------------------------------------
-template<unsigned int Dim>
-void clitk::ImageResampleGenericFilter::InitializeImageTypeWithDim()
-{
- ADD_DEFAULT_IMAGE_TYPES(Dim);
-}
-//--------------------------------------------------------------------
-
-
-//--------------------------------------------------------------------
-template<class InputImageType>
-void clitk::ImageResampleGenericFilter::UpdateWithInputImageType()
-{
-
- // Some typedefs
- typedef typename InputImageType::SizeType SizeType;
- typedef typename InputImageType::SpacingType SpacingType;
- typedef typename InputImageType::PointType PointType;
- typedef typename InputImageType::PixelType PixelType;
- static unsigned int dim = InputImageType::ImageDimension;
-
- // Reading input
- typename InputImageType::Pointer input = this->GetInput<InputImageType>(0);
-
- // Warning
- if (!std::numeric_limits<PixelType>::is_signed) {
- if ((mInterpolatorName == "bspline") || (mInterpolatorName == "blut")) {
- std::cerr << "Warning : input pixel type is not signed, use bspline interpolation at your own risk ..." << std::endl;
- }
- }
-
- // Check options
- if (mOutputSize.size() != dim) {
- std::cerr << "Please set size with " << dim << " dimensions." << std::endl;
- return;
- }
- if (mOutputSpacing.size() != dim) {
- std::cerr << "Please set spacing with " << dim << " dimensions." << std::endl;
- return;
- }
- mOutputOrigin.resize(dim);
-
- if (mApplyGaussianFilterBefore && mSigma.size() != dim) {
- std::cerr << "Please set sigma with " << dim << " dimensions." << std::endl;
- return;
- }
-
- // Create Image Filter
- typedef itk::ResampleImageFilter<InputImageType,InputImageType> FilterType;
- typename FilterType::Pointer filter = FilterType::New();
-
- // Instance of the transform object to be passed to the resample
- // filter. By default, identity transform is applied
- typedef itk::AffineTransform<double, InputImageType::ImageDimension> TransformType;
- typename TransformType::Pointer transform = TransformType::New();
- filter->SetTransform(transform);
-
- // Set filter's parameters
- SizeType outputSize;
- SpacingType outputSpacing;
- PointType outputOrigin;
- for(unsigned int i=0; i<InputImageType::ImageDimension; i++) {
- outputSize[i] = mOutputSize[i];
- outputSpacing[i] = mOutputSpacing[i];
- outputOrigin[i] = input->GetOrigin()[i];
- }
-
- filter->SetSize(outputSize);
- filter->SetOutputSpacing(outputSpacing);
- filter->SetOutputOrigin(outputOrigin);
- filter->SetDefaultPixelValue(static_cast<PixelType>(mDefaultPixelValue));//DS TODO//JV comme ça?
-
- // Select interpolator
- if (mInterpolatorName == "nn") {
- typedef itk::NearestNeighborInterpolateImageFunction<InputImageType, double> InterpolatorType;
- typename InterpolatorType::Pointer interpolator = InterpolatorType::New();
- filter->SetInterpolator(interpolator);
- } else {
- if (mInterpolatorName == "linear") {
- typedef itk::LinearInterpolateImageFunction<InputImageType, double> InterpolatorType;
- typename InterpolatorType::Pointer interpolator = InterpolatorType::New();
- filter->SetInterpolator(interpolator);
- } else {
- if (mInterpolatorName == "windowed sinc") {
- typedef itk::WindowedSincInterpolateImageFunction<InputImageType, 4> InterpolatorType;
- typename InterpolatorType::Pointer interpolator = InterpolatorType::New();
- filter->SetInterpolator(interpolator);
- } else {
- if (mInterpolatorName == "bspline") {
- typedef itk::BSplineInterpolateImageFunction<InputImageType, double> InterpolatorType;
- typename InterpolatorType::Pointer interpolator = InterpolatorType::New();
- interpolator->SetSplineOrder(mBSplineOrder);
- filter->SetInterpolator(interpolator);
- } else {
- if (mInterpolatorName == "blut") {
- typedef itk::BSplineInterpolateImageFunctionWithLUT<InputImageType, double> InterpolatorType;
- typename InterpolatorType::Pointer interpolator = InterpolatorType::New();
- interpolator->SetSplineOrder(mBSplineOrder);
- interpolator->SetLUTSamplingFactor(mSamplingFactors[0]);
- filter->SetInterpolator(interpolator);
- } else {
- std::cerr << "Sorry, I do not know the interpolator '" << mInterpolatorName
- << "'. Known interpolators are : nn, linear, bspline, blut" << std::endl;
- exit(0);
- }
- }
- }
- }
- }
-
- // Build initial Gaussian bluring (if needed)
- typedef itk::RecursiveGaussianImageFilter<InputImageType, InputImageType> GaussianFilterType;
- std::vector<typename GaussianFilterType::Pointer> gaussianFilters;
- if (mApplyGaussianFilterBefore) {
- for(unsigned int i=0; i<InputImageType::ImageDimension; i++) {
- // Create filter
- gaussianFilters.push_back(GaussianFilterType::New());
- // Set options
- gaussianFilters[i]->SetDirection(i);
- gaussianFilters[i]->SetOrder(GaussianFilterType::ZeroOrder);
- gaussianFilters[i]->SetNormalizeAcrossScale(false);
- gaussianFilters[i]->SetSigma(mSigma[i]); // in millimeter !
- // Set input
- if (i==0) gaussianFilters[i]->SetInput(input);
- else gaussianFilters[i]->SetInput(gaussianFilters[i-1]->GetOutput());
- }
- filter->SetInput(gaussianFilters[InputImageType::ImageDimension-1]->GetOutput());
- } else {
- filter->SetInput(input);
- }
-
- // Go !
- try {
- filter->Update();
- } catch( itk::ExceptionObject & err ) {
- std::cerr << "Error while filtering " << m_InputFilenames[0].c_str()
- << " " << err << std::endl;
- exit(0);
- }
-
- // Get result
- typename InputImageType::Pointer outputImage = filter->GetOutput();
-
- // Write/save results
- this->SetNextOutput<InputImageType>(outputImage);
-
-}
-//--------------------------------------------------------------------
-
-
-//--------------------------------------------------------------------
-void clitk::ImageResampleGenericFilter::SetOutputSize(const std::vector<int> & size)
-{
- mOutputSize.resize(size.size());
- std::copy(size.begin(), size.end(), mOutputSize.begin());
-}
-//--------------------------------------------------------------------
-
-//--------------------------------------------------------------------
-void clitk::ImageResampleGenericFilter::SetOutputSpacing(const std::vector<double> & spacing)
-{
- mOutputSpacing.resize(spacing.size());
- std::copy(spacing.begin(), spacing.end(), mOutputSpacing.begin());
-}
-//--------------------------------------------------------------------
-
-//--------------------------------------------------------------------
-void clitk::ImageResampleGenericFilter::SetInterpolationName(const std::string & inter)
-{
- mInterpolatorName = inter;
-}
-//--------------------------------------------------------------------
-
-//--------------------------------------------------------------------
-void clitk::ImageResampleGenericFilter::SetGaussianSigma(const std::vector<double> & sigma)
-{
- mApplyGaussianFilterBefore = true;
- mSigma.resize(sigma.size());
- std::copy(sigma.begin(), sigma.end(), mSigma.begin());
-}
-//--------------------------------------------------------------------
-
-#endif
-
+++ /dev/null
-/*=========================================================================
- Program: vv http://www.creatis.insa-lyon.fr/rio/vv
-
- Authors belong to:
- - University of LYON http://www.universite-lyon.fr/
- - Léon Bérard cancer center http://oncora1.lyon.fnclcc.fr
- - CREATIS CNRS laboratory http://www.creatis.insa-lyon.fr
-
- This software is distributed WITHOUT ANY WARRANTY; without even
- the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
- PURPOSE. See the copyright notices for more information.
-
- It is distributed under dual licence
-
- - BSD See included LICENSE.txt file
- - CeCILL-B http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
-======================================================================-====*/
-
-#ifndef CLITKIMAGERESAMPLEGENERICFILTER_H
-#define CLITKIMAGERESAMPLEGENERICFILTER_H
-
-// clitk include
-#include "clitkImageToImageGenericFilter.h"
-
-namespace clitk {
-
- //--------------------------------------------------------------------
- class ImageResampleGenericFilter:
- public ImageToImageGenericFilter<ImageResampleGenericFilter> {
-
- public:
- // constructor
- ImageResampleGenericFilter();
-
- // Types
- typedef ImageResampleGenericFilter Self;
- typedef itk::SmartPointer<Self> Pointer;
- typedef itk::SmartPointer<const Self> ConstPointer;
-
- // New
- itkNewMacro(Self);
-
- void SetOutputSize(const std::vector<int> & size);
- void SetOutputSpacing(const std::vector<double> & spacing);
- void SetGaussianSigma(const std::vector<double> & sigma);
- void SetInterpolationName(const std::string & inter);
- void SetDefaultPixelValue(double dpv) { mDefaultPixelValue = dpv;}
- void SetBSplineOrder(int o) { mBSplineOrder = o; }
- void SetBLUTSampling(int b) { mSamplingFactors.resize(1); mSamplingFactors[0] = b; }
-
- //--------------------------------------------------------------------
- template<class InputImageType> void UpdateWithInputImageType();
-
- protected:
- //--------------------------------------------------------------------
- std::string mInterpolatorName;
- std::vector<int> mOutputSize;
- std::vector<double> mOutputSpacing;
- std::vector<double> mOutputOrigin;
- double mDefaultPixelValue;
- bool mApplyGaussianFilterBefore;
- std::vector<double> mSigma;
- int mBSplineOrder;
- std::vector<int> mSamplingFactors;
-
- //--------------------------------------------------------------------
- template<unsigned int Dim> void InitializeImageTypeWithDim();
-
- }; // end class ImageResampleGenericFilter
- //--------------------------------------------------------------------
-
- //#include "clitkImageResampleGenericFilter.txx"
-
-} // end namespace
-//--------------------------------------------------------------------
-
-#endif /* end #define CLITKIMAGERESAMPLEGENERICFILTER_H */
-
+++ /dev/null
-/*=========================================================================
- Program: vv http://www.creatis.insa-lyon.fr/rio/vv
-
- Authors belong to:
- - University of LYON http://www.universite-lyon.fr/
- - Léon Bérard cancer center http://oncora1.lyon.fnclcc.fr
- - CREATIS CNRS laboratory http://www.creatis.insa-lyon.fr
-
- This software is distributed WITHOUT ANY WARRANTY; without even
- the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
- PURPOSE. See the copyright notices for more information.
-
- It is distributed under dual licence
-
- - BSD See included LICENSE.txt file
- - CeCILL-B http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
-======================================================================-====*/
-#ifndef CLITKIMAGERESAMPLEGENERICFILTER_TXX
-#define CLITKIMAGERESAMPLEGENERICFILTER_TXX
-/**
- ------------------------------------------------=
- * @file clitkImageResampleGenericFilter.txx
- * @author David Sarrut <david.sarrut@creatis.insa-lyon.fr>
- * @date 23 Feb 2008 08:40:11
- *
- * @brief
- *
- *
- ------------------------------------------------=*/
-
-
-#endif /* end #define CLITKIMAGERESAMPLEGENERICFILTER_TXX */
-