Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
otb
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
273
Issues
273
List
Boards
Labels
Service Desk
Milestones
Merge Requests
8
Merge Requests
8
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Packages & Registries
Packages & Registries
Container Registry
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Main Repositories
otb
Commits
ab05eac0
Commit
ab05eac0
authored
Jan 09, 2010
by
Manuel Grizonnet
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ADD:add labelmaptovectordata
parent
ab6fccf0
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
180 additions
and
0 deletions
+180
-0
Examples/OBIA/LabelMapToVectorData.cxx
Examples/OBIA/LabelMapToVectorData.cxx
+180
-0
No files found.
Examples/OBIA/LabelMapToVectorData.cxx
0 → 100644
View file @
ab05eac0
/*=========================================================================
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.
=========================================================================*/
// Software Guide : BeginLatex
//
// \index{otb::LabelMapToVectorDataFilter}
//
//
// This class vectorizes a LabelObject to a VectorData.
//
// LabelMapToVectorDataFilter converts a LabelMap to a
// VectorData where all the pixels get the attribute value of the label object they belong.
// It uses the class otbLabelObjectToPolygonFunctor wich follows a finite states machine described in:
//
// "An algorithm for the rapid computation of boundaries of run-length
// encoded regions", Francis K. H. Queck, in Pattern Recognition 33
// (2000), p 1637-1649.
//
// This filter converts label object to polygons.
// Software Guide : EndLatex
#include "otbImageFileReader.h"
#include "otbVectorDataFileWriter.h"
#include "otbVectorData.h"
#include "otbVectorDataProjectionFilter.h"
#include <fstream>
#include <iostream>
#include "otbImage.h"
#include "otbLabelMapToVectorDataFilter.h"
#include "otbAttributesMapLabelObject.h"
#include "itkLabelImageToLabelMapFilter.h"
int
main
(
int
argc
,
char
*
argv
[])
{
/** Use the labelObjecttopolygon functor (not thread safe) only polygon conversion is available yet*/
if
(
argc
!=
3
)
{
std
::
cerr
<<
"Usage: "
<<
argv
[
0
];
std
::
cerr
<<
" inputImageFile outputVectorfile(shp)"
<<
std
::
endl
;
return
EXIT_FAILURE
;
}
const
char
*
infname
=
argv
[
1
];
const
char
*
outfname
=
argv
[
2
];
// Software Guide : BeginLatex
//
// The image types are now defined using pixel types and
// dimension. The input image is defined as an \doxygen{itk}{Image},
// the output is a \doxygen{otb}{VectorData}.
//
// Software Guide : EndLatex
// Software Guide : BeginCodeSnippet
const
unsigned
int
Dimension
=
2
;
typedef
unsigned
short
LabelType
;
typedef
otb
::
Image
<
LabelType
,
Dimension
>
LabeledImageType
;
typedef
otb
::
VectorData
<
double
,
2
>
VectorDataType
;
// Software Guide : EndCodeSnippet
// We instantiate reader and writer types
typedef
otb
::
ImageFileReader
<
LabeledImageType
>
LabeledReaderType
;
typedef
otb
::
VectorDataFileWriter
<
VectorDataType
>
WriterType
;
// Label map typedef
// Software Guide : BeginLatex
//
// The Attribute Label Map is
// instantiated using the image pixel types as template parameters.
// The LabelObjectToPolygonFunctor is instantiated with LabelObjectType and PolygonType
// Software Guide : EndLatex
// Software Guide : BeginCodeSnippet
typedef
otb
::
AttributesMapLabelObject
<
LabelType
,
Dimension
,
double
>
LabelObjectType
;
typedef
itk
::
LabelMap
<
LabelObjectType
>
LabelMapType
;
typedef
itk
::
LabelImageToLabelMapFilter
<
LabeledImageType
,
LabelMapType
>
LabelMapFilterType
;
typedef
otb
::
Polygon
<
double
>
PolygonType
;
typedef
otb
::
Functor
::
LabelObjectToPolygonFunctor
<
LabelObjectType
,
PolygonType
>
FunctorType
;
typedef
VectorDataType
::
DataNodeType
DataNodeType
;
typedef
otb
::
VectorDataProjectionFilter
<
VectorDataType
,
VectorDataType
>
VectorDataFilterType
;
LabeledReaderType
::
Pointer
lreader
=
LabeledReaderType
::
New
();
WriterType
::
Pointer
writer
=
WriterType
::
New
();
// Software Guide : BeginLatex
//
// Now the input image is set and a name is given to the output image.
//
// Software Guide : EndLatex
// Software Guide : BeginCodeSnippet
lreader
->
SetFileName
(
infname
);
writer
->
SetFileName
(
outfname
);
// Software Guide : EndCodeSnippet
// Software Guide : BeginLatex
//
// Then, the
// Here each whyte region connected regions are converted. So the background is define all zero pixels.
// Software Guide : EndLatex
// Software Guide : BeginCodeSnippet
LabelMapFilterType
::
Pointer
labelMapFilter
=
LabelMapFilterType
::
New
();
labelMapFilter
->
SetInput
(
lreader
->
GetOutput
());
labelMapFilter
->
SetBackgroundValue
(
itk
::
NumericTraits
<
LabelType
>::
min
());
labelMapFilter
->
Update
();
// Software Guide : EndCodeSnippet
// Software Guide : BeginLatex
//
// Then, the \doxygen{otb}{LabelMapToVectorDataFilter} is instantiated.
// Software Guide : EndLatex
// Software Guide : BeginCodeSnippet
typedef
otb
::
LabelMapToVectorDataFilter
<
LabelMapType
,
VectorDataType
>
LabelMapToVectorDataFilterType
;
LabelMapToVectorDataFilterType
::
Pointer
MyFilter
=
LabelMapToVectorDataFilterType
::
New
();
MyFilter
->
SetInput
(
labelMapFilter
->
GetOutput
());
MyFilter
->
Update
();
MyFilter
->
GetOutput
()
->
SetProjectionRef
(
lreader
->
GetOutput
()
->
GetProjectionRef
());
// Software Guide : EndCodeSnippet
// Software Guide : BeginLatex
//
// The output can be passed to a writer.
//
// Software Guide : EndLatex
// Software Guide : BeginCodeSnippet
writer
->
SetInput
(
MyFilter
->
GetOutput
());
// Software Guide : BeginCodeSnippet
// Software Guide : BeginLatex
//
// The invocation of the \code{Update()} method on the writer triggers the
// execution of the pipeline. It is recommended to place update calls in a
// \code{try/catch} block in case errors occur and exceptions are thrown.
//
// Software Guide : EndLatex
// Software Guide : BeginCodeSnippet
try
{
writer
->
Update
();
return
EXIT_SUCCESS
;
}
catch
(
itk
::
ExceptionObject
&
excep
)
{
std
::
cerr
<<
"Exception caught !"
<<
std
::
endl
;
std
::
cerr
<<
excep
<<
std
::
endl
;
}
// Software Guide : EndCodeSnippet
catch
(
...
)
{
std
::
cout
<<
"Unknown exception !"
<<
std
::
endl
;
return
EXIT_FAILURE
;
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment