Commit 54f40219 authored by Cyrille Valladeau's avatar Cyrille Valladeau
Browse files

ENH : add a detector filter + test

parent 592b8a3e
/*=========================================================================
Program: ORFEO Toolbox
Language: C++
Date: $Date$
Version: $Revision$
Copyright (c) Centre National d'Etudes Spatiales. All rights reserved.
See OTBCopyright.txt for details.
Copyright (c) CS Systemes d'information. All rights reserved.
See CSCopyright.txt for details.
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.
=========================================================================*/
#ifndef __otbEdgeDetectorImageFilter_h
#define __otbEdgeDetectorImageFilter_h
#include "itkImageToImageFilter.h"
#include "itkBinaryThresholdImageFilter.h"
/** \class EdgeDetectorImageFilter
* \brief This composite filter binaries a edge detection image output.
* The used edge detection filter is given as template of the class.
* The class only supports Image.
*
*/
namespace otb
{
template <class TInputImage, class TOutputImage , class TEdgeDetection>
class ITK_EXPORT EdgeDetectorImageFilter
: public itk::ImageToImageFilter<TInputImage, TOutputImage>
{
public:
/** Standard class typedefs. */
typedef EdgeDetectorImageFilter Self;
typedef itk::ImageToImageFilter<TInputImage,TOutputImage> Superclass ;
typedef itk::SmartPointer<Self> Pointer;
typedef itk::SmartPointer<const Self> ConstPointer;
/** Method for creation through the object factory. */
itkNewMacro(Self);
/** Run-time type information (and related methods). */
itkTypeMacro(EdgeDetectorImageFilter,itk::ImageToImageFilter);
/** Template parameters typedefs*/
typedef TInputImage InputImageType;
typedef TOutputImage OutputImageType;
typedef typename InputImageType::Pointer InputImagePointerType;
typedef typename InputImageType::PixelType InputImagePixelType;
typedef typename InputImageType::SizeType InputImageSizeType;
typedef typename OutputImageType::RegionType OutputImageRegionType;
typedef typename OutputImageType::Pointer OutputImagePointerType;
typedef typename OutputImageType::PixelType OutputImagePixelType;
/** Edge Detection */
typedef TEdgeDetection DetectionType;
typedef typename DetectionType::Pointer DetectionPointerType;
/** Thresholder filter : Otsu */
typedef itk::BinaryThresholdImageFilter<InputImageType, InputImageType> BinaryFilterType;
typedef typename BinaryFilterType::Pointer BinaryFilterPointerType;
/**Set/Get detector */
itkSetObjectMacro(Detector, DetectionType);
itkGetObjectMacro(Detector, DetectionType);
itkGetConstObjectMacro(Detector, DetectionType);
/**Set/Get binary filter */
itkSetObjectMacro(BinaryFilter, BinaryFilterType);
itkGetObjectMacro(BinaryFilter, BinaryFilterType);
//itkGetObjectMacro(DetectorImageFilter, DetectorImageType);
/** Set lower threshold value. */
void SetLowerThreshold(InputImagePixelType val)
{
m_BinaryFilter->SetLowerThreshold(val);
this->Modified();
}
/** Set upper threshold value. */
void SetUpperThreshold(InputImagePixelType val)
{
m_BinaryFilter->SetUpperThreshold(val);
this->Modified();
}
protected:
EdgeDetectorImageFilter();
virtual ~EdgeDetectorImageFilter();
virtual void PrintSelf(std::ostream& os, itk::Indent indent) const;
virtual void GenerateData( );
private:
EdgeDetectorImageFilter(const Self&); //purposely not implemented
void operator=(const Self&); //purposely not implemented
DetectionPointerType m_Detector;
BinaryFilterPointerType m_BinaryFilter;
};
}
#ifndef OTB_MANUAL_INSTANTIATION
#include "otbEdgeDetectorImageFilter.txx"
#endif
#endif
/*=========================================================================
Program: ORFEO Toolbox
Language: C++
Date: $Date$
Version: $Revision$
Copyright (c) Centre National d'Etudes Spatiales. All rights reserved.
See OTBCopyright.txt for details.
Copyright (c) CS systèmes d'information. All rights reserved.
See CSCopyright.txt for details.
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 "otbEdgeDetectorImageFilter.h"
namespace otb
{
/**---------------------------------------------------------
* Constructor
----------------------------------------------------------*/
template <class TInputImage , class TOutputImage, class TEdgeDetection>
EdgeDetectorImageFilter<TInputImage, TOutputImage, TEdgeDetection>
::EdgeDetectorImageFilter()
{
this->SetNumberOfRequiredInputs( 1 );
m_Detector = DetectionType::New();
m_BinaryFilter = BinaryFilterType::New();
m_BinaryFilter->SetInsideValue( static_cast<OutputImagePixelType>(1.) );
m_BinaryFilter->SetOutsideValue( static_cast<OutputImagePixelType>(0.) );
m_BinaryFilter->SetUpperThreshold( itk::NumericTraits<InputImagePixelType>::max() );
m_BinaryFilter->SetLowerThreshold( itk::NumericTraits<InputImagePixelType>::min() );
}
/*---------------------------------------------------------
* Destructor.c
----------------------------------------------------------*/
template <class TInputImage , class TOutputImage, class TEdgeDetection>
EdgeDetectorImageFilter<TInputImage, TOutputImage, TEdgeDetection>
::~EdgeDetectorImageFilter()
{}
/**
* threaded Generate Data
*/
template <class TInputImage , class TOutputImage, class TEdgeDetection>
void
EdgeDetectorImageFilter<TInputImage, TOutputImage, TEdgeDetection>
::GenerateData()
{
m_Detector->SetInput( this->GetInput() );
m_BinaryFilter->SetInput( m_Detector->GetOutput() );
m_BinaryFilter->GraftOutput(this->GetOutput());
m_BinaryFilter->Update();
this->GraftOutput(m_BinaryFilter->GetOutput());
/*
m_Detector->GraftOutput(this->GetOutput());
m_Detector->Update();
this->GraftOutput(m_Detector->GetOutput());
*/
}
/*----------------------------------------------------------------
PrintSelf
-----------------------------------------------------------------*/
template <class TInputImage , class TOutputImage, class TEdgeDetection>
void
EdgeDetectorImageFilter<TInputImage, TOutputImage, TEdgeDetection>
::PrintSelf(std::ostream& os, itk::Indent indent) const
{
Superclass::PrintSelf(os, indent);
}
}/** end namesapce otb*/
......@@ -26,6 +26,7 @@ SET(BASICFILTERS_TESTS8 ${CXX_TEST_PATH}/otbBasicFiltersTests8)
SET(BASICFILTERS_TESTS9 ${CXX_TEST_PATH}/otbBasicFiltersTests9)
SET(BASICFILTERS_TESTS10 ${CXX_TEST_PATH}/otbBasicFiltersTests10)
SET(BASICFILTERS_TESTS11 ${CXX_TEST_PATH}/otbBasicFiltersTests11)
SET(BASICFILTERS_TESTS12 ${CXX_TEST_PATH}/otbBasicFiltersTests12)
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ otbBasicFiltersTests1 ~~~~~~~~~~~~~~~~~~~~~~~~~~
......@@ -1048,7 +1049,7 @@ ADD_TEST(bfTvEdgeDensityImageFilter ${BASICFILTERS_TESTS9}
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ otbBasicFiltersTests10 ~~~~~~~~~~~~~~~~~~~~~~~~~~
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ otbBasicFiltersTests10 ~~~~~~~~~~~~~~~~~~~~~~~~~
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ADD_TEST(bfTuScalarImageTextureFunctorNew ${BASICFILTERS_TESTS10}
otbScalarImageTextureFunctorNew )
......@@ -1155,6 +1156,11 @@ ADD_TEST(bfTvPersistentVectorizationImageFilter ${BASICFILTERS_TESTS10}
${TEMP}/bfTvPersistentVectorizationImageFilterOutput.txt
)
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ otbBasicFiltersTests10 ~~~~~~~~~~~~~~~~~~~~~~~~~
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# ------- Combination ExtractROI and StremingResample ----------------------------
ADD_TEST(bfTvExtractROIResample ${BASICFILTERS_TESTS11}
......@@ -1442,6 +1448,30 @@ ADD_TEST(bfTvListSampleToHistogramListGenerator ${BASICFILTERS_TESTS11}
10 1
)
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ otbBasicFiltersTests12 ~~~~~~~~~~~~~~~~~~~~~~~~~
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# ------- otbEdgeDetectorImageFilter ----------------------------
ADD_TEST(bfTvEdgeDetectorImageFilterNew ${BASICFILTERS_TESTS12}
otbEdgeDetectorImageFilterNew
)
ADD_TEST(bfTvEdgeDetectorImageFilter ${BASICFILTERS_TESTS12}
--compare-image ${TOL}
${BASELINE}/bfTvEdgeDetectorImageFilter.tif
${TEMP}/bfTvEdgeDetectorImageFilter.tif
otbEdgeDetectorImageFilter
${INPUTDATA}/poupees_sub.png
${TEMP}/bfTvEdgeDetectorImageFilter.tif
50000 # lower threshold
2000000 # upper threshold
)
# A enrichir
SET(BasicFilters_SRCS1
otbLeeFilter.cxx
......@@ -1632,6 +1662,10 @@ otbListSampleToHistogramListGeneratorNew.cxx
otbListSampleToHistogramListGenerator.cxx
)
SET(BasicFilters_SRCS12
otbEdgeDetectorImageFilter.cxx
otbEdgeDetectorImageFilterNew.cxx
)
INCLUDE_DIRECTORIES("${OTBTesting_BINARY_DIR}")
......@@ -1668,4 +1702,7 @@ TARGET_LINK_LIBRARIES(otbBasicFiltersTests10 OTBBasicFilters OTBIO )
ADD_EXECUTABLE(otbBasicFiltersTests11 otbBasicFiltersTests11.cxx ${BasicFilters_SRCS11})
TARGET_LINK_LIBRARIES(otbBasicFiltersTests11 OTBBasicFilters ITKAlgorithms OTBIO )
ADD_EXECUTABLE(otbBasicFiltersTests12 otbBasicFiltersTests12.cxx ${BasicFilters_SRCS12})
TARGET_LINK_LIBRARIES(otbBasicFiltersTests12 OTBBasicFilters ITKAlgorithms OTBIO )
ENDIF( NOT OTB_DISABLE_CXX_TESTING AND BUILD_TESTING )
/*=========================================================================
Program: ORFEO Toolbox
Language: C++
Date: $Date$
Version: $Revision$
Copyright (c) Centre National d'Etudes Spatiales. All rights reserved.
See OTBCopyright.txt for details.
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.
=========================================================================*/
// this file defines the otbCommonTest for the test driver
// and all it expects is that you have a function called RegisterTests
#if defined(_MSC_VER)
#pragma warning ( disable : 4786 )
#endif
#include "otbTestMain.h"
void RegisterTests()
{
REGISTER_TEST(otbEdgeDetectorImageFilter);
REGISTER_TEST(otbEdgeDetectorImageFilterNew);
}
/*=========================================================================
Program: ORFEO Toolbox
Language: C++
Date: $Date$
Version: $Revision$
Copyright (c) Centre National d'Etudes Spatiales. All rights reserved.
See OTBCopyright.txt for details.
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 "otbImage.h"
#include "otbEdgeDetectorImageFilter.h"
#include "otbImageFileReader.h"
#include "otbImageFileWriter.h"
#include "itkSobelEdgeDetectionImageFilter.h"
int otbEdgeDetectorImageFilter(int argc, char* argv[] )
{
typedef double PixelType;
typedef otb::Image< PixelType, 2 > ImageType;
typedef otb::ImageFileReader<ImageType> ReaderType;
typedef otb::ImageFileWriter<ImageType> WriterType;
typedef itk::SobelEdgeDetectionImageFilter<ImageType , ImageType> SobelDetectionType;
typedef otb::EdgeDetectorImageFilter<ImageType, ImageType, SobelDetectionType> DetectorType;
/**Instancitation of an object*/
ReaderType::Pointer reader = ReaderType::New();
WriterType::Pointer writer = WriterType::New();
DetectorType::Pointer detector = DetectorType::New();
SobelDetectionType::Pointer sobelFilter = SobelDetectionType::New();
reader->SetFileName(argv[1]);
detector->SetInput(reader->GetOutput());
detector->SetLowerThreshold(static_cast<PixelType>(atof(argv[3])));
detector->SetUpperThreshold(static_cast<PixelType>(atof(argv[4])));
writer->SetFileName(argv[2]);
writer->SetInput(detector->GetOutput());
writer->Update();
return EXIT_SUCCESS;
}
/*=========================================================================
Program: ORFEO Toolbox
Language: C++
Date: $Date$
Version: $Revision$
Copyright (c) Centre National d'Etudes Spatiales. All rights reserved.
See OTBCopyright.txt for details.
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 "otbImage.h"
#include "otbEdgeDetectorImageFilter.h"
#include "itkSobelEdgeDetectionImageFilter.h"
int otbEdgeDetectorImageFilterNew(int, char* [] )
{
typedef double PixelType;
typedef otb::Image< PixelType, 2 > ImageType;
typedef itk::SobelEdgeDetectionImageFilter<ImageType, ImageType> SobelType;
typedef otb::EdgeDetectorImageFilter<ImageType, ImageType, SobelType> FilterType;
/**Instancitation of an object*/
FilterType::Pointer filter = FilterType::New();
return EXIT_SUCCESS;
}
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