X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=tools%2FclitkImageUncertainty.cxx;h=a8e76de080c278e6d87cb095a1f2ee03160a808f;hb=ba7eb37f66c14a90fe67ac035ecf9d8bc70fef1a;hp=9240bd8278161746245374a99c79e47d32254ef6;hpb=a845c6a04ecfeedc8eced5f4051e06ee88c59e90;p=clitk.git diff --git a/tools/clitkImageUncertainty.cxx b/tools/clitkImageUncertainty.cxx index 9240bd8..a8e76de 100644 --- a/tools/clitkImageUncertainty.cxx +++ b/tools/clitkImageUncertainty.cxx @@ -34,13 +34,12 @@ #include "clitkImageUncertainty_ggo.h" #include "clitkImageCommon.h" #include "clitkCommon.h" +#include "clitkPortability.h" // itk include #include "itkImageRegionConstIterator.h" #include "itkImageRegionIterator.h" -#include - //==================================================================== int main(int argc, char * argv[]) { @@ -54,9 +53,9 @@ int main(int argc, char * argv[]) { // Read images ImageType::Pointer input = - clitk::readImage(args_info.input_arg, args_info.verbose_flag); + clitk::readImage(args_info.input_arg, args_info.verbose_flag); ImageType::Pointer inputSquared = - clitk::readImage(args_info.inputSquared_arg, args_info.verbose_flag); + clitk::readImage(args_info.inputSquared_arg, args_info.verbose_flag); // Create Output ImageType::Pointer output = ImageType::New(); @@ -76,39 +75,36 @@ int main(int argc, char * argv[]) { int NumberOfEvents = args_info.NumberOfEvents_arg; while ( !pi.IsAtEnd() ) { - double squared = pii.Get(); - double mean = pi.Get(); - double uncert = sqrt((NumberOfEvents*squared - mean*mean) / ((NumberOfEvents-1)*(mean*mean))); - if (uncert != uncert || uncert == std::numeric_limits::infinity() || uncert == -std::numeric_limits::infinity()) uncert = 1.; - po.Set(uncert); - ++pi; - ++pii; - ++po; + double squared = pii.Get(); + double mean = pi.Get(); + double uncert = sqrt((NumberOfEvents*squared - mean*mean) / (NumberOfEvents-1)); + if(!args_info.absolute_flag) + uncert /= std::abs(mean); + if (!IsNormal(uncert)) uncert = args_info.default_arg; + po.Set(uncert); + ++pi; + ++pii; + ++po; } -// *po = sqrt( (NumberOfEvents*squared - mean*mean) / -// ((NumberOfEvents-1)*(mean*mean)) ); -// ++po; - - // Write output image // DD(clitk::GetExtension(args_info.output_arg)); if (clitk::GetExtension(args_info.output_arg) != "txt") { - clitk::writeImage(output, args_info.output_arg, args_info.verbose_flag); + clitk::writeImage(output, args_info.output_arg, args_info.verbose_flag); } else { - std::ofstream os; - clitk::openFileForWriting(os, args_info.output_arg); - typedef itk::ImageRegionConstIterator IteratorType; - IteratorType pi(output, output->GetLargestPossibleRegion()); - pi.GoToBegin(); - os << "# Image size = " << output->GetLargestPossibleRegion().GetSize() << std::endl; - os << "# Image spacing = " << output->GetSpacing() << std::endl; - os << "# Number of events = " << NumberOfEvents << std::endl; - while (!pi.IsAtEnd()) { - os << pi.Get() << std::endl; - ++pi; - } + std::ofstream os; + clitk::openFileForWriting(os, args_info.output_arg); + typedef itk::ImageRegionConstIterator IteratorType; + IteratorType pi(output, output->GetLargestPossibleRegion()); + pi.GoToBegin(); + os << "# Image size = " << output->GetLargestPossibleRegion().GetSize() << std::endl; + os << "# Image spacing = " << output->GetSpacing() << std::endl; + os << "# Number of events = " << NumberOfEvents << std::endl; + while (!pi.IsAtEnd()) { + os << pi.Get() << std::endl; + ++pi; + } } }