From c9051b5447296495d798e718f39810351cc0851d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Traizet?= <traizetc@cesbio.cnes.fr> Date: Thu, 11 May 2017 15:23:19 +0200 Subject: [PATCH] encode_filter and dummy_filter have been removed, as they are not used in the applications anymore. --- include/dummy_filter.h | 47 ----------- include/dummy_filter.txx | 79 ------------------ include/encode_filter.h | 54 ------------- include/encode_filter.txx | 165 -------------------------------------- 4 files changed, 345 deletions(-) delete mode 100644 include/dummy_filter.h delete mode 100644 include/dummy_filter.txx delete mode 100644 include/encode_filter.h delete mode 100644 include/encode_filter.txx diff --git a/include/dummy_filter.h b/include/dummy_filter.h deleted file mode 100644 index ea6dd8d21a..0000000000 --- a/include/dummy_filter.h +++ /dev/null @@ -1,47 +0,0 @@ -#ifndef __dummy_Filter_h -#define __dummy_Filter_h - -#include "itkImageToImageFilter.h" -#include "itkMacro.h" - - -template< class TImage> -class ITK_EXPORT DummyFilter:public itk::ImageToImageFilter< TImage, TImage > -{ - public: - /** Standard class typedefs. */ - typedef DummyFilter Self; - typedef itk::ImageToImageFilter< TImage, TImage > Superclass; - typedef itk::SmartPointer< Self > Pointer; - - /** Method for creation through the object factory. */ - itkNewMacro(Self); - - /** Run-time type information (and related methods). */ - itkTypeMacro(DummyFilter, ImageToImageFilter); - - //void SetInputImage(const TImage* image); - - - protected: - DummyFilter(); - ~DummyFilter(){} - - typename TImage::ConstPointer GetInputImage(); - - /** Does the real work. */ - - virtual void BeforeThreadedGenerateData(); - void ThreadedGenerateData(const typename TImage::RegionType &outputRegionForThread, unsigned int threadId) ITK_OVERRIDE; - - private: - DummyFilter(const Self &); //purposely not implemented - void operator=(const Self &); //purposely not implemented -}; - -#ifndef ITK_MANUAL_INSTANTIATION -#include "dummy_filter.txx" -#endif - - -#endif // __dummy_Filter_h diff --git a/include/dummy_filter.txx b/include/dummy_filter.txx deleted file mode 100644 index 2ec1ced9e8..0000000000 --- a/include/dummy_filter.txx +++ /dev/null @@ -1,79 +0,0 @@ -#ifndef __dummy_filter_txx -#define __dummy_filter_txx - -#include "dummy_filter.h" -#include <fstream> - - -#include "itkObjectFactory.h" -#include "itkImageRegionIterator.h" -#include "itkImageRegionConstIterator.h" -#include "otbVectorImage.h" - -/* -#include <shark/Data/Csv.h> -#include <shark/Data/Pgm.h> //for exporting the learned filters -#include <shark/Data/SparseData.h>//for reading in the images as sparseData/Libsvm format -#include <shark/Models/Autoencoder.h>//normal autoencoder model -#include <shark/Models/TiedAutoencoder.h>//autoencoder with tied weights -#include <shark/Models/Normalizer.h> -#include <shark/Algorithms/Trainers/NormalizeComponentsUnitVariance.h> -*/ - -//using namespace shark; - -template< class TImage> -DummyFilter<TImage>::DummyFilter() -{ - this->SetNumberOfRequiredInputs(1); -} - - - -template< class TImage> -typename TImage::ConstPointer DummyFilter<TImage>::GetInputImage() -{ - return static_cast< const TImage * > - ( this->itk::ProcessObject::GetInput(0) ); -} - - - - - -template< class TImage> -void DummyFilter<TImage>::BeforeThreadedGenerateData() -{ -#ifdef _OPENMP -// OpenMP will take care of threading -this->SetNumberOfThreads(1); -#endif -} - - -/*template< class TImage, class AutoencoderModel, class NormalizerModel> -void EncodeFilter<TImage, AutoencoderModel, NormalizerModel>::GenerateData()*/ -template< class TImage> -void DummyFilter<TImage>::ThreadedGenerateData(const typename TImage::RegionType &outputRegionForThread, unsigned int threadId) -{ - //Data_with_info info; - typename TImage::ConstPointer input = this->GetInput(); - typename TImage::Pointer output = this->GetOutput(); - - // Image to vector - const unsigned int img_bands = input->GetNumberOfComponentsPerPixel(); - - itk::ImageRegionConstIterator<TImage> inputIterator(input,outputRegionForThread); - itk::ImageRegionIterator<TImage> imageIteratorOut(output,outputRegionForThread); - - typename TImage::PixelType pixelValue; - while(!inputIterator.IsAtEnd()){ - imageIteratorOut.Set(inputIterator.Get()); - ++inputIterator; - ++imageIteratorOut; - } - -} - - -#endif diff --git a/include/encode_filter.h b/include/encode_filter.h deleted file mode 100644 index 903912be28..0000000000 --- a/include/encode_filter.h +++ /dev/null @@ -1,54 +0,0 @@ -#ifndef __encode_Filter_h -#define __encode_Filter_h - -#include "itkImageToImageFilter.h" -#include "itkMacro.h" - - -template< class TImage, class AutoencoderModel, class NormalizerModel> -class ITK_EXPORT EncodeFilter:public itk::ImageToImageFilter< TImage, TImage > -{ - public: - // Standard class typedefs. - typedef EncodeFilter Self; - typedef itk::ImageToImageFilter< TImage, TImage > Superclass; - typedef itk::SmartPointer< Self > Pointer; - - // Method for creation through the object factory. - itkNewMacro(Self); - - // Run-time type information (and related methods). - itkTypeMacro(EncodeFilter, ImageToImageFilter); - - //void SetInputImage(const TImage* image); - void SetAutoencoderModel(const std::string encoderPath); - void SetNormalizerModel(const std::string NormalizerPath); - void SetModels( const AutoencoderModel net, const NormalizerModel normalizer); - std::size_t GetDimension(){return m_hidden_neuron;}; - protected: - EncodeFilter(); - ~EncodeFilter(){} - - typename TImage::ConstPointer GetInputImage(); - AutoencoderModel GetAutoencoderModel(); - NormalizerModel GetNormalizerModel(); - - // Does the real work. - virtual void GenerateOutputInformation(); - virtual void BeforeThreadedGenerateData(); - void ThreadedGenerateData(const typename TImage::RegionType &outputRegionForThread, unsigned int threadId) ITK_OVERRIDE; - - private: - EncodeFilter(const Self &); //purposely not implemented - void operator=(const Self &); //purposely not implemented - AutoencoderModel m_net; - NormalizerModel m_normalizer; - std::size_t m_hidden_neuron; -}; - -#ifndef ITK_MANUAL_INSTANTIATION -#include "encode_filter.txx" -#endif - - -#endif // __encode_Filter_h diff --git a/include/encode_filter.txx b/include/encode_filter.txx deleted file mode 100644 index a96b048f33..0000000000 --- a/include/encode_filter.txx +++ /dev/null @@ -1,165 +0,0 @@ -#ifndef __encode_filter_txx -#define __encode_filter_txx - -#include "encode_filter.h" -#include <fstream> - - -#include "itkObjectFactory.h" -#include "itkImageRegionIterator.h" -#include "itkImageRegionConstIterator.h" -#include "otbVectorImage.h" - - -#include <shark/Data/Csv.h> -#include <shark/Data/Pgm.h> //for exporting the learned filters -#include <shark/Data/SparseData.h>//for reading in the images as sparseData/Libsvm format -#include <shark/Models/Autoencoder.h>//normal autoencoder model -#include <shark/Models/TiedAutoencoder.h>//autoencoder with tied weights -#include <shark/Models/Normalizer.h> -#include <shark/Algorithms/Trainers/NormalizeComponentsUnitVariance.h> - - -//using namespace shark; - -template< class TImage, class AutoencoderModel, class NormalizerModel> -EncodeFilter<TImage, AutoencoderModel, NormalizerModel>::EncodeFilter() -{ - this->SetNumberOfRequiredInputs(1); -} - - -template< class TImage, class AutoencoderModel, class NormalizerModel> -void EncodeFilter<TImage, AutoencoderModel, NormalizerModel>::SetAutoencoderModel(const std::string encoderPath) -{ - //m_net = net; - std::ifstream ifs(encoderPath); - boost::archive::polymorphic_text_iarchive ia(ifs); - m_net.read(ia); - ifs.close(); - m_hidden_neuron = m_net.numberOfHiddenNeurons(); -} - - -template< class TImage, class AutoencoderModel, class NormalizerModel> -void EncodeFilter<TImage, AutoencoderModel, NormalizerModel>::SetNormalizerModel(const std::string NormalizerPath) -{ - //m_normalizer = normalizer; - std::ifstream ifs(NormalizerPath); - boost::archive::polymorphic_text_iarchive ia(ifs); - m_normalizer.read(ia); - ifs.close(); -} - - -template< class TImage, class AutoencoderModel, class NormalizerModel> -void EncodeFilter<TImage, AutoencoderModel, NormalizerModel>::SetModels(const AutoencoderModel net, const NormalizerModel normalizer) -{ - m_net = net; - m_normalizer = normalizer; -} - - -template< class TImage, class AutoencoderModel, class NormalizerModel> -typename TImage::ConstPointer EncodeFilter<TImage, AutoencoderModel, NormalizerModel>::GetInputImage() -{ - return static_cast< const TImage * > - ( this->itk::ProcessObject::GetInput(0) ); -} - - - -template< class TImage, class AutoencoderModel, class NormalizerModel> -AutoencoderModel EncodeFilter<TImage, AutoencoderModel, NormalizerModel>::GetAutoencoderModel() -{ - return m_net; -} - - -template< class TImage, class AutoencoderModel, class NormalizerModel> -NormalizerModel EncodeFilter<TImage, AutoencoderModel, NormalizerModel>::GetNormalizerModel() -{ - return m_normalizer; -} - - - -struct Data_with_info { - shark::Data<shark::RealVector> data; // This file format can be used to do Machine Learning with the Shark ML library - otb::VectorImage<double, 2>::RegionType region; - otb::VectorImage<double, 2>::PointType origin; - otb::VectorImage<double, 2>::SpacingType spacing; -}; - - -template< class TImage, class AutoencoderModel, class NormalizerModel> -void EncodeFilter<TImage, AutoencoderModel, NormalizerModel>::BeforeThreadedGenerateData() -{ -#ifdef _OPENMP -// OpenMP will take care of threading -this->SetNumberOfThreads(1); -#endif -} - -template< class TImage, class AutoencoderModel, class NormalizerModel> -void EncodeFilter<TImage, AutoencoderModel, NormalizerModel>::GenerateOutputInformation() -{ - Superclass::GenerateOutputInformation(); - this->GetOutput()->SetNumberOfComponentsPerPixel( m_hidden_neuron ); -} - -template< class TImage, class AutoencoderModel, class NormalizerModel> -void EncodeFilter<TImage, AutoencoderModel, NormalizerModel>::ThreadedGenerateData(const typename TImage::RegionType &outputRegionForThread, unsigned int threadId) -{ - //Data_with_info info; - typename TImage::ConstPointer input = this->GetInput(); - typename TImage::Pointer output = this->GetOutput(); - // Image to vector - const unsigned int img_bands = input->GetNumberOfComponentsPerPixel(); - - itk::ImageRegionConstIterator<TImage> inputIterator(input,outputRegionForThread); - - std::vector<shark::RealVector> image_vect; - - typename TImage::PixelType pixelValue; - while(!inputIterator.IsAtEnd()){ - shark::RealVector vect; - pixelValue = inputIterator.Get(); - for(unsigned int a = 0; a < img_bands; ++a){ - vect.push_back(pixelValue[a]); - } - image_vect.push_back(vect); - ++inputIterator; - } - shark::Data<shark::RealVector> data = shark::createDataFromRange(image_vect); - image_vect.clear(); - - /** Normalize the data */ - - data= transform(data, m_normalizer); - /** Encode the data */ - - data = m_net.encode(data); - - /** vector to image */ - - std::size_t numHidden = data.element(1).size(); - output->SetVectorLength(numHidden); - itk::ImageRegionIterator<TImage> imageIteratorOut(output,outputRegionForThread); - auto vect_it = data.elements().begin(); - while(!imageIteratorOut.IsAtEnd() && vect_it!=data.elements().end()){ - pixelValue.SetSize(numHidden); - shark::RealVector vect_out=(*vect_it); - for(unsigned int a = 0; a < numHidden; ++a){ - pixelValue[a]=vect_out[a]; - } - - imageIteratorOut.Set(pixelValue); - ++imageIteratorOut; - ++vect_it; - } - -} - - -#endif -- GitLab