Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Main Repositories
otb
Commits
5b035c87
Commit
5b035c87
authored
Apr 16, 2015
by
Guillaume Pasero
Browse files
ENH: new filter to generate boundaries from a segmentation
parent
2e89f406
Changes
5
Hide whitespace changes
Inline
Side-by-side
Modules/Segmentation/Labelling/include/otbLabelToBoundaryImageFilter.h
0 → 100644
View file @
5b035c87
/*=========================================================================
Program: Insight Segmentation & Registration Toolkit
Module: $RCSfile: itkRelabelComponentImageFilter.h, v $
Language: C++
Date: $Date: 2009-04-27 22:58:48 $
Version: $Revision: 1.17 $
Copyright (c) Insight Software Consortium. All rights reserved.
See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm 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.
=========================================================================*/
#ifndef __otbLabelToBoundaryImageFilter_h
#define __otbLabelToBoundaryImageFilter_h
#include
"otbUnaryFunctorNeighborhoodImageFilter.h"
namespace
otb
{
namespace
Functor
{
/**
* \class LabelToBoundaryFunctor
*
* \brief Functor to extract segmentation boundaries
*
* Functor intended to work with 3x3 neighborhood and scalar label image
* The generated boundary is 1-pixel wide, so it is not symetric.
* Output value is 1 on the boundaries and 0 in the background
*
*/
template
<
class
TInput
,
class
TOutput
>
class
LabelToBoundaryFunctor
{
public:
LabelToBoundaryFunctor
()
{
}
virtual
~
LabelToBoundaryFunctor
()
{
}
TOutput
operator
()
(
const
TInput
&
input
)
{
unsigned
char
output
=
1
;
if
(
input
.
GetCenterPixel
()
==
input
.
GetPixel
(
5
)
&&
input
.
GetCenterPixel
()
==
input
.
GetPixel
(
7
)
&&
input
.
GetCenterPixel
()
==
input
.
GetPixel
(
8
))
{
output
=
0
;
}
return
static_cast
<
TOutput
>
(
output
);
}
};
// end of class
}
// end of Functor namespace
/**
* \class LabelToBoundaryImageFilter
*
* \brief Filter to extract boundaries of a label image
*
* Filter intended to work with a scalar label image.
* The generated boundary is 1-pixel wide, so it is not symetric.
* Output value is 1 on the boundaries and 0 in the background
*
*/
template
<
class
TInputImage
,
class
TOutputImage
>
class
ITK_EXPORT
LabelToBoundaryImageFilter
:
public
UnaryFunctorNeighborhoodImageFilter
<
TInputImage
,
TOutputImage
,
Functor
::
LabelToBoundaryFunctor
<
typename
itk
::
ConstNeighborhoodIterator
<
TInputImage
>
,
typename
TOutputImage
::
PixelType
>
>
{
public:
typedef
LabelToBoundaryImageFilter
Self
;
typedef
UnaryFunctorNeighborhoodImageFilter
<
TInputImage
,
TOutputImage
,
Functor
::
LabelToBoundaryFunctor
<
typename
itk
::
ConstNeighborhoodIterator
<
TInputImage
>
,
typename
TOutputImage
::
PixelType
>
>
Superclass
;
typedef
itk
::
SmartPointer
<
Self
>
Pointer
;
typedef
itk
::
SmartPointer
<
const
Self
>
ConstPointer
;
itkNewMacro
(
Self
);
itkTypeMacro
(
LabelToBoundaryImageFilter
,
UnaryFunctorNeighborhoodImageFilter
);
protected:
LabelToBoundaryImageFilter
()
{
this
->
SetRadius
(
1
);
}
virtual
~
LabelToBoundaryImageFilter
()
{
}
private:
LabelToBoundaryImageFilter
(
const
Self
&
);
// Not implemented
void
operator
=
(
const
Self
&
);
// Not implemented
};
// end of class
}
// end of otb namespace
#endif
Modules/Segmentation/Labelling/test/CMakeLists.txt
View file @
5b035c87
...
...
@@ -8,6 +8,8 @@ otbLabelizeConnectedThresholdImageFilterNew.cxx
otbLabelizeNeighborhoodConnectedImageFilterNew.cxx
otbLabelizeNeighborhoodConnectedImageFilter.cxx
otbLabelizeConfidenceConnectedImageFilterNew.cxx
otbLabelToBoundaryImageFilterNew.cxx
otbLabelToBoundaryImageFilter.cxx
)
add_executable
(
otbLabellingTestDriver
${
OTBLabellingTests
}
)
...
...
@@ -57,3 +59,14 @@ otb_add_test(NAME bfTvLabelizeNeighborhoodConnectedImageFilter COMMAND otbLabell
otb_add_test
(
NAME bfTuLabelizeConfidenceConnectedImageFilterNew COMMAND otbLabellingTestDriver
otbLabelizeConfidenceConnectedImageFilterNew
)
otb_add_test
(
NAME bfTuLabelToBoundaryImageFilterNew COMMAND otbLabellingTestDriver
otbLabelToBoundaryImageFilterNew
)
otb_add_test
(
NAME bfTvLabelToBoundaryImageFilter COMMAND otbLabellingTestDriver
--compare-image
${
EPSILON_7
}
${
BASELINE
}
/bfTvLabelToBoundaryImageFilterOutput.tif
${
TEMP
}
/bfTvLabelToBoundaryImageFilterOutput.tif
otbLabelToBoundaryImageFilter
${
INPUTDATA
}
/maur_labelled.tif
${
TEMP
}
/bfTvLabelToBoundaryImageFilterOutput.tif
)
Modules/Segmentation/Labelling/test/otbLabelToBoundaryImageFilter.cxx
0 → 100644
View file @
5b035c87
/*=========================================================================
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.
=========================================================================*/
#include
"otbLabelToBoundaryImageFilter.h"
#include
"otbImageFileReader.h"
#include
"otbImageFileWriter.h"
#include
"otbImage.h"
int
otbLabelToBoundaryImageFilter
(
int
argc
,
char
*
argv
[])
{
typedef
unsigned
int
InputPixelType
;
typedef
unsigned
char
OutputPixelType
;
const
unsigned
int
Dimension
=
2
;
typedef
otb
::
Image
<
InputPixelType
,
Dimension
>
InputImageType
;
typedef
otb
::
Image
<
OutputPixelType
,
Dimension
>
OutputImageType
;
typedef
otb
::
ImageFileReader
<
InputImageType
>
ReaderType
;
typedef
otb
::
ImageFileWriter
<
OutputImageType
>
WriterType
;
typedef
otb
::
LabelToBoundaryImageFilter
<
InputImageType
,
OutputImageType
>
BoundaryFilterType
;
typedef
BoundaryFilterType
::
Pointer
BoundaryFilterPointerType
;
if
(
argc
!=
3
)
{
std
::
cerr
<<
"Usage : "
<<
argv
[
0
]
<<
" input_label_image output_boundary"
<<
std
::
endl
;
return
EXIT_FAILURE
;
}
std
::
string
inputPath
(
argv
[
1
]);
std
::
string
outputPath
(
argv
[
2
]);
ReaderType
::
Pointer
reader
=
ReaderType
::
New
();
reader
->
SetFileName
(
inputPath
);
BoundaryFilterPointerType
filter
=
BoundaryFilterType
::
New
();
filter
->
SetInput
(
reader
->
GetOutput
());
WriterType
::
Pointer
writer
=
WriterType
::
New
();
writer
->
SetInput
(
filter
->
GetOutput
());
writer
->
SetFileName
(
outputPath
);
writer
->
Update
();
return
EXIT_SUCCESS
;
}
Modules/Segmentation/Labelling/test/otbLabelToBoundaryImageFilterNew.cxx
0 → 100644
View file @
5b035c87
/*=========================================================================
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.
=========================================================================*/
#include
"otbLabelToBoundaryImageFilter.h"
#include
"otbImage.h"
int
otbLabelToBoundaryImageFilterNew
(
int
itkNotUsed
(
argc
),
char
*
itkNotUsed
(
argv
)
[])
{
typedef
unsigned
int
InputPixelType
;
typedef
unsigned
char
OutputPixelType
;
const
unsigned
int
Dimension
=
2
;
typedef
otb
::
Image
<
InputPixelType
,
Dimension
>
InputImageType
;
typedef
otb
::
Image
<
OutputPixelType
,
Dimension
>
OutputImageType
;
typedef
otb
::
LabelToBoundaryImageFilter
<
InputImageType
,
OutputImageType
>
BoundaryFilterType
;
typedef
BoundaryFilterType
::
Pointer
BoundaryFilterPointerType
;
BoundaryFilterPointerType
filter
=
BoundaryFilterType
::
New
();
std
::
cout
<<
filter
<<
std
::
endl
;
return
EXIT_SUCCESS
;
}
Modules/Segmentation/Labelling/test/otbLabellingTestDriver.cxx
View file @
5b035c87
...
...
@@ -7,4 +7,6 @@ void RegisterTests()
REGISTER_TEST
(
otbLabelizeNeighborhoodConnectedImageFilterNew
);
REGISTER_TEST
(
otbLabelizeNeighborhoodConnectedImageFilter
);
REGISTER_TEST
(
otbLabelizeConfidenceConnectedImageFilterNew
);
REGISTER_TEST
(
otbLabelToBoundaryImageFilter
);
REGISTER_TEST
(
otbLabelToBoundaryImageFilterNew
);
}
Write
Preview
Supports
Markdown
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