From 05e26237e30a14a226cb4eb480a0eb9697f8ba06 Mon Sep 17 00:00:00 2001 From: tbaudier Date: Thu, 15 Nov 2018 16:24:18 +0100 Subject: [PATCH] Change behavior of clitkCropImage with like option Before, if we cropped an image like another, the output's origin was set at the origin of the input. But we prefer to keep the registration correctly, so we prefer to have an output's origin defined to still have the registration between the output and the input. This is the normal behavior of the itk::PasteImageFilter. I removed the SetNumberOfRequiredInputs to avoid this error: PasteImageFilter(0x1927770): At least 2 of the first 2 indexed inputs are required but only 1 are specified. The required inputs are expected to be the first inputs. I add the updateOrigin flag to keep the previous behavior. If the flag is set to On (default is off), the origin of the output is set to the same origin than the input. I update the description of the filte about this origin managment --- itk/clitkPasteImageFilter.hxx | 2 +- tools/clitkCropImage.ggo | 4 +++- tools/clitkCropImageGenericFilter.cxx | 4 +++- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/itk/clitkPasteImageFilter.hxx b/itk/clitkPasteImageFilter.hxx index 348d858..2a3f99d 100644 --- a/itk/clitkPasteImageFilter.hxx +++ b/itk/clitkPasteImageFilter.hxx @@ -15,7 +15,7 @@ namespace clitk PasteImageFilter< TInputImage, TSourceImage, TOutputImage > ::PasteImageFilter() { - this->ProcessObject::SetNumberOfRequiredInputs(2); + //this->ProcessObject::SetNumberOfRequiredInputs(2); this->InPlaceOff(); this->m_DestinationIndex.Fill(0); diff --git a/tools/clitkCropImage.ggo b/tools/clitkCropImage.ggo index a674f8b..a70452d 100644 --- a/tools/clitkCropImage.ggo +++ b/tools/clitkCropImage.ggo @@ -1,7 +1,8 @@ #File clitkCropImage.ggo package "clitkCropImage" version "1.0" -purpose "Crop an image according to a given extends or AutoCrop with a background value or like another image" +purpose "Crop an image according to a given extends or AutoCrop with a background value or like another image. +In all cases, by default, the output origin is set to be able to overlay input and output without registration." option "config" - "Config file" string no option "imagetypes" - "Display allowed image types" flag off @@ -25,6 +26,7 @@ option "BG" - "Background value in input." double default="0" no section "Crop like another image" option "like" - "Crop like this image (must have the same spacing" string no +option "updateOrigin" - "By default, with like image, the output origin is the same than the like image. Set to on the flag to keep the origin." flag off option "BGLike" - "Background value in output (if like larger)" double default="0" no diff --git a/tools/clitkCropImageGenericFilter.cxx b/tools/clitkCropImageGenericFilter.cxx index 4adcb9b..4f3bb23 100644 --- a/tools/clitkCropImageGenericFilter.cxx +++ b/tools/clitkCropImageGenericFilter.cxx @@ -106,6 +106,8 @@ void clitk::CropImageGenericFilter::UpdateWithInputImageType() // Check options if (mArgsInfo.BG_given && mArgsInfo.like_given) clitkExceptionMacro("Do not use --BG and --like at the same time"); + if (mArgsInfo.updateOrigin_flag && !mArgsInfo.like_given) + clitkExceptionMacro("Use --updateOrigin with --like"); // Prepare output typename ImageType::Pointer output; @@ -182,7 +184,7 @@ void clitk::CropImageGenericFilter::UpdateWithInputImageType() typename ImageType::IndexType index = region.GetIndex(); typename ImageType::PointType origin = output->GetOrigin(); typename ImageType::SpacingType spacing = output->GetSpacing(); - if (!mArgsInfo.BG_given) { + if (!mArgsInfo.BG_given && (!mArgsInfo.like_given || mArgsInfo.updateOrigin_flag)) { if (mArgsInfo.verbose_flag) std::cout << "origin before crop " << origin << std::endl; input->TransformIndexToPhysicalPoint(index,origin); if (mArgsInfo.verbose_flag) std::cout << "origin after crop " << origin << std::endl; -- 2.47.1