Commit e60455a2 authored by Cédric Traizet's avatar Cédric Traizet

REFAC: remove hough filters

parent ae21c3f0
size of the Line list 8
[19, 9] [0, 8]
[18, 39] [19, 20]
[18, 48] [18, 40]
[39, 9] [20, 8]
[20, 39] [21, 20]
[20, 48] [21, 40]
[48, 9] [40, 8]
[48, 35] [40, 24]
......@@ -19,7 +19,4 @@
#
project(OTBEdge)
set(OTBEdge_LIBRARIES OTBEdge)
otb_module_impl()
/*
* Copyright (C) 2005-2019 Centre National d'Etudes Spatiales (CNES)
*
* This file is part of Orfeo Toolbox
*
* https://www.orfeo-toolbox.org/
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef otbExtractSegmentsImageFilter_h
#define otbExtractSegmentsImageFilter_h
#include "otbPixelSuppressionByDirectionImageFilter.h"
#include "otbLocalHoughFilter.h"
#include "otbFillGapsFilter.h"
#include "otbDrawLineSpatialObjectListFilter.h"
#include "itkRescaleIntensityImageFilter.h"
namespace otb
{
/** \class ExtractSegmentsImageFilter
*
* This class implements a composite filter that generate an image of segments
* primitives. It combines four filters :
* - otb::PixelSuppressionByDirectionImageFilter
* - otb::LocalHoughFilter
* - otb::FillGapsFilter
* - otb::DrawLineSpatialObjectListFilter
*
*
* \ingroup OTBEdge
*/
template <class TInputImage,
class TOutputImage>
class ITK_EXPORT ExtractSegmentsImageFilter :
public itk::ImageToImageFilter<TInputImage, TOutputImage>
{
public:
itkStaticConstMacro(InputImageDimension,
unsigned int,
TInputImage::ImageDimension);
itkStaticConstMacro(OutputImageDimension,
unsigned int,
TOutputImage::ImageDimension);
typedef TInputImage InputImageType;
typedef TOutputImage OutputImageType;
typedef TInputImage PSOutputImageType;
typedef ExtractSegmentsImageFilter Self;
typedef itk::ImageToImageFilter<InputImageType, OutputImageType> Superclass;
typedef itk::SmartPointer<Self> Pointer;
typedef itk::SmartPointer<const Self> ConstPointer;
itkNewMacro(Self);
itkTypeMacro(ExtractSegmentsImageFilter, itk::ImageToImageFilter);
typedef typename InputImageType::PixelType InputPixelType;
typedef typename InputImageType::SizeType SizeType;
typedef typename OutputImageType::PixelType OutputPixelType;
/** Definition of the list of lines. */
typedef LineSpatialObjectList LinesListType;
/** Set/Get the radius of the region of the pixel suppression by direction image filter. */
void SetPixelSuppressionRadius(SizeType Radius);
const SizeType GetPixelSuppressionRadius();
/** Set/Get Angular Accuracy on the direction of the central pixel for
the pixel suppression by direction image filter. */
void SetPixelSuppressionAngularBeam(float AngularBeam);
float GetPixelSuppressionAngularBeam();
/** Set/Get the radius used to define the region of local hough filter. */
void SetLocalHoughRadius(SizeType Radius);
const SizeType GetLocalHoughRadius();
/** Set/Get the number of lines we are looking for in the local hough filter. */
void SetLocalHoughNumberOfLines(unsigned int Radius);
unsigned int GetLocalHoughNumberOfLines();
/** Set/Get the radius of the disc to remove from the accumulator
* for each line found */
void SetLocalHoughDiscRadius(float DiscRadius);
float GetLocalHoughDiscRadius();
/** Set/Get the variance of the gaussian bluring for the accumulator */
void SetLocalHoughVariance(float Variance);
float GetLocalHoughVariance();
/** Set/Get the radius between two segments in the fill gaps filter. */
void SetFillGapsRadius(float Radius);
float GetFillGapsRadius();
/** Set/Get Angular Beam between two segments in the fill gaps filter. */
void SetFillGapsAngularBeam(float AngularBeam);
float GetFillGapsAngularBeam();
/** Set/Get the image input of this filter. */
void SetInputImage(const InputImageType *image);
const InputImageType * GetInputImage();
/** Set/Get the image direction of this filter. */
void SetInputImageDirection(const InputImageType *image);
const InputImageType * GetInputImageDirection();
/** Set/Get the value of the drawed line*/
itkGetMacro(LineValue, typename OutputImageType::PixelType);
itkSetMacro(LineValue, typename OutputImageType::PixelType);
protected:
ExtractSegmentsImageFilter();
~ExtractSegmentsImageFilter() override {}
typedef PixelSuppressionByDirectionImageFilter<InputImageType, PSOutputImageType> PixelSuppressionType;
typedef LocalHoughFilter<InputImageType> LocalHoughType;
typedef FillGapsFilter FillGapsType;
typedef DrawLineSpatialObjectListFilter<InputImageType, OutputImageType> DrawLineListType;
typedef itk::RescaleIntensityImageFilter<TInputImage, TInputImage> RescaleType;
void GenerateData() override;
void PrintSelf(std::ostream& os, itk::Indent indent) const override;
private:
ExtractSegmentsImageFilter(const Self &) = delete;
void operator =(const Self&) = delete;
typename OutputImageType::PixelType m_LineValue;
typename PixelSuppressionType::Pointer m_PixelSuppression;
typename LocalHoughType::Pointer m_LocalHough;
typename FillGapsType::Pointer m_FillGaps;
typename DrawLineListType::Pointer m_DrawLineList;
typename RescaleType::Pointer m_Rescaler;
};
} // end namespace otb
#ifndef OTB_MANUAL_INSTANTIATION
#include "otbExtractSegmentsImageFilter.hxx"
#endif
#endif
/*
* Copyright (C) 2005-2019 Centre National d'Etudes Spatiales (CNES)
*
* This file is part of Orfeo Toolbox
*
* https://www.orfeo-toolbox.org/
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef otbExtractSegmentsImageFilter_hxx
#define otbExtractSegmentsImageFilter_hxx
#include "otbExtractSegmentsImageFilter.h"
namespace otb
{
/**
*
*/
template <class TInputImage, class TOutputImage>
ExtractSegmentsImageFilter<TInputImage, TOutputImage>
::ExtractSegmentsImageFilter()
{
this->SetNumberOfRequiredInputs(2);
this->SetNumberOfRequiredOutputs(1);
m_PixelSuppression = PixelSuppressionType::New();
m_LocalHough = LocalHoughType::New();
m_FillGaps = FillGapsType::New();
m_DrawLineList = DrawLineListType::New();
m_Rescaler = RescaleType::New();
m_LineValue = static_cast<typename OutputImageType::PixelType>(255.);
}
/**
* Set/Get image input
*/
template <class TInputImage, class TOutputImage>
void ExtractSegmentsImageFilter<TInputImage, TOutputImage>
::SetInputImage(const InputImageType *image)
{
this->SetInput(0, image);
}
template <class TInputImage, class TOutputImage>
const typename ExtractSegmentsImageFilter<TInputImage, TOutputImage>::InputImageType *
ExtractSegmentsImageFilter<TInputImage, TOutputImage>
::GetInputImage()
{
return static_cast<const InputImageType *>
(this->GetInput(0));
}
/**
* Set/Get image direction input
*/
template <class TInputImage, class TOutputImage>
void ExtractSegmentsImageFilter<TInputImage, TOutputImage>
::SetInputImageDirection(const InputImageType *image)
{
this->SetInput(1, image);
}
template <class TInputImage, class TOutputImage>
const typename ExtractSegmentsImageFilter<TInputImage, TOutputImage>::InputImageType *
ExtractSegmentsImageFilter<TInputImage, TOutputImage>
::GetInputImageDirection()
{
return static_cast<const InputImageType *>
(this->GetInput(1));
}
/**
* Set/Get PixelSuppressionyDirectionImageFilter parameters
*/
template <class TInputImage, class TOutputImage>
void ExtractSegmentsImageFilter<TInputImage, TOutputImage>
::SetPixelSuppressionRadius(SizeType Radius)
{
m_PixelSuppression->SetRadius(Radius);
}
template <class TInputImage, class TOutputImage>
const typename ExtractSegmentsImageFilter<TInputImage, TOutputImage>::SizeType
ExtractSegmentsImageFilter<TInputImage, TOutputImage>
::GetPixelSuppressionRadius()
{
return (m_PixelSuppression->GetRadius());
}
template <class TInputImage, class TOutputImage>
void ExtractSegmentsImageFilter<TInputImage, TOutputImage>
::SetPixelSuppressionAngularBeam(float AngularBeam)
{
m_PixelSuppression->SetAngularBeam(AngularBeam);
}
template <class TInputImage, class TOutputImage>
float
ExtractSegmentsImageFilter<TInputImage, TOutputImage>
::GetPixelSuppressionAngularBeam()
{
return (m_PixelSuppression->GetAngularBeam());
}
/**
* Set/Get LocalHoughFilter parameters
*/
template <class TInputImage, class TOutputImage>
void ExtractSegmentsImageFilter<TInputImage, TOutputImage>
::SetLocalHoughRadius(SizeType Radius)
{
m_LocalHough->SetRadius(Radius);
}
template <class TInputImage, class TOutputImage>
const typename ExtractSegmentsImageFilter<TInputImage, TOutputImage>::SizeType
ExtractSegmentsImageFilter<TInputImage, TOutputImage>
::GetLocalHoughRadius()
{
return (m_LocalHough->GetRadius());
}
template <class TInputImage, class TOutputImage>
void ExtractSegmentsImageFilter<TInputImage, TOutputImage>
::SetLocalHoughNumberOfLines(unsigned int NumberOfLines)
{
m_LocalHough->SetNumberOfLines(NumberOfLines);
}
template <class TInputImage, class TOutputImage>
unsigned int
ExtractSegmentsImageFilter<TInputImage, TOutputImage>
::GetLocalHoughNumberOfLines()
{
return (m_LocalHough->GetNumberOfLines());
}
template <class TInputImage, class TOutputImage>
void ExtractSegmentsImageFilter<TInputImage, TOutputImage>
::SetLocalHoughDiscRadius(float DiscRadius)
{
m_LocalHough->SetDiscRadius(DiscRadius);
}
template <class TInputImage, class TOutputImage>
float
ExtractSegmentsImageFilter<TInputImage, TOutputImage>
::GetLocalHoughDiscRadius()
{
return (m_LocalHough->GetDiscRadius());
}
template <class TInputImage, class TOutputImage>
void ExtractSegmentsImageFilter<TInputImage, TOutputImage>
::SetLocalHoughVariance(float Variance)
{
m_LocalHough->SetVariance(Variance);
}
template <class TInputImage, class TOutputImage>
float
ExtractSegmentsImageFilter<TInputImage, TOutputImage>
::GetLocalHoughVariance()
{
return (m_LocalHough->GetVariance());
}
/**
* Set/Get FillGapsFilter parameters
*/
template <class TInputImage, class TOutputImage>
void ExtractSegmentsImageFilter<TInputImage, TOutputImage>
::SetFillGapsRadius(float Radius)
{
m_FillGaps->SetRadius(Radius);
}
template <class TInputImage, class TOutputImage>
float
ExtractSegmentsImageFilter<TInputImage, TOutputImage>
::GetFillGapsRadius()
{
return (m_FillGaps->GetRadius());
}
template <class TInputImage, class TOutputImage>
void ExtractSegmentsImageFilter<TInputImage, TOutputImage>
::SetFillGapsAngularBeam(float AngularBeam)
{
m_FillGaps->SetAngularBeam(AngularBeam);
}
template <class TInputImage, class TOutputImage>
float
ExtractSegmentsImageFilter<TInputImage, TOutputImage>
::GetFillGapsAngularBeam()
{
return (m_FillGaps->GetAngularBeam());
}
template <class TInputImage, class TOutputImage>
void
ExtractSegmentsImageFilter<TInputImage, TOutputImage>
::GenerateData()
{
m_PixelSuppression->SetInputImage(this->GetInputImage());
m_PixelSuppression->SetInputImageDirection(this->GetInputImageDirection());
m_Rescaler->SetInput(m_PixelSuppression->GetOutput());
m_LocalHough->SetInput(m_Rescaler->GetOutput());
m_FillGaps->SetInput (m_LocalHough->GetOutput());
m_DrawLineList->SetInput(this->GetInputImage());
m_DrawLineList->SetInputLineSpatialObjectList(m_FillGaps->GetOutput());
m_DrawLineList->SetValue(m_LineValue);
m_DrawLineList->GraftOutput(this->GetOutput());
m_DrawLineList->Update();
this->GraftOutput(m_DrawLineList->GetOutput());
}
/**
* Standard "PrintSelf" method
*/
template <class TInputImage, class TOutput>
void
ExtractSegmentsImageFilter<TInputImage, TOutput>
::PrintSelf(std::ostream& os, itk::Indent indent) const
{
Superclass::PrintSelf(os, indent);
/* os << indent << "Length: " << m_LengthLine << std::endl;
os << indent << "Width: " << m_WidthLine << std::endl; */
}
} // end namespace otb
#endif
/*
* Copyright (C) 2005-2019 Centre National d'Etudes Spatiales (CNES)
*
* This file is part of Orfeo Toolbox
*
* https://www.orfeo-toolbox.org/
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef otbFillGapsFilter_h
#define otbFillGapsFilter_h
#include "itkProcessObject.h"
#include "otbLineSpatialObjectList.h"
namespace otb
{
/** \class FillGapsFilter
* \brief To be documented
*
* \ingroup OTBEdge
*/
class ITK_EXPORT FillGapsFilter : public itk::ProcessObject
{
public:
/** Standard class typedefs. */
typedef FillGapsFilter Self;
typedef itk::ProcessObject 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(FillGapsFilter, itk::ProcessObject);
/** Some convenient typedefs. */
typedef LineSpatialObjectList LineSpatialObjectListType;
typedef LineSpatialObjectListType::Pointer LineSpatialObjectListPointer;
typedef LineSpatialObjectListType::LineType LineSpatialObjectType;
typedef LineSpatialObjectType::PointListType PointListType;
typedef LineSpatialObjectType::LinePointType PointType;
typedef itk::ProcessObject ProcessObjectType;
using Superclass::SetInput;
void SetInput(const LineSpatialObjectListType * input);
const LineSpatialObjectListType * GetInput();
LineSpatialObjectListType * GetOutput();
itkSetMacro(AngularBeam, double);
itkGetConstReferenceMacro(AngularBeam, double);
itkSetMacro(Radius, double);
itkGetConstReferenceMacro(Radius, double);
protected:
FillGapsFilter();
~FillGapsFilter() override {}
void PrintSelf(std::ostream& os, itk::Indent indent) const override;
void GenerateData() override;
private:
FillGapsFilter(const Self &) = delete;
void operator =(const Self&) = delete;
double m_AngularBeam;
double m_Radius;
};
} // end namespace otb
#endif
/*
* Copyright (C) 2005-2019 Centre National d'Etudes Spatiales (CNES)
*
* This file is part of Orfeo Toolbox
*
* https://www.orfeo-toolbox.org/
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef otbHoughTransform2DLinesImageFilter_h
#define otbHoughTransform2DLinesImageFilter_h
#include "itkImageToImageFilter.h"
#include "otbImage.h"
#include "itkLineSpatialObject.h"
namespace otb
{
/**
* \class HoughTransform2DLinesImageFilter
* \brief Performs the Hough Transform to find 2D straight lines
* in a 2D image.
*
* This filter derives from ImageToImageFilter
* The input is an image, and all pixels above some threshold are those
* to be extracted. The output is the image of the accumulator.
* GetLines() returns a list of LinesSpatialObjects
*
* Lines are parameterized in the form: R = x*std::cos(Teta)+y*std::sin(Teta)
* where R is the perpendicular distance from the origin and Teta
* the angle with the normal.
*
* The output is the accumulator array:
* -The first dimension (X) represents the distance R from the origin
* to the line. This is the distance axis. Its size depends on the size
* of the diagonal of the input image.
*
* -The second dimension (Y) represents the angle between the X axis
* and the normal to the line. This is the angle axis. Its size depends
* on the AngleAxisSize parameter (500 by default) and its bounds can be
* set with the AngleAxisMinimum and AngleAxisMaximum parameters
* (-PI and +PI by default).
*
* \ingroup ImageFeatureExtraction
* \sa LineSpatialObject
*
*
* \ingroup OTBEdge
* */
template<typename TInputPixelType, typename TOutputPixelType>
class ITK_EXPORT HoughTransform2DLinesImageFilter :
public itk::ImageToImageFilter< Image<TInputPixelType, 2>, Image<TOutputPixelType, 2> >
{
public:
/** Standard "Self" typedef. */
typedef HoughTransform2DLinesImageFilter Self;
/** Input Image typedef */
typedef otb::Image<TInputPixelType, 2> InputImageType;
typedef typename InputImageType::Pointer InputImagePointer;
typedef typename InputImageType::ConstPointer InputImageConstPointer;
/** Output Image typedef */
typedef otb::Image<TOutputPixelType, 2> OutputImageType;
typedef typename OutputImageType::Pointer OutputImagePointer;
/** Smart pointer typedef support. */
typedef itk::SmartPointer<Self> Pointer;
typedef itk::SmartPointer<const Self> ConstPointer;
/** Line typedef */
typedef itk::LineSpatialObject<2> LineType;
typedef typename LineType::Pointer LinePointer;
typedef std::list<LinePointer> LinesListType;
typedef LineType::LinePointType LinePointType;
/** Standard "Superclass" typedef. */
typedef itk::ImageToImageFilter<InputImageType, OutputImageType> Superclass;
/** Image index typedef */
typedef typename InputImageType::IndexType IndexType;
/** Image pixel value typedef */
typedef typename InputImageType::PixelType PixelType;
/** Typedef to describe the output image region type. */
typedef typename InputImageType::RegionType OutputImageRegionType;
/** Run-time type information (and related methods). */
itkTypeMacro(HoughTransform2DLinesImageFilter, ImageToImageFilter);
/** Method for creation through the object factory. */
itkNewMacro(Self);
/** Method for evaluating the implicit function over the image. */
void GenerateData() override;
/** Accessors for the threshold above which the filter should consider
the point as a valid point */
itkSetMacro(Threshold, float);
itkGetMacro(Threshold, float);
/** Accessors for the parameters of the angle axis.
The Hough space describes (in the angle direction)
[AngleAxisMinimum, AngleAxisMaximum[ with AngleAxisSize values */
/** Accessors for the size of the angle axis */
itkSetMacro(AngleAxisSize, unsigned int);
itkGetMacro(AngleAxisSize, unsigned int);
/** Accessors for the minimum of the angle axis */
itkSetMacro(AngleAxisMinimum, double);
itkGetMacro(AngleAxisMinimum, double);
/** Accessors for the maximum of the angle axis */
itkSetMacro(AngleAxisMaximum, double);
itkGetMacro(AngleAxisMaximum, double);
/** Accessors for the parameters of the distance axis.
The Hough space describes (in the distance direction)
[DistanceAxisMinimum, DistanceAxisMaximum[ with DistanceAxisSize values */
/** Accessors for the actual size of the Distance axis */
itkSetMacro(DistanceAxisSize, unsigned int);
itkGetMacro(DistanceAxisSize, unsigned int);
/** Accessors for the maximum size of the Distance axis */
itkGetMacro(DistanceAxisMaximumSize, unsigned int);
/** Accessors for the minimum of the Distance axis */
itkSetMacro(DistanceAxisMinimum, double);
itkGetMacro(DistanceAxisMinimum, double);
/** Accessors for the maximum of the Distance axis */
itkSetMacro(DistanceAxisMaximum, double);
itkGetMacro(DistanceAxisMaximum, double);
/** Set/Get the number of lines to extract */
itkSetMacro(NumberOfLines, unsigned int);
itkGetMacro(NumberOfLines, unsigned int);
/** Set/Get the radius of the disc to remove from the accumulator
* for each line found */