Skip to content
Snippets Groups Projects
Commit 3d87a383 authored by Otmane Lahlou's avatar Otmane Lahlou
Browse files

ENH : add a Maximum Image Calculator (for DrawLine filter ) and possibility to...

ENH : add a Maximum Image Calculator (for DrawLine filter ) and possibility to tune parameters (Angle & distance)
parent fa4dc209
No related branches found
No related tags found
No related merge requests found
/*=========================================================================
Program: ORFEO Toolbox
Language: C++
Date: $Date$
Version: $Revision$
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) 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 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.
=========================================================================*/
......@@ -28,6 +28,7 @@
#include "otbLineSpatialObjectList.h"
#include "otbDrawLineSpatialObjectListFilter.h"
#include "otbLineSegmentDetector.h"
#include "itkMinimumMaximumImageCalculator.h"
// Software Guide : BeginCommandLineArgs
// INPUTS: {qb_RoadExtract2.tif}
......@@ -58,6 +59,9 @@ int main( int argc, char * argv[] )
const char * outfname = argv[2];
const char * inprettyfname = argv[3];
const char * outprettyfname = argv[4];
double angleThreshold = atof(argv[5]);
double distanceThreshold = atof(argv[6]);
const unsigned int Dimension = 2;
typedef float PixelType;
......@@ -70,115 +74,131 @@ int main( int argc, char * argv[] )
reader->SetFileName(infname);
WriterType::Pointer writer = WriterType::New();
// Software Guide : BeginLatex
//
// After defining, as usual, the types for the input image and the
// image reader, we define the specific types needed for this
// example. First of all, we will use a list of line spatial objects
// to store the detected lines which will be provided by the line
// segment detector.
//
// Software Guide : EndLatex
// Software Guide : BeginLatex
//
// After defining, as usual, the types for the input image and the
// image reader, we define the specific types needed for this
// example. First of all, we will use a list of line spatial objects
// to store the detected lines which will be provided by the line
// segment detector.
//
// Software Guide : EndLatex
// Software Guide : BeginCodeSnippet
// Software Guide : BeginCodeSnippet
typedef otb::LineSpatialObjectList LinesListType;
// Software Guide : EndCodeSnippet
// Software Guide : BeginLatex
//
// The right angle detector's output is a pointset where each point
// gives the coordinate of the detected angle. In the data field of
// the pointset, the 2 lines which define the right angle are stored
// in a vector. Therefore we define the 2 following types.
//
// Software Guide : EndLatex
// Software Guide : EndCodeSnippet
// Software Guide : BeginLatex
//
// The right angle detector's output is a pointset where each point
// gives the coordinate of the detected angle. In the data field of
// the pointset, the 2 lines which define the right angle are stored
// in a vector. Therefore we define the 2 following types.
//
// Software Guide : EndLatex
// Software Guide : BeginCodeSnippet
// Software Guide : BeginCodeSnippet
typedef LinesListType::LineType LineType;
typedef std::vector<LineType*> LineVectorType;
// Software Guide : EndCodeSnippet
// Software Guide : BeginLatex
//
// And we can now define the pointset type for storing all the
// information related to the detected right angles.
//
// Software Guide : EndLatex
// Software Guide : EndCodeSnippet
// Software Guide : BeginLatex
//
// And we can now define the pointset type for storing all the
// information related to the detected right angles.
//
// Software Guide : EndLatex
// Software Guide : BeginCodeSnippet
// Software Guide : BeginCodeSnippet
typedef itk::PointSet<LineVectorType, Dimension> PointSetType;
// Software Guide : EndCodeSnippet
// Software Guide : BeginLatex
//
// We define the type for the line segment detector. A detailed
// example for this detector can be found in section \ref{sec:LSD}.
//
// Software Guide : EndLatex
// Software Guide : BeginLatex
//
// We define the type for the line segment detector. A detailed
// example for this detector can be found in section \ref{sec:LSD}.
//
// Software Guide : EndLatex
// Software Guide : BeginCodeSnippet
// Software Guide : BeginCodeSnippet
typedef otb::LineSegmentDetector<ImageType , PixelType> LsdFilterType;
// Software Guide : EndCodeSnippet
// Software Guide : BeginLatex
//
// We can finally define the type for the right angle detection
// filter. This filter is templated over the input image type, the
// type of the lines provided by the line segment detector, and the
// output pointset type containing the detected right angles.
//
// Software Guide : EndLatex
// Software Guide : BeginCodeSnippet
// Software Guide : BeginLatex
//
// We can finally define the type for the right angle detection
// filter. This filter is templated over the input image type, the
// type of the lines provided by the line segment detector, and the
// output pointset type containing the detected right angles.
//
// Software Guide : EndLatex
typedef itk::MinimumMaximumImageCalculator<ImageType> MinMaxFilterType;
// Software Guide : BeginCodeSnippet
typedef otb::LineSpatialObjectListToRightAnglePointSetFilter<ImageType,
LinesListType, PointSetType>
RightAngleFilterType;
LinesListType, PointSetType>
RightAngleFilterType;
// Software Guide : EndCodeSnippet
// Software Guide : BeginLatex
//
// We instantiate the line segment detector and the right angle detector.
//
// Software Guide : EndLatex
// Software Guide : EndCodeSnippet
// Software Guide : BeginLatex
//
// We instantiate the line segment detector and the right angle detector.
//
// Software Guide : EndLatex
// Software Guide : BeginCodeSnippet
// Software Guide : BeginCodeSnippet
LsdFilterType::Pointer lsdFilter = LsdFilterType::New();
RightAngleFilterType::Pointer rightAngleFilter =
RightAngleFilterType::New();
RightAngleFilterType::Pointer rightAngleFilter = RightAngleFilterType::New();
// Software Guide : EndCodeSnippet
// Software Guide : BeginLatex
//
// We plug the pipeline. The right angle detector has 2 inputs: the
// image to be processed and the previously detected lines.
//
// Software Guide : EndLatex
// Software Guide : EndCodeSnippet
MinMaxFilterType::Pointer minmaxCalculator = MinMaxFilterType::New();
// Software Guide : BeginLatex
//
// We plug the pipeline. The right angle detector has 2 inputs: the
// image to be processed and the previously detected lines.
//
// Software Guide : EndLatex
// Software Guide : BeginCodeSnippet
// Software Guide : BeginCodeSnippet
lsdFilter->SetInput(reader->GetOutput());
rightAngleFilter->SetInputImage(reader->GetOutput());
rightAngleFilter->SetInput(lsdFilter->GetOutput());
// Software Guide : EndCodeSnippet
// Software Guide : BeginLatex
//
// You can qualify how far the right angle must the segments be, and the tolerance
// to consider an angle between two segments as an right one.
//
rightAngleFilter->SetThresholdAngle(angleThreshold);
rightAngleFilter->SetThresholdDistance(distanceThreshold);
//
// Software Guide : EndLatex
// Software Guide : BeginCodeSnippet
rightAngleFilter->Update();
// Software Guide : EndCodeSnippet
// Software Guide : BeginLatex
//
// We will now draw the right angles on top of the inout image. For
// this, we get the output of the right angle detector.
//
// Software Guide : EndLatex
// Software Guide : EndCodeSnippet
// Software Guide : BeginLatex
//
// We will now draw the right angles on top of the inout image. For
// this, we get the output of the right angle detector.
//
// Software Guide : EndLatex
// Software Guide : BeginCodeSnippet
// Software Guide : BeginCodeSnippet
PointSetType::Pointer segmentOrtho = PointSetType::New();
segmentOrtho = rightAngleFilter->GetOutput();
// Software Guide : EndCodeSnippet
// Software Guide : BeginLatex
//
// We will iterate through the pointset and get the lines which define
// each right angle stored inside each point of the pointset. The
// lines will be stored into a line list.
//
// Software Guide : EndLatex
// Software Guide : BeginLatex
//
// We will iterate through the pointset and get the lines which define
// each right angle stored inside each point of the pointset. The
// lines will be stored into a line list.
//
// Software Guide : EndLatex
// Software Guide : BeginCodeSnippet
// Software Guide : BeginCodeSnippet
PointSetType::PointType pRight;
LineVectorType outputVectorLines;
LinesListType::Pointer outputLinesList = LinesListType::New();
......@@ -186,54 +206,57 @@ int main( int argc, char * argv[] )
for (unsigned int i = 0; i<segmentOrtho->GetNumberOfPoints(); i++)
{
// Software Guide : EndCodeSnippet
// Software Guide : BeginLatex
//
// Even if we do not use it in this example, we show here how to get
// the coordinates of the right angle.
//
// Software Guide : EndLatex
// Software Guide : BeginCodeSnippet
// Software Guide : BeginLatex
//
// Even if we do not use it in this example, we show here how to get
// the coordinates of the right angle.
//
// Software Guide : EndLatex
// Software Guide : BeginCodeSnippet
segmentOrtho->GetPoint(i, &pRight);
// Software Guide : EndCodeSnippet
// Software Guide : BeginLatex
//
// The lines associated to a given angle are obtained using the
// \code{GetPointData} method of the pointset. Then they are stored
// into the list of lines.
//
// Software Guide : EndLatex
// Software Guide : BeginCodeSnippet
// Software Guide : BeginLatex
//
// The lines associated to a given angle are obtained using the
// \code{GetPointData} method of the pointset. Then they are stored
// into the list of lines.
//
// Software Guide : EndLatex
// Software Guide : BeginCodeSnippet
segmentOrtho->GetPointData(i, &outputVectorLines);
outputLinesList->push_back(outputVectorLines[0]);
outputLinesList->push_back(outputVectorLines[1]);
}
// Software Guide : EndCodeSnippet
// Software Guide : BeginLatex
//
// We will use the \doxygen{otb}{DrawLineSpatialObjectListFilter} to
// draw the list of lines on top of the input image.
//
// Software Guide : EndLatex
// Software Guide : EndCodeSnippet
minmaxCalculator->SetImage(reader->GetOutput());
minmaxCalculator->ComputeMaximum();
// Software Guide : BeginLatex
//
// We will use the \doxygen{otb}{DrawLineSpatialObjectListFilter} to
// draw the list of lines on top of the input image.
// The value assigned to the line is the maximum of the input image.
// Software Guide : EndLatex
// Software Guide : BeginCodeSnippet
// Software Guide : BeginCodeSnippet
typedef otb::DrawLineSpatialObjectListFilter< ImageType,
ImageType > DrawLineListType;
ImageType > DrawLineListType;
DrawLineListType::Pointer drawLineFilter = DrawLineListType::New();
drawLineFilter->SetInput(reader->GetOutput());
drawLineFilter->SetInputLineSpatialObjectList(outputLinesList);
drawLineFilter->SetValue(minmaxCalculator->GetMaximum());
writer->SetInput(drawLineFilter->GetOutput());
writer->SetFileName(outfname);
reader->GenerateOutputInformation();
writer->Update();
// Software Guide : EndCodeSnippet
// Software Guide : BeginLatex
// Software Guide : BeginLatex
// Figure~\ref{fig:RIGHTANGLE_FILTER} shows the result of applying
// the right angle detection filter to an image.
// \begin{figure}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment