X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=tools%2FclitkCropImageGenericFilter.cxx;h=b062976b678b4dac3abe72804dd6dbda572c81aa;hb=fdc1613169b9725128ad19aaa4c4a5c39f2920d7;hp=7e37c1cfaf984660eeba18d666c1c63bbba40d10;hpb=a26cd8a19e1b9ad8344ab501436045f171a73713;p=clitk.git diff --git a/tools/clitkCropImageGenericFilter.cxx b/tools/clitkCropImageGenericFilter.cxx old mode 100755 new mode 100644 index 7e37c1c..b062976 --- a/tools/clitkCropImageGenericFilter.cxx +++ b/tools/clitkCropImageGenericFilter.cxx @@ -3,7 +3,7 @@ Authors belong to: - University of LYON http://www.universite-lyon.fr/ - - Léon Bérard cancer center http://oncora1.lyon.fnclcc.fr + - Léon Bérard cancer center http://www.centreleonberard.fr - CREATIS CNRS laboratory http://www.creatis.insa-lyon.fr This software is distributed WITHOUT ANY WARRANTY; without even @@ -14,7 +14,7 @@ - BSD See included LICENSE.txt file - CeCILL-B http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html -======================================================================-====*/ +===========================================================================**/ #ifndef clitkCropImageGenericFilter_cxx #define clitkCropImageGenericFilter_cxx @@ -37,35 +37,131 @@ namespace clitk //----------------------------------------------------------- // Constructor //----------------------------------------------------------- - CropImageGenericFilter::CropImageGenericFilter() + CropImageGenericFilter::CropImageGenericFilter(): + ImageToImageGenericFilter("CropImage") { - m_Verbose=false; - m_InputFileName=""; + cmdline_parser_clitkCropImage_init(&mArgsInfo); + InitializeImageType<2>(); + InitializeImageType<3>(); + InitializeImageType<4>(); } - - //----------------------------------------------------------- - // Update - //----------------------------------------------------------- - void CropImageGenericFilter::Update() + //-------------------------------------------------------------------- + template + void clitk::CropImageGenericFilter::InitializeImageType() { - // Read the Dimension and PixelType - int Dimension, Components; - std::string PixelType; - ReadImageDimensionAndPixelType(m_InputFileName, Dimension, PixelType, Components); + ADD_DEFAULT_IMAGE_TYPES(Dim); + //ADD_IMAGE_TYPE(Dim, uchar); + //ADD_IMAGE_TYPE(Dim, short); + // ADD_IMAGE_TYPE(Dim, uint); + // ADD_IMAGE_TYPE(Dim, ulong); + // ADD_IMAGE_TYPE(Dim, int); + // ADD_IMAGE_TYPE(Dim, float); + } + //-------------------------------------------------------------------- + //-------------------------------------------------------------------- + void clitk::CropImageGenericFilter::SetArgsInfo(const args_info_type& a) + { + mArgsInfo=a; + SetIOVerbose(mArgsInfo.verbose_flag); + if (mArgsInfo.imagetypes_flag) this->PrintAvailableImageTypes(); + if (mArgsInfo.input_given) AddInputFilename(mArgsInfo.input_arg); + if (mArgsInfo.output_given) AddOutputFilename(mArgsInfo.output_arg); + } + //-------------------------------------------------------------------- + + //-------------------------------------------------------------------- + // Update with the number of dimensions and the pixeltype + //-------------------------------------------------------------------- + template + void clitk::CropImageGenericFilter::UpdateWithInputImageType() + { + // Reading input + typename ImageType::Pointer input = this->template GetInput(0); + + // Check options + if (mArgsInfo.BG_given && mArgsInfo.like_given) + clitkExceptionMacro("Do not use --BG and --like at the same time"); + + // Prepare output + typename ImageType::Pointer output; - // Call UpdateWithDim - if(Dimension==2) UpdateWithDim<2>(PixelType, Components); - else if(Dimension==3) UpdateWithDim<3>(PixelType, Components); - else if (Dimension==4)UpdateWithDim<4>(PixelType, Components); - else - { - std::cout<<"Error, Only for 2, 3 or 4 Dimensions!!!"< FilterType; + typename FilterType::Pointer filter = FilterType::New(); + filter->SetInput(input); + filter->SetBackgroundValue(mArgsInfo.BG_arg); + filter->Update(); + output = filter->GetOutput(); + } + else { + // ------------------------------------------------ + if (mArgsInfo.like_given) { // CropLike filter + if (mArgsInfo.boundingBox_given) + clitkExceptionMacro("Do not use --like and --boundingBox at the same time"); + if (mArgsInfo.lower_given) + clitkExceptionMacro("Do not use --like and --lower at the same time"); + if (mArgsInfo.upper_given) + clitkExceptionMacro("Do not use --like and --upper at the same time"); + typedef clitk::CropLikeImageFilter FilterType; + typename FilterType::Pointer filter = FilterType::New(); + filter->SetInput(input); + filter->SetCropLikeFilename(mArgsInfo.like_arg); + filter->SetBackgroundValue(mArgsInfo.BGLike_arg); + filter->Update(); + output = filter->GetOutput(); } - } + else { + // ------------------------------------------------ + typename ImageType::SizeType lSize; + typename ImageType::SizeType uSize; + if (mArgsInfo.boundingBox_given) { + for(unsigned int i=0; iGetLargestPossibleRegion().GetSize()[i]-mArgsInfo.boundingBox_arg[2*i+1]-1; + } + } + else { + if (mArgsInfo.lower_given) { + for(unsigned int i=0; i(mArgsInfo.lower_arg[i]); + } + else lSize.Fill(0); + if (mArgsInfo.upper_given) { + for(unsigned int i=0; i(mArgsInfo.upper_arg[i]); + } + else uSize.Fill(0); + } + typedef itk::CropImageFilter CropImageFilterType; + typename CropImageFilterType::Pointer filter=CropImageFilterType::New(); + filter->SetInput(input); + filter->SetLowerBoundaryCropSize(lSize); + filter->SetUpperBoundaryCropSize(uSize); + filter->Update(); + output = filter->GetOutput(); + } + } + // Force origin if needed + if (mArgsInfo.origin_flag) { + typename ImageType::PointType origin; + origin.Fill(itk::NumericTraits::Zero); + output->SetOrigin(origin); + } + + // Write/Save results + this->template SetNextOutput(output); + } + //-------------------------------------------------------------------- } //end clitk