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
PasteImageFilter< TInputImage, TSourceImage, TOutputImage >
::PasteImageFilter()
{
- this->ProcessObject::SetNumberOfRequiredInputs(2);
+ //this->ProcessObject::SetNumberOfRequiredInputs(2);
this->InPlaceOff();
this->m_DestinationIndex.Fill(0);
#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
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
// 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;
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;