Medical Imaging Interaction Toolkit  2018.4.99-389bf124
Medical Imaging Interaction Toolkit
itkMaskedStatisticsImageFilterTest.cpp
Go to the documentation of this file.
1 /*============================================================================
2 
3 The Medical Imaging Interaction Toolkit (MITK)
4 
5 Copyright (c) German Cancer Research Center (DKFZ)
6 All rights reserved.
7 
8 Use of this source code is governed by a 3-clause BSD license that can be
9 found in the LICENSE file.
10 
11 ============================================================================*/
12 
13 #include "itkImage.h"
14 #include "itkImageRegionIterator.h"
15 
17 
18 #include "mitkTestingMacros.h"
19 #include "mitkVector.h"
20 
22 
23 int itkMaskedStatisticsImageFilterTest(int /*argc*/, char*[] /*argv[]*/)
24 {
25  // always start with this!
26  MITK_TEST_BEGIN("itkMaskedStatisticsImageFilterTest")
27 
28  //Prepare test artifacts and helper
29 
30  mitk::TestImageType::Pointer img1 = mitk::GenerateTestImage();
31 
33  FilterType::Pointer testFilter = FilterType::New();
34 
35  testFilter->SetInput(img1);
36 
37  testFilter->SetNumberOfThreads(2);
38 
39  testFilter->Update();
40 
41  FilterType::PixelType max = testFilter->GetMaximum();
42  FilterType::PixelType min = testFilter->GetMinimum();
43  FilterType::RealType mean = testFilter->GetMean();
44  FilterType::RealType sig = testFilter->GetSigma();
45  FilterType::RealType variance = testFilter->GetVariance();
46  FilterType::RealType sum = testFilter->GetSum();
47 
48  CPPUNIT_ASSERT_MESSAGE("Check computed maximum",9 == max);
49  CPPUNIT_ASSERT_MESSAGE("Check computed minimum",1 == min);
50  CPPUNIT_ASSERT_MESSAGE("Check computed mean",5 == mean);
51  CPPUNIT_ASSERT_MESSAGE("Check computed sigma",sqrt(7.5) == sig);
52  CPPUNIT_ASSERT_MESSAGE("Check computed variance",7.5 == variance);
53  CPPUNIT_ASSERT_MESSAGE("Check computed sum",45 == sum);
54 
55  //Test with mask set
56  mitk::TestMaskType::Pointer mask = mitk::GenerateTestMask();
57  testFilter->SetMask(mask);
58 
59  testFilter->Update();
60 
61  max = testFilter->GetMaximum();
62  min = testFilter->GetMinimum();
63  mean = testFilter->GetMean();
64  sig = testFilter->GetSigma();
65  variance = testFilter->GetVariance();
66  sum = testFilter->GetSum();
67 
68  CPPUNIT_ASSERT_MESSAGE("Check computed maximum",4 == max);
69  CPPUNIT_ASSERT_MESSAGE("Check computed minimum",2 == min);
70  CPPUNIT_ASSERT_MESSAGE("Check computed mean",3 == mean);
71  CPPUNIT_ASSERT_MESSAGE("Check computed sigma",1 == sig);
72  CPPUNIT_ASSERT_MESSAGE("Check computed variance",1 == variance);
73  CPPUNIT_ASSERT_MESSAGE("Check computed sum",9 == sum);
74 
76 }
section GeneralTestsDeprecatedOldTestingStyle Deprecated macros All tests with MITK_TEST_BEGIN()
TestImageType::Pointer MITKTESTINGHELPER_EXPORT GenerateTestImage(int factor=1)
Compute min. max, variance and mean of an (masked) Image.
static T max(T x, T y)
Definition: svm.cpp:56
static T min(T x, T y)
Definition: svm.cpp:53
int itkMaskedStatisticsImageFilterTest(int, char *[])
mitk::Image::Pointer mask
and MITK_TEST_END()
TestMaskType::Pointer MITKTESTINGHELPER_EXPORT GenerateTestMask()