Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
CLUtilities/test/mitkSmoothedClassProbabilitesTest.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,
6 Division of Medical and Biological Informatics.
7 All rights reserved.
8 
9 This software is distributed WITHOUT ANY WARRANTY; without
10 even the implied warranty of MERCHANTABILITY or FITNESS FOR
11 A PARTICULAR PURPOSE.
12 
13 See LICENSE.txt or http://www.mitk.org for details.
14 
15 ===================================================================*/
16 
17 #include <mitkTestingMacros.h>
18 #include <mitkTestFixture.h>
19 #include "mitkIOUtil.h"
20 
22 #include <mitkImageCast.h>
23 
24 class mitkSmoothedClassProbabilitesTestSuite : public mitk::TestFixture
25 {
26 
27  CPPUNIT_TEST_SUITE(mitkSmoothedClassProbabilitesTestSuite );
28 
29  MITK_TEST(TrainSVMClassifier);
30  // MITK_TEST(TestThreadedDecisionForest);
31 
32  CPPUNIT_TEST_SUITE_END();
33 
34 private:
35 
36  typedef itk::Image<double,3> ImageType;
37  mitk::Image::Pointer p1,p2,p3,pmask;
38  ImageType::Pointer i1,i2,i3,imask;
39 
40 public:
41 
42 
43  void setUp(void)
44  {
45 
46  // Load Image Data
47  p1 = mitk::IOUtil::LoadImage(GetTestDataFilePath("Classification/Algorithm/ResultProb_Class-0_0.nrrd"));
48  p2 = mitk::IOUtil::LoadImage(GetTestDataFilePath("Classification/Algorithm/ResultProb_Class-1_0.nrrd"));
49  p3 = mitk::IOUtil::LoadImage(GetTestDataFilePath("Classification/Algorithm/ResultProb_Class-2_0.nrrd"));
50  pmask = mitk::IOUtil::LoadImage(GetTestDataFilePath("Classification/Algorithm/mask.nrrd"));
51 
52  mitk::CastToItkImage(p1,i1);
53  mitk::CastToItkImage(p2,i2);
54  mitk::CastToItkImage(p3,i3);
55  mitk::CastToItkImage(pmask,imask);
56  }
57 
58  void TrainSVMClassifier()
59  {
61  filter->SetInput(0,i1);
62  filter->SetInput(1,i2);
63  filter->SetInput(2,i3);
64  filter->SetMaskImage(imask);
65  filter->SetSigma(1.0);
66  filter->Update();
67 
69  mitk::CastToMitkImage(filter->GetOutput(), out);
70 
71  mitk::IOUtil::Save(out, "/Users/jc/test.nrrd");
72  }
73 
74  void TestThreadedDecisionForest()
75  {
76  // m_LoadedDecisionForest->SetCollection(m_TrainDatacollection);
77  // m_LoadedDecisionForest->SetModalities(m_Selected_items);
78  // m_LoadedDecisionForest->SetMaskName("ClassMask");
79  // m_LoadedDecisionForest->SetResultMask("ResultMask");
80  // m_LoadedDecisionForest->SetResultProb("ResultProb");
81  // m_LoadedDecisionForest->TestThreaded();
82 
83  // mitk::DataCollection::Pointer res_col = dynamic_cast<mitk::DataCollection *>(dynamic_cast<mitk::DataCollection *>(m_TrainDatacollection->GetData("Test-Study").GetPointer())->GetData("Test-Subject").GetPointer());
84  // mitk::IOUtil::Save(res_col->GetMitkImage("ResultMask"),"/Users/jc/res_mask.nrrd");
85  // mitk::IOUtil::Save(res_col->GetMitkImage("ResultProb_Class-0"),"/Users/jc/res_prob_0.nrrd");
86  // mitk::IOUtil::Save(res_col->GetMitkImage("ResultProb_Class-1"),"/Users/jc/res_prob_1.nrrd");
87  // mitk::IOUtil::Save(res_col->GetMitkImage("ResultProb_Class-2"),"/Users/jc/res_prob_2.nrrd");
88  }
89 
90 };
91 
92 MITK_TEST_SUITE_REGISTRATION(mitkSmoothedClassProbabilites)
93 
94 
static void Save(const mitk::BaseData *data, const std::string &path)
Save a mitk::BaseData instance.
Definition: mitkIOUtil.cpp:824
itk::SmartPointer< Self > Pointer
MITK_TEST_SUITE_REGISTRATION(mitkImageToItk)
#define MITK_TEST(TESTMETHOD)
Adds a test to the current test suite.
static std::string GetTestDataFilePath(const std::string &testData)
Get the absolute path for test data.
map::core::discrete::Elements< 3 >::InternalImageType ImageType
Test fixture for parameterized tests.
void CastToMitkImage(const itk::SmartPointer< ItkOutputImageType > &itkimage, itk::SmartPointer< mitk::Image > &mitkoutputimage)
Cast an itk::Image (with a specific type) to an mitk::Image.
Definition: mitkImageCast.h:78
void MITKCORE_EXPORT CastToItkImage(const mitk::Image *mitkImage, itk::SmartPointer< ItkOutputImageType > &itkOutputImage)
Cast an mitk::Image to an itk::Image with a specific type.
static mitk::Image::Pointer LoadImage(const std::string &path)
LoadImage Convenience method to load an arbitrary mitkImage.
Definition: mitkIOUtil.cpp:597