La migration est terminée. Bien qu'elle a été beaucoup plus longue que prévue, elle s'est bien déroulée. N'hésitez pas à signaler tout problème à forge.support@irstea.fr.

Commit d5cea606 authored by Cresson Remi's avatar Cresson Remi

Initial commit

parents
project(MLUtils)
otb_module_impl()
This is free software under the GNU Affero General Public License v3.0. See
http://www.gnu.org/licenses/agpl.html for details.
# Machine Learning Utils
This module contains applications dedicated to machine learning
## License
Please see the license for legal issues on the use of the software (GNU Affero General Public License v3.0).
## Contact
Rémi Cresson (IRSTEA)
cmake_minimum_required (VERSION 2.8)
OTB_CREATE_APPLICATION(NAME ClassificationMapMosaic
SOURCES otbClassificationMapMosaic.cxx
LINK_LIBRARIES OTBCommon)
/*=========================================================================
Copyright (c) Remi Cresson (IRSTEA). All rights reserved.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notices for more information.
=========================================================================*/
#include "itkFixedArray.h"
#include "itkObjectFactory.h"
#include "otbWrapperApplicationFactory.h"
// Application engine
#include "otbStandardFilterWatcher.h"
#include "itkFixedArray.h"
// Filter
#include "otbClassificationMapMosaicFilter.h"
namespace otb
{
namespace Wrapper
{
class ClassificationMapMosaic : public Application
{
public:
/** Standard class typedefs. */
typedef ClassificationMapMosaic Self;
typedef Application Superclass;
typedef itk::SmartPointer<Self> Pointer;
typedef itk::SmartPointer<const Self> ConstPointer;
/** Standard macro */
itkNewMacro(Self);
itkTypeMacro(ClassificationMapMosaic, Application);
/** Filter */
typedef otb::ClassificationMapMosaicFilter<FloatVectorImageType, FloatVectorImageType, double> FilterType;
void DoUpdateParameters()
{
}
void DoInit()
{
// Documentation
SetName("ClassificationMapMosaic");
SetDocName("ClassificationMapMosaic");
SetDescription("Mosaic multiple classification maps");
SetDocLongDescription("The application perform the mosaicing of multiple classification maps ");
SetDocAuthors("Remi Cresson");
AddParameter(ParameterType_InputImageList, "il", "Input classification maps");
AddParameter(ParameterType_OutputImage, "out", "output classification map");
SetDefaultOutputPixelType("out", ImagePixelType_uint8);
}
void DoExecute()
{
// Get the input image list
FloatVectorImageListType::Pointer inputArray = this->GetParameterImageList("il");
m_Filter = FilterType::New();
for (unsigned int i = 0 ; i < inputArray->Size() ; i++)
{
m_Filter->PushBackInput(inputArray->GetNthElement(i) );
}
}
private:
FilterType::Pointer m_Filter;
}; // end of class
} // end namespace wrapper
} // end namespace otb
OTB_APPLICATION_EXPORT( otb::Wrapper::ClassificationMapMosaic )
#ifndef __ClassificationMapMosaicFilter_H
#define __ClassificationMapMosaicFilter_H
#include "otbStreamingMosaicFilterBase.h"
namespace otb
{
/** \class ClassificationMapMosaicFilter
* \brief Computes the mosaic of an input classification map set.
*
* \ingroup MLUtils
*/
template <class TInputImage, class TOutputImage=TInputImage, class TInternalValueType=double>
class ITK_EXPORT ClassificationMapMosaicFilter : public otb::StreamingMosaicFilterBase<TInputImage, TOutputImage,
TInternalValueType>
{
public:
/** Standard Self typedef */
typedef ClassificationMapMosaicFilter Self;
typedef otb::StreamingMosaicFilterBase<TInputImage, TOutputImage, TInternalValueType> Superclass;
typedef itk::SmartPointer<Self> Pointer;
typedef itk::SmartPointer<const Self> ConstPointer;
/** Method for creation through the object factory. */
itkNewMacro(Self);
/** Runtime information support. */
itkTypeMacro(ClassificationMapMosaicFilter, StreamingMosaicFilterBase);
/** Input image typedefs. */
typedef typename Superclass::InputImageType InputImageType;
typedef typename Superclass::InputImagePixelType InputImagePixelType;
typedef typename Superclass::IteratorType IteratorType;
typedef typename Superclass::InterpolatorPointerType InterpolatorPointerType;
typedef typename Superclass::InputImageRegionType InputImageRegionType;
/** Output image typedefs. */
typedef typename Superclass::OutputImageType OutputImageType;
typedef typename Superclass::OutputImagePointType OutputImagePointType;
typedef typename Superclass::OutputImagePixelType OutputImagePixelType;
typedef typename Superclass::OutputImageInternalPixelType OutputImageInternalPixelType;
typedef typename Superclass::OutputImageRegionType OutputImageRegionType;
/** Internal computing typedef support. */
typedef typename Superclass::InternalValueType InternalValueType;
typedef typename Superclass::InternalPixelType InternalPixelType;
protected:
ClassificationMapMosaicFilter() {
}
virtual ~ClassificationMapMosaicFilter() {
}
/** Overrided methods */
virtual void GenerateOutputInformation(void);
virtual void ThreadedGenerateData(const OutputImageRegionType& outputRegionForThread, itk::ThreadIdType threadId );
private:
ClassificationMapMosaicFilter(const Self&); //purposely not implemented
void operator=(const Self&); //purposely not implemented
}; // end of class
} // end namespace otb
#ifndef OTB_MANUAL_INSTANTIATION
#include "otbClassificationMapMosaicFilter.txx"
#endif
#endif
#ifndef __ClassificationMapMosaicFilter_txx
#define __ClassificationMapMosaicFilter_txx
#include "otbClassificationMapMosaicFilter.h"
namespace otb {
template <class TInputImage, class TOutputImage, class TInternalValueType>
void
ClassificationMapMosaicFilter<TInputImage, TOutputImage, TInternalValueType>
::GenerateOutputInformation(void)
{
Superclass::GenerateOutputInformation();
// Output pixel has 1 channel
unsigned int outNbBands = 1;
OutputImageType * outputPtr = this->GetOutput();
outputPtr->SetNumberOfComponentsPerPixel(outNbBands);
// No data value is 255
OutputImagePixelType noDataPix;
noDataPix.SetSize(outNbBands);
noDataPix.Fill(255);
this->SetNoDataOutputPixel(noDataPix);
}
/**
* Processing
*/
template <class TInputImage, class TOutputImage, class TInternalValueType>
void
ClassificationMapMosaicFilter<TInputImage, TOutputImage, TInternalValueType>
::ThreadedGenerateData(const OutputImageRegionType& outputRegionForThread, itk::ThreadIdType threadId)
{
// Debug info
itkDebugMacro(<<"Actually executing thread " << threadId << " in region " << outputRegionForThread);
// Support progress methods/callbacks
itk::ProgressReporter progress(this, threadId, outputRegionForThread.GetNumberOfPixels() );
// Get output pointer
OutputImageType * mosaicImage = this->GetOutput();
// Get number of used inputs
const unsigned int nbOfUsedInputImages = Superclass::GetNumberOfUsedInputImages();
// Get number of bands
const unsigned int nBands = Superclass::GetNumberOfBands();
// Iterate through the thread region
IteratorType outputIt(mosaicImage, outputRegionForThread);
// Prepare interpolated pixel
InternalPixelType interpolatedMathPixel;
interpolatedMathPixel.SetSize(nBands);
// Prepare input pointers, interpolators, and valid regions (input images)
typename std::vector<InputImageType *> currentImage;
typename std::vector<InterpolatorPointerType> interp;
Superclass::PrepareImageAccessors(currentImage, interp);
// Container for geo coordinates
OutputImagePointType geoPoint;
InputImagePixelType tmpPixel(Superclass::GetNoDataInputPixel() );
bool isData;
for ( outputIt.GoToBegin(); !outputIt.IsAtEnd(); ++outputIt )
{
// Prepare output pixel
tmpPixel.Fill(0);
isData = false;
OutputImagePixelType outPixel(Superclass::GetNoDataOutputPixel() );
// Current pixel --> Geographical point
mosaicImage->TransformIndexToPhysicalPoint (outputIt.GetIndex(), geoPoint) ;
// Loop on used input images
for (unsigned int i = 0 ; i < nbOfUsedInputImages ; i++)
{
// Check if the point is inside the transformed thread region
// (i.e. the region in the current input image which match the thread
// region)
if (interp[i]->IsInsideBuffer(geoPoint) )
{
// Compute the interpolated pixel value
InputImagePixelType interpolatedPixel = interp[i]->Evaluate(geoPoint);
// Check that interpolated pixel is not empty
if (Superclass::IsPixelNotEmpty(interpolatedPixel) )
{
// Update the output pixel
isData = true;
for (unsigned int band = 0 ; band < nBands ; band++)
{
tmpPixel[band] += interpolatedPixel[band];
}
} // Interpolated pixel is not empty
} // point inside buffer
} // next image
// Update output pixel value
if (isData)
{
OutputImageInternalPixelType argmax = 0;
float max = -1.0;
for (unsigned int band = 0 ; band < nBands ; band++)
{
if (tmpPixel[band] > max)
{
argmax = band;
max = tmpPixel[band];
}
}
outPixel[0] = argmax;
}
outputIt.Set(outPixel);
// Update progress
progress.CompletedPixel();
} // next output pixel
}
} // end namespace gtb
#endif
set(DOCUMENTATION "Machine learning utils")
otb_module(MLUtils
DEPENDS
OTBITK
OTBCommon
OTBApplicationEngine
Mosaic
TEST_DEPENDS
OTBTestKernel
OTBCommandLine
DESCRIPTION
$DOCUMENTATION
)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment