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 -------------------------------------------------------------------------*/
13 #ifndef CLITKIMAGEARITHM_CXX
14 #define CLITKIMAGEARITHM_CXX
17 -------------------------------------------------
18 * @file clitkImageArithm.cxx
19 * @author David Sarrut <David.Sarrut@creatis.insa-lyon.fr>
20 * @date 23 Feb 2008 08:37:53
21 -------------------------------------------------*/
24 #include "clitkImageArithm_ggo.h"
25 #include "clitkImageArithmGenericFilter.h"
28 //--------------------------------------------------------------------
29 int main(int argc, char * argv[]) {
32 GGO(clitkImageArithm, args_info);
35 // Check that we have either the 2nd image or the scalar
36 if ((args_info.input2_given) && (args_info.scalar_given)) {
37 std::cerr << "ERROR : you cannot provide both --scalar and --input2 option" << std::endl;
40 if ((!args_info.input2_given) && (!args_info.scalar_given)) {
41 if (args_info.operation_arg < 5) {
42 std::cerr << "Such operation need the --scalar option." << std::endl;
47 // Read input image header1 to check image dimension
48 itk::ImageIOBase::Pointer header1 = clitk::readImageHeader(args_info.input1_arg);
49 unsigned int dim1 = header1->GetNumberOfDimensions();
50 std::string pixelTypeName = header1->GetComponentTypeAsString(header1->GetComponentType());
52 // Options for arithm operation between 2 images
53 if (args_info.input2_given) {
55 itk::ImageIOBase::Pointer header2 = clitk::readImageHeader(args_info.input2_arg);
56 unsigned int dim2 = header2->GetNumberOfDimensions();
57 std::string pixelTypeName2 = header2->GetComponentTypeAsString(header1->GetComponentType());
61 std::cerr << "Images should have the same dimension : " <<std::endl;
62 std::cerr << "Dim input1 = " << dim1 << std::endl;
63 std::cerr << "Dim input2 = " << dim2 << std::endl;
67 // Check same type of pixel in both images
68 if (pixelTypeName2 != pixelTypeName) {
69 std::cerr << "Input images do not have the same pixel type: " <<std::endl;
70 std::cerr << "Type input1 = " << pixelTypeName << std::endl;
71 std::cerr << "Type input2 = " << pixelTypeName2 << std::endl;
75 // Check same X,Y dimensions in both images
76 for(int i=0; i<2; i++) {
77 if ( header1->GetDimensions(i) != header2->GetDimensions(i) ) {
78 std::cerr << "ERROR: input images should have same X and Y size. " << std::endl;
79 std::cerr << "Dimensions X and Y of input1: = " << header1->GetDimensions(0) <<" "<< header1->GetDimensions(1)<< std::endl;
80 std::cerr << "Dimensions X and Y of input2: = " << header2->GetDimensions(0) <<" "<< header2->GetDimensions(1)<< std::endl;
85 if (header1->GetDimensions(2) < header2->GetDimensions(2)) {
86 std::cerr << "ERROR: Z size in input1 is greater than in input2. " << std::endl;
87 std::cerr << "Size input1 : " << header1->GetDimensions(0) << " " << header1->GetDimensions(1)<< " " << header1->GetDimensions(2) << std::endl;
88 std::cerr << "Size input2 : " << header2->GetDimensions(0) << " " << header2->GetDimensions(1)<< " " << header2->GetDimensions(2) << std::endl;
91 } //end if operation between 2 images
93 // Creation of a generic filter
94 clitk::ImageArithmGenericFilter::Pointer filter = clitk::ImageArithmGenericFilter::New();
95 filter->AddInputFilename(args_info.input1_arg);
96 if (args_info.input2_given) filter->AddInputFilename(args_info.input2_arg);
97 else filter->SetScalar(args_info.scalar_arg);
98 //if (args_info.binary_given) filter->SetBinaryMaskFilename(args_info.binary_arg);
99 filter->SetTypeOfOperation(args_info.operation_arg);
100 filter->SetDefaultPixelValue(args_info.pixelValue_arg);
101 filter->SetOutputFilename(args_info.output_arg);
106 // this is the end my friend
110 #endif //define CLITKIMAGEARITHM_CXX