From 223594d7e02b8e849cc76d2d1a69d7019a01cd13 Mon Sep 17 00:00:00 2001 From: Benoit Presles Date: Wed, 15 Jul 2020 16:45:39 +0200 Subject: [PATCH] =?UTF-8?q?improve=20the=20consistency=20of=20the=20clitkI?= =?UTF-8?q?mageStatistics=20tool=20=E2=80=93=20#2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 4 +++ tools/clitkImageStatisticsGenericFilter.txx | 33 ++++++++++++++++++--- 2 files changed, 33 insertions(+), 4 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..f96872c1 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +CMakeLists.txt.user* +.vs +CMakeSettings.json + diff --git a/tools/clitkImageStatisticsGenericFilter.txx b/tools/clitkImageStatisticsGenericFilter.txx index 82a11ab5..ad85727f 100644 --- a/tools/clitkImageStatisticsGenericFilter.txx +++ b/tools/clitkImageStatisticsGenericFilter.txx @@ -193,7 +193,30 @@ namespace clitk numberOfLabels=m_ArgsInfo.label_given; else numberOfLabels=1; - + // Let's do some checks + if (m_ArgsInfo.label_given && !m_ArgsInfo.mask_given) { + std::cerr << "If a/some specific label(s) is/are given, a mask image needs to be provided" << std::endl; + exit(-1); + } + if (m_ArgsInfo.label_given && m_ArgsInfo.mask_given) { + //Let's check if the labels exist in the mask image + for (unsigned int k=0; k< numberOfLabels; k++) { + label=m_ArgsInfo.label_arg[k]; + unsigned int label_counter = 0; + itk::ImageRegionConstIterator it(labelImage,labelImage->GetLargestPossibleRegion()); + it.GoToBegin(); + while( !it.IsAtEnd() ) { + if(label == it.Get()) { + ++label_counter; + } + ++it; + } + if (label_counter == 0) { + std::cerr << "The label number " << (int) label << " does not exist in the mask image" << std::endl; + exit(-1); + } + } + } unsigned int firstComponent = 0, lastComponent = 0; if (m_ArgsInfo.channel_arg == -1) { firstComponent = 0; @@ -214,9 +237,11 @@ namespace clitk label=m_ArgsInfo.label_arg[k]; std::cout<