From c504dab2ce9dc023cc3df156088ebc066215ace5 Mon Sep 17 00:00:00 2001 From: Romulo Pinho Date: Mon, 18 Jul 2011 13:41:15 +0200 Subject: [PATCH] corrections in padding tool --- tools/clitkPadImage.cxx | 27 +++++++++++++++++---------- tools/clitkPadImage.ggo | 10 +++++----- 2 files changed, 22 insertions(+), 15 deletions(-) diff --git a/tools/clitkPadImage.cxx b/tools/clitkPadImage.cxx index 8b6570b..188442e 100644 --- a/tools/clitkPadImage.cxx +++ b/tools/clitkPadImage.cxx @@ -16,13 +16,14 @@ enum typedef unsigned int DimType; template -int pad_like(typename ImageType::Pointer input, const std::string& likeFile, PadBoundType* pad_lower, PadBoundType* pad_upper) +int pad_like(typename ImageType::Pointer input, const std::string& likeFile, PadBoundType* padLower, PadBoundType* padUpper) { typedef typename ImageType::SpacingType SpacingType; typedef typename ImageType::RegionType RegionType; typedef typename ImageType::SizeType SizeType; typedef typename ImageType::IndexType IndexType; typedef typename ImageType::PointType PointType; + typedef typename ImageType::PointValueType PointValueType; typedef itk::ImageFileReader ImageReaderType; typename ImageReaderType::Pointer reader = ImageReaderType::New(); @@ -33,27 +34,33 @@ int pad_like(typename ImageType::Pointer input, const std::string& likeFile, Pad SpacingType spacing = input->GetSpacing(), like_spacing = like_image->GetSpacing(); if (spacing != like_spacing) { - std::cerr << spacing << " " << like_spacing << std::endl; + std::cerr << "Like-image must have same spacing as input: " << spacing << " " << like_spacing << std::endl; return ERR_NOT_SAME_SPACING; } SizeType size = input->GetLargestPossibleRegion().GetSize(), like_size = like_image->GetLargestPossibleRegion().GetSize(); PointType origin = input->GetOrigin(), like_origin = like_image->GetOrigin(); - IndexType lower_bound, like_lower_bound; - SizeType upper_bound, like_upper_bound; + PointType lower_bound, like_lower_bound; + PointType upper_bound, like_upper_bound; + PointValueType auxl = 0, auxu = 0; for (DimType i = 0; i < dim; i++) { lower_bound[i] = origin[i]; like_lower_bound[i] = like_origin[i]; - pad_lower[i] = (PadBoundType)(abs(like_lower_bound[i] - lower_bound[i])/spacing[i]); + auxl = round(((lower_bound[i] - like_lower_bound[i])/spacing[i])); upper_bound[i] = (lower_bound[i] + size[i]*spacing[i]); like_upper_bound[i] = (like_lower_bound[i] + like_size[i]*spacing[i]); - pad_upper[i] = (PadBoundType)((like_upper_bound[i] - upper_bound[i])/spacing[i]); - if (pad_upper[i] < 0) - pad_upper[i] = 0; - } + auxu = round(((like_upper_bound[i] - upper_bound[i])/spacing[i])); + + if (auxl < 0 || auxu < 0) { + std::cerr << "Like-image's bounding box must be larger than input's" << std::endl; + return ERR_NOT_LIKE_LARGER; + } - + padLower[i] = (PadBoundType)auxl; + padUpper[i] = (PadBoundType)auxu; + } + return ERR_SUCCESS; } diff --git a/tools/clitkPadImage.ggo b/tools/clitkPadImage.ggo index 59c1f98..6f21563 100644 --- a/tools/clitkPadImage.ggo +++ b/tools/clitkPadImage.ggo @@ -1,7 +1,7 @@ #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 "Pad an image according to a given extends or like another image" option "config" - "Config file" string no option "verbose" v "Verbose" flag off @@ -11,15 +11,15 @@ section "I/O" option "input" i "Input image filename" string yes option "output" o "Output image filename" string yes -section "Used determined crop" +section "Used determined padding" option "lower" l "Size of the lower crop region (multiple values)" int no multiple option "upper" u "Size of the upper crop region (multiple values)" int no multiple -section "Crop like another image" -option "like" - "Crop like this image (must have the same spacing" string no +section "Pad like another image" +option "like" - "Pad like this image (must have the same spacing and bounding box must be larger)" string no section "Extra parameters" -option "value" - "Value to be set in padded aread" float default="0" no +option "value" - "Value to be set in padded area" float default="0" no -- 2.47.1