1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173
|
/*
* Copyright (C) 2005-2017 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 otbLocalHoughFilter_h
#define otbLocalHoughFilter_h
#include "itkUnaryFunctorImageFilter.h"
#include "itkHoughTransform2DLinesImageFilter.h"
#include "otbImageToLineSpatialObjectListFilter.h"
#include "otbExtractROI.h"
namespace otb
{
/** \class LocalHoughFilter
* \brief Application of Hough filter on a nxm pixel tiling of the image.
*
* This class implements a filter that applies the hough transform on nxm
* pixel tiling of the image. The Hough filter is used to find straight
* lines in a 2-dimensional image. It detects the best line in each tile
* and suppresses dubious line detection due to small local structures.
*
* Input parameters are : the tile radius, the number of lines we are
* looking for, the variance of the accumulator blurring (default = 5) and
* the radius of the disc to remove from the accumulator (default = 10).
*
*
* \ingroup OTBEdge
*/
template <class TInputImage>
class ITK_EXPORT LocalHoughFilter : public ImageToLineSpatialObjectListFilter<TInputImage>
{
public:
/** Standard class typedefs. */
typedef LocalHoughFilter Self;
typedef ImageToLineSpatialObjectListFilter<TInputImage> Superclass;
typedef itk::SmartPointer<Self> Pointer;
typedef itk::SmartPointer<const Self> ConstPointer;
/** Method for management of the "object factory". */
itkNewMacro(Self);
/** Return the name of the class. */
itkTypeMacro(LocalHoughFilter, ImageToLineSpatialObjectListFilter);
/** Definition of the list of lines. */
typedef typename Superclass::LinesListType LinesListType;
typedef typename LinesListType::const_iterator LineIterator;
typedef typename LinesListType::LineType LineType;
typedef typename LineType::Pointer LinePointer;
typedef typename LineType::PointListType PointListType;
typedef typename LineType::LinePointType LinePointType;
/** Extract dimensions as well of the images of entry of exit. */
itkStaticConstMacro(InputImageDimension,
unsigned int,
TInputImage::ImageDimension);
typedef TInputImage InputImageType;
//------------------------------------------------------------
typedef unsigned char OutputPixelType;
typedef otb::Image<OutputPixelType, 2> OutputImageType;
//-----------------------------------------------
/** Definition of the pixel type of the input and output images */
typedef typename InputImageType::PixelType InputPixelType;
typedef float AccumulatorPixelType;
typedef typename InputImageType::RegionType InputImageRegionType;
/** Definition of the size of the images. */
typedef typename InputImageType::SizeType SizeType;
typedef typename InputImageType::RegionType::IndexType IndexType;
/** Typedefs to define the extract ROI filter. */
typedef ExtractROI<InputPixelType, InputPixelType> ROIFilterType;
/** Set the radius of the local region where to apply the Hough filter. */
itkSetMacro(Radius, SizeType);
/** Get the radius of the local region. */
itkGetConstReferenceMacro(Radius, SizeType);
/** Set the radius of the overlap of the local region where to apply the Hough filter. */
itkSetMacro(Overlap, SizeType);
/** Get the radius of the overlap. */
itkGetConstReferenceMacro(Overlap, SizeType);
/** Set the number of lines we are looking for. */
itkSetMacro(NumberOfLines, unsigned int);
/** Get the number of lines we are looking for. */
itkGetConstReferenceMacro(NumberOfLines, unsigned int);
/** Set/Get the radius of the disc to remove from the accumulator
* for each line found */
itkSetMacro(DiscRadius, float);
itkGetMacro(DiscRadius, float);
/** Set/Get the variance of the gaussian bluring for the accumulator */
itkSetMacro(Variance, float);
itkGetMacro(Variance, float);
itkSetMacro(Threshold, float);
itkGetMacro(Threshold, float);
protected:
LocalHoughFilter();
~LocalHoughFilter() override {}
void PrintSelf(std::ostream& os, itk::Indent indent) const override;
/** Definition of the Hough Filter. */
typedef itk::HoughTransform2DLinesImageFilter<InputPixelType, AccumulatorPixelType> HoughFilterType;
void GenerateData() override;
private:
LocalHoughFilter(const Self &); //purposely not implemented
void operator =(const Self&); //purposely not implemented
/** Radius used to define the local region. */
SizeType m_Radius;
/** Radius used to define the overlap of local regions. */
SizeType m_Overlap;
/** Parameter of the Hough filter : number of lines we are looking for. */
unsigned int m_NumberOfLines;
/** Variance of the accumulator blurring (default = 5). */
float m_Variance;
/** Radius of the disc to remove from the accumulator (default = 10). */
float m_DiscRadius;
/** Threshold abouve which a pixel is consedered as valid */
float m_Threshold;
LinePointer LinePointResearch(LineIterator itLines, InputImageType *localImage, IndexType origin);
};
} // end namespace otb
#ifndef OTB_MANUAL_INSTANTIATION
#include "otbLocalHoughFilter.txx"
#endif
#endif
|