diff --git a/Modules/PhotoacousticArtifacts/include/mitkPhotoacousticArtifact.h b/Modules/PhotoacousticArtifacts/include/mitkPhotoacousticArtifact.h index d7fd7d2605..ce20b14908 100644 --- a/Modules/PhotoacousticArtifacts/include/mitkPhotoacousticArtifact.h +++ b/Modules/PhotoacousticArtifacts/include/mitkPhotoacousticArtifact.h @@ -1,53 +1,53 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #ifndef mitkPhotoacousticArtifact_h #define mitkPhotoacousticArtifact_h #include #include #include #include #include namespace mitk { class MITKPHOTOACOUSTICARTIFACTS_EXPORT PhotoacousticArtifact final : public mitk::ImageToImageFilter { public: // All classes that derive from an ITK-based MITK class need at least the // following two macros. Make sure you don't declare the constructor public // to force clients of your class to follow the ITK convention for // instantiating classes via the static New() method. mitkClassMacro(PhotoacousticArtifact, mitk::ImageToImageFilter) itkFactorylessNewMacro(Self) - itkSetMacro(SVC, int) - itkGetMacro(SVC, int) + itkSetMacro(SVD, int) + itkGetMacro(SVD, int) protected: private: PhotoacousticArtifact(); - ~PhotoacousticArtifact(); + ~PhotoacousticArtifact(); void GenerateData() override; - int m_SVC; + int m_SVD; }; } #endif mitkPhotoacousticArtifact_h diff --git a/Modules/PhotoacousticArtifacts/src/Algorithms/mitkPhotoacousticArtifact.cpp b/Modules/PhotoacousticArtifacts/src/Algorithms/mitkPhotoacousticArtifact.cpp index 20ee0a456d..e088f047bc 100644 --- a/Modules/PhotoacousticArtifacts/src/Algorithms/mitkPhotoacousticArtifact.cpp +++ b/Modules/PhotoacousticArtifacts/src/Algorithms/mitkPhotoacousticArtifact.cpp @@ -1,105 +1,104 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #include #include #include #include #include -template -static void ComputeSVD(const Eigen::JacobiSVD<_MatrixType, QRPreconditioner>* inputMatrix, int svdNumber, mitk::Image::Pointer outputImage) -{ - typedef typename Eigen::JacobiSVD<_MatrixType, QRPreconditioner> JacobiSVDType; - - auto svd = JacobiSVDType::New(); - svd->SetInput(inputMatrix); - svd->SetSVD(svdNumber); - JacobiSVDType->compute(); - - MatrixXd m(2, 2); +//Step 1: inputImage in matrix m überführen +//Step 2: eigenvectoren der matrix berechnen +//Step 3: eigenvectors in outputImage überführen - MITK_INFO << "Here is the matrix m:" << endl << m << endl; - Eigen::JacobiSVD svd(m, ComputeThinU | ComputeThinV); - MITK_INFO << "Its singular values are:" << endl << svd.singularValues() << endl; - MITK_INFO << "Its left singular vectors are the columns of the thin U matrix:" << endl << svd.matrixU() << endl; - MITK_INFO << "Its right singular vectors are the columns of the thin V matrix:" << endl << svd.matrixV() << endl; - - Eigen::JacobiSVD<_MatrixType, QRPreconditioner>::compute(inputMatrix); +static void ComputeSVD(mitk::Image::Pointer inputImage, int svdNumber, mitk::Image::Pointer outputImage) +{ + //MatrixXd m = + Eigen::MatrixXd m(2, 2); + m(0, 0) = 2; + m(1, 0) = -1; + m(0, 1) = 2; + m(1, 1) = 1; + Eigen::JacobiSVD svdSolver(m, Eigen::ComputeFullV); + Eigen::MatrixXd matrixV = svdSolver.matrixV(); + auto eigenVec1 = matrixV.col(0); + auto eigenVec2 = matrixV.col(1); + MITK_INFO << "Matrix V: " << endl << matrixV << endl; + MITK_INFO << "Eigenvector 1: " << endl << eigenVec1 << endl; + MITK_INFO << "Eigenvector 2: " << endl << eigenVec2 << endl; //This is the tricky part that is done wrong very often.As the image data // of ITK images and MITK images are binary compatible, we don't need to // cast or copy the ITK output image.Instead, we just want to reference // the image data and tell ITK that we took the ownership. - mitk::GrabItkImageMemory(svd->GetOutput(), outputImage); + //mitk::GrabItkImageMemory(svd->GetOutput(), outputImage); } mitk::PhotoacousticArtifact::PhotoacousticArtifact() - : m_SVC(1) + : m_SVD(1) { - // TODO output this->SetPrimaryOutput(mitk::Image::New()); - MITK_INFO << "Test. Hi."; + MITK_INFO << "Hello."; this->SetNumberOfRequiredInputs(1); + this->SetNumberOfRequiredOutputs(1); } mitk::PhotoacousticArtifact::~PhotoacousticArtifact() { } void mitk::PhotoacousticArtifact::GenerateData() { - //template - //static void ComputeSVD(inputMatrix, svdNumber, outputImage); + mitk::Image::Pointer inputImage = this->GetInput(0); - //mitk::Image::Pointer inputImage = this->GetInput(0); + mitk::Image::Pointer outputImage = this->GetOutput(); - //mitk::Image::Pointer outputImage = this->GetOutput(); + ComputeSVD(nullptr, 1, nullptr); //try //{ // // We want to apply an ITK filter to the MITK input image. While MITK // // images are not templated, ITK images are templated by both pixel type // // and image dimension. The actual image data is binary compatible, though. // // MITK provides ITK access macros that enable you to directly operate // // on MITK images without any superfluous copying. // // To allow ITK filters to work with different image types at runtime you // // would be required to instantiate your function templates for each and // // every expected combination of pixel type and image dimension. Luckily, // // MITK provides a whole bunch of multiplexer macros to save you doing this // // manually (see mitkImageAccessByItk.h). // // These macros range from being completely generic to partly constrained // // variants. For example, you may want to constrain the image dimension or // // the pixel type. As your function template is compiled for each allowed // // combination, compile time and code size may increase dramatically. // // As a rule of thumb, use a suitable multiplexer macro that is as // // constrained as possible and yet as generic as necessary. // // To prevent a combinatorial explosion, image dimension is restricted to // // 2 and 3 even for the dimension-variable multiplexer macros. // // Thus, the following multiplexer macro allows for 2-dimensional and // // 3-dimensional images with an integer pixel type, for example, // // (un)signed char, short, and int, resulting in a total of 12 distinct // // combinations. - // AccessIntegralPixelTypeByItk_n(inputImage, ComputeSVD, (m_SVC, outputImage)); + // AccessIntegralPixelTypeByItk_n(inputImage, ComputeSVD, (outputImage)); //} //catch (const mitk::AccessByItkException& e) //{ // MITK_ERROR << "Unsupported pixel type or image dimension: " << e.what(); //} } diff --git a/Modules/PhotoacousticArtifacts/test/mitkPhotoacousticArtifactsTest.cpp b/Modules/PhotoacousticArtifacts/test/mitkPhotoacousticArtifactsTest.cpp index 06b364b463..1cd495a329 100644 --- a/Modules/PhotoacousticArtifacts/test/mitkPhotoacousticArtifactsTest.cpp +++ b/Modules/PhotoacousticArtifacts/test/mitkPhotoacousticArtifactsTest.cpp @@ -1,89 +1,92 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #include #include #include #include #include class mitkPhotoacousticArtifactsTestSuite : public mitk::TestFixture { CPPUNIT_TEST_SUITE(mitkPhotoacousticArtifactsTestSuite); MITK_TEST(TestSimpleSVD); CPPUNIT_TEST_SUITE_END(); private: - //input und outputbilder, alle parameter für den test + // alle Parameter: inputImage, expectedOutputImage... mitk::PhotoacousticArtifact::Pointer m_Filter; mitk::Image::Pointer m_Input; mitk::Image::Pointer m_ExpectedOutput; public: void setUp() { m_Filter = mitk::PhotoacousticArtifact::New(); - //bild initialisieren --> siehe paVolume.cpp + // inputImage initialisieren unsigned int* dimensions = new unsigned int[3]; dimensions[0] = 1; dimensions[1] = 2; dimensions[2] = 2; m_Input = mitk::Image::New(); double* data = new double[4]; - data[0] = 5; - data[1] = 3; - data[2] = 3; - data[3] = 5; + data[0] = 2; + data[1] = -1; + data[2] = 2; + data[3] = 1; mitk::PixelType pixelType = mitk::MakeScalarPixelType(); m_Input->Initialize(pixelType, 3, dimensions); m_Input->SetImportVolume(data, mitk::Image::ImportMemoryManagementType::CopyMemory); delete data; + // expectedOutputImage initialisieren m_ExpectedOutput = mitk::Image::New(); double* dataOut = new double[4]; - dataOut[0] = 1; - dataOut[1] = 1; - dataOut[2] = -1; - dataOut[3] = 1; + dataOut[0] = 1 / sqrt(2); + dataOut[1] = 1 / sqrt(2); + dataOut[2] = -1 / sqrt(2); + dataOut[3] = 1 / sqrt(2); m_ExpectedOutput->Initialize(pixelType, 3, dimensions); m_ExpectedOutput->SetImportVolume(dataOut, mitk::Image::ImportMemoryManagementType::CopyMemory); delete dataOut; } void TestSimpleSVD() { MITK_INFO << "StartTest"; m_Filter->SetInput(m_Input); m_Filter->Update(); mitk::Image::Pointer outputFilter = m_Filter->GetOutput(); CPPUNIT_ASSERT(mitk::Equal(*outputFilter, *m_ExpectedOutput, mitk::eps, true)); } void tearDown() { - //bilder deleten, aufräumen, nullptr + m_ExpectedOutput = nullptr; + m_Filter = nullptr; + m_Input = nullptr; } }; MITK_TEST_SUITE_REGISTRATION(mitkPhotoacousticArtifacts)