From 3706c8037518ec336c8182fc2db1d08f1700bf1d Mon Sep 17 00:00:00 2001 From: dsarrut Date: Thu, 9 Jun 2011 14:36:39 +0200 Subject: [PATCH] Add "normalize" and "divide by a scalar" --- tools/clitkImageArithm.ggo | 2 +- tools/clitkImageArithmGenericFilter.txx | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/tools/clitkImageArithm.ggo b/tools/clitkImageArithm.ggo index 6f4b932..ca7e916 100644 --- a/tools/clitkImageArithm.ggo +++ b/tools/clitkImageArithm.ggo @@ -13,7 +13,7 @@ option "input2" j "Input second image filename" string no option "output" o "Output image filename" string yes option "scalar" s "Scalar value" double no -option "operation" t "Type of operation : \n With another image : 0=add, 1=multiply, 2=divide,\n 3=max, 4=min, 5=absdiff, 6=squareddiff, 7=difference, 8=relativ diff\n For 'scalar' : 0=add, 1=multiply, 2=inverse,\n 3=max, 4=min 5=absval 6=squareval\n 7=log 8=exp 9=sqrt 10=EPID" int default="0" no +option "operation" t "Type of operation : \n With another image : 0=add, 1=multiply, 2=divide,\n 3=max, 4=min, 5=absdiff, 6=squareddiff, 7=difference, 8=relativ diff\n For 'scalar' : 0=add, 1=multiply, 2=inverse,\n 3=max, 4=min 5=absval 6=squareval\n 7=log 8=exp 9=sqrt 10=EPID 11=divide 12=normalize (divide by max)" int default="0" no option "pixelValue" - "Default value for NaN/Inf" double default="0.0" no option "setFloatOutput" f "Set output to float pixel type" flag off diff --git a/tools/clitkImageArithmGenericFilter.txx b/tools/clitkImageArithmGenericFilter.txx index f3b1d44..8278108 100644 --- a/tools/clitkImageArithmGenericFilter.txx +++ b/tools/clitkImageArithmGenericFilter.txx @@ -20,6 +20,8 @@ #include "clitkImageCommon.h" +#include "itkMinimumMaximumImageCalculator.h" + namespace clitk { @@ -110,6 +112,17 @@ void ImageArithmGenericFilter::UpdateWithInputImageType() typename ImageType::Pointer input2 = NULL; IteratorType it2; + // Special case for normalisation + if (mTypeOfOperation == 12) { + typedef itk::MinimumMaximumImageCalculator MinMaxFilterType; + typename MinMaxFilterType::Pointer ff = MinMaxFilterType::New(); + ff->SetImage(input1); + ff->ComputeMaximum(); + mScalar = ff->GetMaximum(); + DD(mScalar); + DD("normalisation"); + mTypeOfOperation = 11; // divide + } if (mIsOperationUseASecondImage) { // Read input2 @@ -370,6 +383,13 @@ void clitk::ImageArithmGenericFilter::ComputeImage(Iter1 it, Ite ++ito; } break; + case 11: // divide + while (!it.IsAtEnd()) { + ito.Set(PixelTypeDownCast((double)it.Get() / mScalar) ); + ++it; + ++ito; + } + break; default: // error ? std::cerr << "ERROR : the operation number (" << mTypeOfOperation << ") is not known." << std::endl; exit(-1); -- 2.47.1