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://oncora1.lyon.fnclcc.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 CLITKIMAGERESAMPLE_CXX
19 #define CLITKIMAGERESAMPLE_CXX
21 ------------------------------------------------=
22 * @file clitkImageResample.cxx
23 * @author David Sarrut <David.Sarrut@creatis.insa-lyon.fr>
24 * @date 23 Feb 2008 08:37:53
25 ------------------------------------------------=*/
28 #include "clitkImageResample_ggo.h"
30 #include "clitkImageResampleGenericFilter.h"
32 //--------------------------------------------------------------------
33 int main(int argc, char * argv[])
37 GGO(clitkImageResample, args_info);
40 // Read input image header to check image dimension
41 itk::ImageIOBase::Pointer header = clitk::readImageHeader(args_info.input_arg);
42 unsigned int dim = header->GetNumberOfDimensions();
43 std::string pixelTypeName = header->GetComponentTypeAsString(header->GetComponentType());
45 // Print image info if verbose
46 if (args_info.verbose_flag) {
47 std::cout << "Input image <" << args_info.input_arg << "> is ";
48 clitk::printImageHeader(header, std::cout);
49 std::cout << std::endl;
52 // Get input size/spacing
53 std::vector<int> inputSize;
54 std::vector<double> inputSpacing;
55 inputSize.resize(dim);
56 inputSpacing.resize(dim);
57 for(unsigned int i=0; i<dim; i++) {
58 inputSpacing[i] = header->GetSpacing(i);
59 inputSize[i] = header->GetDimensions(i);
63 std::vector<int> outputSize;
64 std::vector<double> outputSpacing;
65 outputSize.resize(dim);
66 outputSpacing.resize(dim);
69 if (!args_info.size_given && !args_info.spacing_given) {
70 std::cerr << "Please indicate output size or spacing." << std::endl;
75 if (args_info.size_given && args_info.spacing_given) {
76 std::cerr << "Please indicate only output size or spacing, not both." << std::endl;
80 // Size is given and not spacing
81 if (args_info.size_given && !args_info.spacing_given) {
82 if (args_info.size_given != dim) {
83 std::cerr << "Input image is " << dim << "D, please give " << dim << " size numbers." << std::endl;
86 for(unsigned int i=0; i<dim; i++) {
87 if ((args_info.size_arg[i] == -1) || (args_info.size_arg[i]==0))
88 outputSize[i] = inputSize[i];
90 outputSize[i] = args_info.size_arg[i];
91 outputSpacing[i] = inputSize[i]*inputSpacing[i]/outputSize[i];
95 // Spacing is given and not size
96 if (!args_info.size_given && args_info.spacing_given) {
97 if (args_info.spacing_given != dim) {
98 if (args_info.spacing_given == 1) {
99 for(unsigned int i=0; i<dim; i++) outputSpacing[i] = args_info.spacing_arg[0];
101 std::cerr << "Input image is " << dim << "D, please give " << dim << " spacing numbers." << std::endl;
105 for(unsigned int i=0; i<dim; i++) {
106 if ((args_info.spacing_arg[i] == -1) || (args_info.spacing_arg[i]==0))
107 outputSpacing[i] = inputSpacing[i];
109 outputSpacing[i] = args_info.spacing_arg[i];
113 for(unsigned int i=0; i<dim; i++)
114 outputSize[i] = (int)lrint(inputSize[i]*inputSpacing[i]/outputSpacing[i]);
117 if (args_info.verbose_flag) {
118 std::cout << "Output image will be : " << std::endl;
120 DDV(outputSpacing,dim);
123 // Get sigma option for Gaussian filter
124 std::vector<double> sigma;
125 sigma.resize(args_info.gauss_given);
126 std::copy(args_info.gauss_arg, args_info.gauss_arg+args_info.gauss_given, sigma.begin());
127 if (args_info.gauss_given) {
128 if (args_info.gauss_given != dim) {
129 if (args_info.gauss_given == 1) {
131 for(unsigned int i=0; i<dim; i++) sigma[i] = args_info.gauss_arg[0];
133 std::cerr << "Input image is " << dim << "D, please give " << dim << " sigma numbers for gaussian filter." << std::endl;
140 clitk::ImageResampleGenericFilter::Pointer filter = clitk::ImageResampleGenericFilter::New();
141 filter->SetInputFilename(args_info.input_arg);
142 filter->SetOutputSize(outputSize);
143 filter->SetOutputSpacing(outputSpacing);
144 filter->SetInterpolationName(args_info.interp_arg);
145 filter->SetBSplineOrder(args_info.order_arg);
146 filter->SetBLUTSampling(args_info.sampling_arg);
147 if (args_info.gauss_given)
148 filter->SetGaussianSigma(sigma);
149 filter->SetOutputFilename(args_info.output_arg);
154 // this is the end my friend
157 //--------------------------------------------------------------------
159 #endif /* end #define CLITKIMAGERESAMPLE_CXX */