Commit ff3773cf authored by Emmanuel Christophe's avatar Emmanuel Christophe

Exemple pour ThresholdToPointSet

parent 7ebfde84
......@@ -61,6 +61,10 @@ ADD_EXECUTABLE(SeamCarvingOtherExample SeamCarvingOtherExample.cxx)
TARGET_LINK_LIBRARIES(SeamCarvingOtherExample OTBIO OTBCommon OTBFeatureExtraction
ITKCommon ITKBasicFilters)
ADD_EXECUTABLE(ThresholdToPointSetExample ThresholdToPointSetExample.cxx)
TARGET_LINK_LIBRARIES(ThresholdToPointSetExample OTBIO OTBCommon OTBFeatureExtraction
ITKCommon ITKBasicFilters)
IF( NOT OTB_DISABLE_CXX_TESTING AND NOT OTB_DISABLE_CXX_EXAMPLES_TESTING )
SET(BASELINE ${OTB_DATA_ROOT}/Baseline/Examples/FeatureExtraction)
......
/*=========================================================================
Program: ORFEO Toolbox
Language: C++
Date: $Date$
Version: $Revision$
Copyright (c) Centre National d'Etudes Spatiales. All rights reserved.
See OTBCopyright.txt for details.
Some parts of this code are derived from ITK. See ITKCopyright.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.
=========================================================================*/
#if defined(_MSC_VER)
#pragma warning ( disable : 4786 )
#endif
#ifdef __BORLANDC__
#define ITK_LEAN_AND_MEAN
#endif
// Software Guide : BeginCommandLineArgs
// INPUTS: {ROISpot5.png}
// 250 252
// Software Guide : EndCommandLineArgs
// Software Guide : BeginLatex
//
// The following example illustrates the use of the
// \doxygen{otb}{ThresholdImageToPointSetFilter} which provide a list of points
// within given thresholds. Points set are described in section
// \ref{sec:PointSetSection} on page \pageref{sec:PointSetSection}.
//
// Software Guide : EndLatex
#include "otbImage.h"
#include "otbImageFileReader.h"
// Software Guide : BeginLatex
//
// The first step required to use this filter is to include the header
//
// Software Guide : EndLatex
// Software Guide : BeginCodeSnippet
#include "otbThresholdImageToPointSetFilter.h"
#include "itkPointSet.h"
// Software Guide : EndCodeSnippet
int main(int argc, char ** argv)
{
if( argc < 3 )
{
std::cerr << "Usage: " << argv[0] << " inputImageFile ";
std::cerr << " lowerThreshold upperThreshold" << std::endl;
return EXIT_FAILURE;
}
// Software Guide : BeginLatex
//
// The next step is to decide which pixel types to use for the input image
// and the Point Set as well as their dimension.
//
// Software Guide : EndLatex
// Software Guide : BeginCodeSnippet
typedef unsigned char PixelType;
const unsigned int Dimension = 2;
typedef otb::Image<PixelType, Dimension> ImageType;
typedef itk::PointSet<PixelType, Dimension> PointSetType;
// Software Guide : EndCodeSnippet
// Software Guide : BeginLatex
//
// A reader is instanciated to read the input image
//
// Software Guide : EndLatex
// Software Guide : BeginCodeSnippet
typedef otb::ImageFileReader< ImageType > ReaderType;
ReaderType::Pointer reader = ReaderType::New();
const char * filenamereader = argv[1];
reader->SetFileName( filenamereader );
// Software Guide : EndCodeSnippet
// Software Guide : BeginLatex
//
// We get the parameters from the command line for the threshold filter. The
// lower and upper thresholds parameters are similar to those of the
// \doxygen{itk}{BinaryThresholdImageFilter} (see Section
// \ref{sec:BinaryThresholdingImageFilter} on page
// \pageref{sec:BinaryThresholdingImageFilter} for more information).
//
// Software Guide : EndLatex
// Software Guide : BeginCodeSnippet
int lowerThreshold = atoi(argv[2]);
int upperThreshold = atoi(argv[3]);
// Software Guide : EndCodeSnippet
// Software Guide : BeginLatex
//
// Then we create the ThresholdImageToPointSetFilter and we pass the
// parameters.
//
// Software Guide : EndLatex
// Software Guide : BeginCodeSnippet
typedef otb::ThresholdImageToPointSetFilter
< ImageType, PointSetType > FilterThresholdType;
FilterThresholdType::Pointer filterThreshold = FilterThresholdType::New();
filterThreshold->SetLowerThreshold( lowerThreshold );
filterThreshold->SetUpperThreshold( upperThreshold );
filterThreshold->SetInput(0, reader->GetOutput() );
// Software Guide : EndCodeSnippet
// Software Guide : BeginLatex
//
// To manipulate and display the result of this filter, we manually
// instanciate a point set and we call the \code{Update()} method on the
// threshold filter to trigger the pipeline execution.
//
// After this step, the \code{pointSet} variable contains the point set.
//
// Software Guide : EndLatex
// Software Guide : BeginCodeSnippet
PointSetType::Pointer pointSet = PointSetType::New();
pointSet = filterThreshold->GetOutput();
filterThreshold->Update();
// Software Guide : EndCodeSnippet
// Software Guide : BeginLatex
//
// To display each point, we create an iterator on the list of points,
// which is accessible through the method \code{GetPoints()} of the PointSet.
//
// Software Guide : EndLatex
// Software Guide : BeginCodeSnippet
typedef PointSetType::PointsContainer ContainerType;
ContainerType* pointsContainer = pointSet->GetPoints();
typedef ContainerType::Iterator IteratorType;
IteratorType itList = pointsContainer->Begin();
// Software Guide : EndCodeSnippet
// Software Guide : BeginLatex
//
// A while loop enable us to through the list a display the coordinate of
// each point.
//
// Software Guide : EndLatex
// Software Guide : BeginCodeSnippet
while( itList != pointsContainer->End() )
{
std::cout << itList.Value() << std::endl;
++itList;
}
// Software Guide : EndCodeSnippet
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