Commit 5b035c87 authored by Guillaume Pasero's avatar Guillaume Pasero

ENH: new filter to generate boundaries from a segmentation

parent 2e89f406
/*=========================================================================
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
......@@ -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)
/*=========================================================================
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;
}
/*=========================================================================
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;
}
......@@ -7,4 +7,6 @@ void RegisterTests()
REGISTER_TEST(otbLabelizeNeighborhoodConnectedImageFilterNew);
REGISTER_TEST(otbLabelizeNeighborhoodConnectedImageFilter);
REGISTER_TEST(otbLabelizeConfidenceConnectedImageFilterNew);
REGISTER_TEST(otbLabelToBoundaryImageFilter);
REGISTER_TEST(otbLabelToBoundaryImageFilterNew);
}
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