diff --git a/Modules/Classification/CLActiveLearning/CMakeLists.txt b/Modules/Classification/CLActiveLearning/CMakeLists.txt index ce1ab0109f..8a97303c66 100644 --- a/Modules/Classification/CLActiveLearning/CMakeLists.txt +++ b/Modules/Classification/CLActiveLearning/CMakeLists.txt @@ -1,5 +1,5 @@ MITK_CREATE_MODULE( # INCLUDE_DIRS Algorithms Interactor ${CMAKE_CURRENT_SOURCE_DIR} - DEPENDS MitkCore MitkCLCore MitkSegmentation + DEPENDS MitkCore MitkCLCore MitkSegmentation MitkCLVigraRandomForest PACKAGE_DEPENDS ITK ) diff --git a/Modules/Classification/CLActiveLearning/files.cmake b/Modules/Classification/CLActiveLearning/files.cmake index dab2e8afe2..07dc5017b8 100644 --- a/Modules/Classification/CLActiveLearning/files.cmake +++ b/Modules/Classification/CLActiveLearning/files.cmake @@ -1,15 +1,17 @@ file(GLOB_RECURSE H_FILES RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}" "${CMAKE_CURRENT_SOURCE_DIR}/include/*") set(CPP_FILES + mitkAbstractClassifierPredictionFilter.cpp mitkActiveLearningInteractor.cpp mitkActiveLearningSuggestRegionFilter.cpp mitkPredictionUncertaintyFilter.cpp mitkPredictionConfidenceFilter.cpp mitkPredictionEntropyFilter.cpp mitkPredictionMarginFilter.cpp + mitkSelectHighestUncertaintyRegionFilter.cpp ) set(RESOURCE_FILES Interactions/Paint.xml Interactions/PaintConfig.xml ) diff --git a/Modules/Classification/CLActiveLearning/include/mitkAbstractClassifierPredictionFilter.h b/Modules/Classification/CLActiveLearning/include/mitkAbstractClassifierPredictionFilter.h new file mode 100644 index 0000000000..8c38545099 --- /dev/null +++ b/Modules/Classification/CLActiveLearning/include/mitkAbstractClassifierPredictionFilter.h @@ -0,0 +1,70 @@ +/*=================================================================== + +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 mitkAbstractClassifierPredictionFilter_h +#define mitkAbstractClassifierPredictionFilter_h + +#include + +// ITK +#include + +// MITK +#include +#include + +namespace mitk +{ + /** \class AbstractClassifierPredictionFilter + * \brief Filter that connects to a classifier and a data source and outputs the prediction for the data + * + * Inputs: + * 0 - Training Data + * 1 - A classifier that is based on mitk::AbstractClassifier + * + * Outputs: + * 0 - Prediction + * + * Proper conversion of input data to Eigen::MatrixXd should be implemented via MakeTrainingData() + */ + + class MITKCLACTIVELEARNING_EXPORT AbstractClassifierPredictionFilter : itk::ProcessObject + { + + public: + + mitkClassMacro(AbstractClassifierPredictionFilter, itk::ProcessObject) + itkNewMacro(Self) + + protected: + + AbstractClassifierPredictionFilter(){} + ~AbstractClassifierPredictionFilter(){} + + virtual Eigen::MatrixXd MakeTrainingData(itk::DataObject* /*inputData*/) = 0; + + virtual void GenerateData() override; + + private: + + // ITK examples do this... + AbstractClassifierPredictionFilter(const Self&); + void operator=(const Self&); + + }; + +} + +#endif diff --git a/Modules/Classification/CLActiveLearning/include/mitkActiveLearningSuggestRegionFilter.h b/Modules/Classification/CLActiveLearning/include/mitkActiveLearningSuggestRegionFilter.h index 52922faa7d..c4de26e44d 100644 --- a/Modules/Classification/CLActiveLearning/include/mitkActiveLearningSuggestRegionFilter.h +++ b/Modules/Classification/CLActiveLearning/include/mitkActiveLearningSuggestRegionFilter.h @@ -1,79 +1,80 @@ /*=================================================================== 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 mitkActiveLearningSuggestRegionFilter_h #define mitkActiveLearningSuggestRegionFilter_h #include // ITK #include #include #include #include #include // MITK #include #include namespace mitk { /** \class ActiveLearningSuggestRegionFilter * \brief Filter that takes an image of prediction uncertainties and outputs an image containing only the most uncertain region * * This is just a composite filter using itkThresholdImageFilter and mitkSelectHighestUncertaintyRegionFilter */ template class MITKCLACTIVELEARNING_EXPORT ActiveLearningSuggestRegionFilter : public itk::ImageToImageFilter { public: typedef itk::ImageToImageFilter SuperClassName; mitkClassMacro(ActiveLearningSuggestRegionFilter, SuperClassName) itkNewMacro(Self) // For some reason the typedefs from the ImageToImageFilter are not passed on typedef typename InputImageType::ImageDimension InputImageDimension; typedef typename InputImageType::PixelType InputImagePixelType; typedef typename InputImageType::RegionType InputImageRegionType; + // We're not holding threshold as a member, so no set and get macro void SetThreshold(InputImagePixelType threshold); InputImagePixelType GetThreshold() const; protected: ActiveLearningSuggestRegionFilter(); ~ActiveLearningSuggestRegionFilter(){} virtual void GenerateData() override; virtual void PrintSelf(std::ostream & os, typename Superclass::Indent indent) const; private: // ITK examples do this... ActiveLearningSuggestRegionFilter(const Self&); void operator=(const Self&); typename itk::ThresholdImageFilter::Pointer m_ThresholdFilter; typename mitk::SelectHighestUncertaintyRegionFilter::Pointer m_RegionFilter; }; } #endif diff --git a/Modules/Classification/CLActiveLearning/src/mitkAbstractClassifierPredictionFilter.cpp b/Modules/Classification/CLActiveLearning/src/mitkAbstractClassifierPredictionFilter.cpp new file mode 100644 index 0000000000..523bf99e5f --- /dev/null +++ b/Modules/Classification/CLActiveLearning/src/mitkAbstractClassifierPredictionFilter.cpp @@ -0,0 +1,16 @@ +/*=================================================================== + +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 diff --git a/Modules/Classification/CLActiveLearning/src/mitkActiveLearningSuggestRegionFilter.cpp b/Modules/Classification/CLActiveLearning/src/mitkActiveLearningSuggestRegionFilter.cpp index f2841c37fe..f79e6a18db 100644 --- a/Modules/Classification/CLActiveLearning/src/mitkActiveLearningSuggestRegionFilter.cpp +++ b/Modules/Classification/CLActiveLearning/src/mitkActiveLearningSuggestRegionFilter.cpp @@ -1,69 +1,69 @@ /*=================================================================== 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 namespace mitk { template ActiveLearningSuggestRegionFilter::ActiveLearningSuggestRegionFilter() { m_ThresholdFilter = itk::ThresholdImageFilter::New(); m_RegionFilter = mitk::SelectHighestUncertaintyRegionFilter::New(); m_ThresholdFilter->SetLower(0.5); m_RegionFilter->SetInput(m_ThresholdFilter->GetOutput()); } template void ActiveLearningSuggestRegionFilter::GenerateData() { // Let this filter's input be threshold filter's input typename InputImageType::Pointer input = InputImageType::New(); input->Graft(const_cast(this->GetInput())); m_ThresholdFilter->SetInput(input); - m_ThresholdFilter->Modified(); // Is this necessary? + m_ThresholdFilter->Modified(); // Region filter takes this filter's output, updates, gives it back m_RegionFilter->GraftOutput(this->GetOutput()); m_RegionFilter->Update(); this->GraftOutput(m_RegionFilter->GetOutput()); } template void ActiveLearningSuggestRegionFilter::PrintSelf(std::ostream & os, typename Superclass::Indent indent) const { Superclass::PrintSelf(os, indent); m_ThresholdFilter->PrintSelf(os, indent); m_RegionFilter->PrintSelf(os, indent); } template void ActiveLearningSuggestRegionFilter::SetThreshold(InputImagePixelType threshold) { if (m_ThresholdFilter->GetLower() != threshold) { m_ThresholdFilter->SetLower(threshold); this->Modified(); } } template typename InputImageType::PixelType ActiveLearningSuggestRegionFilter::GetThreshold() const { return m_ThresholdFilter->GetLower(); } }