+ // ------------------------------------------------
+ if (mArgsInfo.BG_given) { // AutoCrop filter
+ if (mArgsInfo.boundingBox_given)
+ clitkExceptionMacro("Do not use --BG and --boundingBox at the same time");
+ if (mArgsInfo.lower_given)
+ clitkExceptionMacro("Do not use --BG and --lower at the same time");
+ if (mArgsInfo.upper_given)
+ clitkExceptionMacro("Do not use --BG and --upper at the same time");
+ typedef clitk::AutoCropFilter<ImageType> 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<ImageType> 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.verbose_flag) std::cout << "input region " << input_region << std::endl;
+ if (mArgsInfo.boundingBox_given) {
+ for(unsigned int i=0; i<ImageType::ImageDimension; i++) {
+ lSize[i] = mArgsInfo.boundingBox_arg[2*i];
+ uSize[i] = input_region.GetSize()[i]-mArgsInfo.boundingBox_arg[2*i+1]-1;
+ }
+ }
+ else {
+ if (mArgsInfo.lower_given) {
+ for(unsigned int i=0; i<ImageType::ImageDimension; i++)
+ lSize[i]=static_cast<unsigned int >(mArgsInfo.lower_arg[i]);
+ }
+ else lSize.Fill(0);
+ if (mArgsInfo.upper_given) {
+ for(unsigned int i=0; i<ImageType::ImageDimension; i++)
+ uSize[i]=static_cast<unsigned int >(mArgsInfo.upper_arg[i]);
+ }
+ else uSize.Fill(0);
+ }
+
+ if (mArgsInfo.verbose_flag) {
+ std::cout << "lower " << lSize << " upper " << uSize << std::endl;
+ }
+
+ typedef itk::CropImageFilter<ImageType, ImageType> CropImageFilterType;
+ typename CropImageFilterType::Pointer filter=CropImageFilterType::New();
+ filter->SetInput(input);
+ filter->SetLowerBoundaryCropSize(lSize);
+ filter->SetUpperBoundaryCropSize(uSize);
+ filter->Update();
+ output = filter->GetOutput();