diff --git a/Modules/PhotoacousticsLib/src/SUFilter/mitkPASpectralUnmixingFilterBase.cpp b/Modules/PhotoacousticsLib/src/SUFilter/mitkPASpectralUnmixingFilterBase.cpp index 61ad41804c..597d7e939c 100644 --- a/Modules/PhotoacousticsLib/src/SUFilter/mitkPASpectralUnmixingFilterBase.cpp +++ b/Modules/PhotoacousticsLib/src/SUFilter/mitkPASpectralUnmixingFilterBase.cpp @@ -1,216 +1,216 @@ /*=================================================================== 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 "mitkPASpectralUnmixingFilterBase.h" // Includes for AddEnmemberMatrix #include "mitkPAPropertyCalculator.h" #include // ImageAccessor #include #include // For testing reasons #include mitk::pa::SpectralUnmixingFilterBase::SpectralUnmixingFilterBase() { this->SetNumberOfIndexedOutputs(2); for (unsigned int i = 0; iSetNthOutput(i, mitk::Image::New()); } m_PropertyCalculator = mitk::pa::PropertyCalculator::New(); } mitk::pa::SpectralUnmixingFilterBase::~SpectralUnmixingFilterBase() { } void mitk::pa::SpectralUnmixingFilterBase::AddWavelength(int wavelength) { m_Wavelength.push_back(wavelength); } void mitk::pa::SpectralUnmixingFilterBase::AddChromophore(ChromophoreType chromophore) { m_Chromophore.push_back(chromophore); } void mitk::pa::SpectralUnmixingFilterBase::GenerateData() { MITK_INFO << "GENERATING DATA.."; // Get input image mitk::Image::Pointer input = GetInput(0); unsigned int xDim = input->GetDimensions()[0]; unsigned int yDim = input->GetDimensions()[1]; unsigned int zDim = input->GetDimensions()[2]; unsigned int size = xDim * yDim * zDim; MITK_INFO << "x dimension: " << xDim; MITK_INFO << "y dimension: " << yDim; MITK_INFO << "z dimension: " << zDim; InitializeOutputs(); auto EndmemberMatrix = AddEndmemberMatrix(); // Copy input image into array mitk::ImageReadAccessor readAccess(input); const float* inputDataArray = ((const float*)readAccess.GetData()); CheckPreConditions(size, zDim, inputDataArray); /* READ OUT INPUTARRAY MITK_INFO << "Info Array:"; int numberOfPixels= 6; for (int i=0; i< numberOfPixels; ++i) MITK_INFO << inputDataArray[i];/**/ // test to see pixel values @ txt file - ofstream myfile; - myfile.open("PASpectralUnmixingPixelValues.txt"); + //ofstream myfile; + //myfile.open("PASpectralUnmixingPixelValues.txt"); //loop over every pixel @ x,y plane for (unsigned int x = 0; x < xDim; x++) { for (unsigned int y = 0; y < yDim; y++) { Eigen::VectorXf inputVector(zDim); for (unsigned int z = 0; z < zDim; z++) { // Get pixel value of pixel x,y @ wavelength z unsigned int pixelNumber = (xDim*yDim*z) + x * yDim + y; auto pixel = inputDataArray[pixelNumber]; //MITK_INFO << "Pixel_values: " << pixel; // dummy values for pixel for testing purposes //float pixel = rand(); //write all wavelength absorbtion values for one(!) pixel to a vector inputVector[z] = pixel; } Eigen::VectorXf resultVector = SpectralUnmixingAlgorithm(EndmemberMatrix, inputVector); // write output for (int outputIdx = 0; outputIdx < GetNumberOfIndexedOutputs(); ++outputIdx) { auto output = GetOutput(outputIdx); mitk::ImageWriteAccessor writeOutput(output); float* writeBuffer = (float *)writeOutput.GetData(); writeBuffer[x*yDim + y] = resultVector[outputIdx]; } - myfile << "Input Pixel(x,y): " << x << "," << y << "\n" << inputVector << "\n"; - myfile << "Result: " << "\n HbO2: " << resultVector[0] << "\n Hb: " << resultVector[1] <<"\n"; + //myfile << "Input Pixel(x,y): " << x << "," << y << "\n" << inputVector << "\n"; + //myfile << "Result: " << "\n HbO2: " << resultVector[0] << "\n Hb: " << resultVector[1] <<"\n"; } } MITK_INFO << "GENERATING DATA...[DONE]"; - myfile.close(); + //myfile.close(); } void mitk::pa::SpectralUnmixingFilterBase::CheckPreConditions(unsigned int size, unsigned int NumberOfInputImages, const float* inputDataArray) { // Checking if number of Inputs == added wavelengths if (m_Wavelength.size() != NumberOfInputImages) mitkThrow() << "CHECK INPUTS! WAVELENGTHERROR"; // Checking if number of wavelengths >= number of chromophores if (m_Chromophore.size() > m_Wavelength.size()) mitkThrow() << "PRESS 'IGNORE' AND ADD MORE WAVELENGTHS!"; // Checking if pixel type is float int maxPixel = size; for (int i = 0; i < maxPixel; ++i) { if (typeid(inputDataArray[i]).name() != typeid(float).name()) { mitkThrow() << "PIXELTYPE ERROR! FLOAT 32 REQUIRED"; } else continue; } MITK_INFO << "CHECK PRECONDITIONS ...[DONE]"; } void mitk::pa::SpectralUnmixingFilterBase::InitializeOutputs() { unsigned int numberOfInputs = GetNumberOfIndexedInputs(); unsigned int numberOfOutputs = GetNumberOfIndexedOutputs(); //MITK_INFO << "Inputs: " << numberOfInputs << " Outputs: " << numberOfOutputs; // Set dimensions (2) and pixel type (float) for output mitk::PixelType pixelType = mitk::MakeScalarPixelType(); const int NUMBER_OF_SPATIAL_DIMENSIONS = 2; auto* dimensions = new unsigned int[NUMBER_OF_SPATIAL_DIMENSIONS]; for(unsigned int dimIdx=0; dimIdxGetDimensions()[dimIdx]; } // Initialize numberOfOutput pictures with pixel type and dimensions for (unsigned int outputIdx = 0; outputIdx < numberOfOutputs; outputIdx++) { GetOutput(outputIdx)->Initialize(pixelType, NUMBER_OF_SPATIAL_DIMENSIONS, dimensions); } } //Matrix with #chromophores colums and #wavelengths rows //so Matrix Element (i,j) contains the Absorbtion of chromophore j @ wavelength i Eigen::Matrix mitk::pa::SpectralUnmixingFilterBase::AddEndmemberMatrix() { unsigned int numberOfChromophores = m_Chromophore.size(); //columns unsigned int numberOfWavelengths = m_Wavelength.size(); //rows Eigen::Matrix EndmemberMatrix(numberOfWavelengths, numberOfChromophores); //loop over i rows (Wavelengths) for(unsigned int i = 0; i < numberOfWavelengths; ++i) { //loop over j columns (Chromophores) for (unsigned int j = 0; j < numberOfChromophores; ++j) { //writes @ Matrix element (i,j) the absorbtion wavelength of the propertycalculator.cpp //'i+1' because MapType is defined different then ChromophoreType EndmemberMatrix(i,j)= m_PropertyCalculator->GetAbsorptionForWavelength( static_cast(m_Chromophore[j]+1), m_Wavelength[i]); /* Tests to see what gets written in the Matrix: auto testtype = m_PropertyCalculator->GetAbsorptionForWavelength( static_cast(m_Chromophore[j]+1), m_Wavelength[i]); MITK_INFO << "TEST_TYPE Matrix: " << typeid(EndmemberMatrix(i,j)).name(); MITK_INFO << "map type: " << static_cast(m_Chromophore[j]+1); MITK_INFO << "wavelength: " << m_Wavelength[i]; MITK_INFO << "Matrixelement: (" << i << ", " << j << ") Absorbtion: " << EndmemberMatrix(i, j);/**/ if (EndmemberMatrix(i, j) == 0) { m_Wavelength.clear(); mitkThrow() << "WAVELENGTH "<< m_Wavelength[i] << "nm NOT SUPPORTED!"; } } } MITK_INFO << "GENERATING ENMEMBERMATRIX [DONE]!"; return EndmemberMatrix; } diff --git a/Plugins/org.mitk.gui.qt.photoacoustics.spectralunmixing/files.cmake b/Plugins/org.mitk.gui.qt.photoacoustics.spectralunmixing/files.cmake index e780fe6bfe..2940e51e6b 100644 --- a/Plugins/org.mitk.gui.qt.photoacoustics.spectralunmixing/files.cmake +++ b/Plugins/org.mitk.gui.qt.photoacoustics.spectralunmixing/files.cmake @@ -1,42 +1,42 @@ set(SRC_CPP_FILES ) set(INTERNAL_CPP_FILES org_mitk_gui_qt_photoacoustics_spectralunmixing_Activator.cpp SpectralUnmixing.cpp ) set(UI_FILES src/internal/SpectralUnmixingControls.ui ) set(MOC_H_FILES src/internal/org_mitk_gui_qt_photoacoustics_spectralunmixing_Activator.h src/internal/SpectralUnmixing.h ) # list of resource files which can be used by the plug-in # system without loading the plug-ins shared library, # for example the icon used in the menu and tabs for the # plug-in views in the workbench set(CACHED_RESOURCE_FILES - resources/icon.xpm + resources/spectralunmixing.svg plugin.xml ) # list of Qt .qrc files which contain additional resources # specific to this plugin set(QRC_FILES ) set(CPP_FILES ) foreach(file ${SRC_CPP_FILES}) set(CPP_FILES ${CPP_FILES} src/${file}) endforeach(file ${SRC_CPP_FILES}) foreach(file ${INTERNAL_CPP_FILES}) set(CPP_FILES ${CPP_FILES} src/internal/${file}) endforeach(file ${INTERNAL_CPP_FILES}) diff --git a/Plugins/org.mitk.gui.qt.photoacoustics.spectralunmixing/plugin.xml b/Plugins/org.mitk.gui.qt.photoacoustics.spectralunmixing/plugin.xml index 063fe5556e..0e3fe22367 100644 --- a/Plugins/org.mitk.gui.qt.photoacoustics.spectralunmixing/plugin.xml +++ b/Plugins/org.mitk.gui.qt.photoacoustics.spectralunmixing/plugin.xml @@ -1,11 +1,12 @@ + icon="resources/spectralunmixing.svg" /> diff --git a/Plugins/org.mitk.gui.qt.photoacoustics.spectralunmixing/resources/icon.xpm b/Plugins/org.mitk.gui.qt.photoacoustics.spectralunmixing/resources/icon.xpm deleted file mode 100644 index 9057c20bc6..0000000000 --- a/Plugins/org.mitk.gui.qt.photoacoustics.spectralunmixing/resources/icon.xpm +++ /dev/null @@ -1,21 +0,0 @@ -/* XPM */ -static const char * icon_xpm[] = { -"16 16 2 1", -" c #FF0000", -". c #000000", -" ", -" ", -" ", -" ", -" ", -" ", -" ", -" ", -" ", -" ", -" ", -" ", -" ", -" ", -" ", -" "}; diff --git a/Plugins/org.mitk.gui.qt.photoacoustics.spectralunmixing/resources/spectralunmixing.svg b/Plugins/org.mitk.gui.qt.photoacoustics.spectralunmixing/resources/spectralunmixing.svg new file mode 100644 index 0000000000..6550cc09c4 --- /dev/null +++ b/Plugins/org.mitk.gui.qt.photoacoustics.spectralunmixing/resources/spectralunmixing.svg @@ -0,0 +1,48 @@ + +image/svg+xml \ No newline at end of file