From 69dacfe0651ee24bef0f9e6b41171b9eec96fd2e Mon Sep 17 00:00:00 2001 From: tbaudier Date: Tue, 5 Mar 2019 11:04:57 +0100 Subject: [PATCH] Add scalar into clitkImageArithm operation For absolute difference and squared difference, the scalar can be included like in ImageAritmh GUI into vv --- tools/clitkImageArithmGenericFilter.txx | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/tools/clitkImageArithmGenericFilter.txx b/tools/clitkImageArithmGenericFilter.txx index 9a4236b..6bf79d5 100644 --- a/tools/clitkImageArithmGenericFilter.txx +++ b/tools/clitkImageArithmGenericFilter.txx @@ -87,7 +87,7 @@ void ImageArithmGenericFilter::SetArgsInfo(const args_info_type exit(-1); } if ((!mArgsInfo.input2_given) && (!mArgsInfo.scalar_given)) { - if (mArgsInfo.operation_arg < 5) { + if (mArgsInfo.operation_arg < 7 || mArgsInfo.operation_arg == 10 || mArgsInfo.operation_arg == 11 || mArgsInfo.operation_arg == 13) { std::cerr << "Such operation need the --scalar option." << std::endl; exit(-1); } @@ -336,16 +336,17 @@ void clitk::ImageArithmGenericFilter::ComputeImage(Iter1 it, Ite break; case 5: // Absolute value while (!it.IsAtEnd()) { - if (it.Get() <= 0) ito.Set(PixelTypeDownCast(-it.Get())); + double value = (double)it.Get() - mScalar; + if (value <= 0) ito.Set(PixelTypeDownCast(-value)); // <= zero to avoid warning for unsigned types - else ito.Set(PixelTypeDownCast(it.Get())); + else ito.Set(value); ++it; ++ito; } break; case 6: // Squared value while (!it.IsAtEnd()) { - ito.Set(PixelTypeDownCast((double)it.Get()*(double)it.Get())); + ito.Set(PixelTypeDownCast(((double)it.Get()-mScalar)*((double)it.Get()-mScalar))); ++it; ++ito; } -- 2.47.1