Commit d972e961 authored by Jordi Inglada's avatar Jordi Inglada

DOC: draft for the attribute computation example

parent dc0f57e8
......@@ -4,6 +4,9 @@ INCLUDE_REGULAR_EXPRESSION("^.*$")
ADD_EXECUTABLE(ImageToLabelToImage ImageToLabelToImage.cxx )
TARGET_LINK_LIBRARIES(ImageToLabelToImage OTBCommon OTBIO ${OTB_IO_UTILITIES_DEPENDENT_LIBRARIES})
ADD_EXECUTABLE(ShapeAttributeComputation ShapeAttributeComputation.cxx )
TARGET_LINK_LIBRARIES(ShapeAttributeComputation OTBCommon OTBIO ${OTB_IO_UTILITIES_DEPENDENT_LIBRARIES})
IF( NOT OTB_DISABLE_CXX_TESTING AND BUILD_TESTING )
......@@ -32,6 +35,15 @@ ADD_TEST( trTeOBIAImageToLabelToImageTest ${EXE_TESTS}
1 1108 0
)
ADD_TEST(trTeOBIAShapeAttributeComputation ${EXE_TESTS}
--compare-ascii ${EPS}
${BASELINE}/OBIAShapeAttribute.txt
${TEMP}/OBIAShapeAttribute.txt
ShapeAttributeComputationTest
${INPUTDATA}/MSLabeledOutput.tif
${TEMP}/OBIAShapeAttribute.txt
)
INCLUDE_DIRECTORIES(${OTB_SOURCE_DIR}/Testing/Code)
ADD_EXECUTABLE(otbOBIAExamplesTests otbOBIAExamplesTests.cxx)
TARGET_LINK_LIBRARIES(otbOBIAExamplesTests ITKAlgorithms ITKStatistics ITKNumerics OTBBasicFilters OTBCommon OTBDisparityMap OTBIO OTBSpatialReasoning OTBChangeDetection OTBFeatureExtraction OTBLearning OTBMultiScale OTBFusion OTBTesting)
......
/*=========================================================================
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 : BeginCommandLineArgs
// INPUTS: {MSLabeledOutput.tif}
// OUTPUTS: {OBIAShapeAttribute.txt}
// Software Guide : EndCommandLineArgs
// Software Guide : BeginLatex
//
// This example shows the
//
// Software Guide : EndLatex
// Software Guide : BeginCodeSnippet
#include "itkShapeLabelObject.h"
#include "itkLabelMap.h"
#include "itkLabelImageToLabelMapFilter.h"
#include "itkShapeLabelMapFilter.h"
// Software Guide : EndCodeSnippet
#include "otbImageFileReader.h"
int main(int argc, char * argv[])
{
const int dim = 2;
typedef unsigned long PixelType;
typedef itk::Image< PixelType, dim > ImageType;
if( argc != 3)
{
std::cerr << "usage: " << argv[0] << " input foreground" << std::endl;
// std::cerr << " : " << std::endl;
exit(1);
}
// read the input image
typedef itk::ImageFileReader< ImageType > ReaderType;
ReaderType::Pointer reader = ReaderType::New();
reader->SetFileName( argv[1] );
// define the object type. Here the ShapeLabelObject type
// is chosen in order to read some attribute related to the shape
// of the objects (by opposition to the content of the object, with
// the StatisticsLabelObejct).
typedef unsigned long LabelType;
typedef itk::ShapeLabelObject< LabelType, dim > LabelObjectType;
typedef itk::LabelMap< LabelObjectType > LabelMapType;
// convert the image in a collection of objects
typedef itk::LabelImageToLabelMapFilter< ImageType, LabelMapType > ConverterType;
ConverterType::Pointer converter = ConverterType::New();
converter->SetInput( reader->GetOutput() );
// converter->SetForegroundValue( atoi(argv[2]) );
typedef itk::ShapeLabelMapFilter< LabelMapType > ShapeFilterType;
ShapeFilterType::Pointer shape = ShapeFilterType::New();
shape->SetInput( converter->GetOutput() );
// update the shape filter, so its output will be up to date
shape->Update();
std::cout << "Nb. objects conv. " << converter->GetOutput()->GetNumberOfLabelObjects() << std::endl;
std::cout << "Nb. objects shape " << shape->GetOutput()->GetNumberOfLabelObjects() << std::endl;
// then we can read the attribute values we're interested in. The BinaryImageToShapeLabelMapFilter
// produce consecutive labels, so we can use a for loop and GetLabelObject() method to retrieve
// the label objects. If the labels are not consecutive, the GetNthLabelObject() method must be
// use instead of GetLabelObject(), or an iterator on the label object container of the label map.
LabelMapType::Pointer labelMap = shape->GetOutput();
for( unsigned long label=1; label<=labelMap->GetNumberOfLabelObjects(); label++ )
{
// we don't need a SmartPointer of the label object here, because the reference is kept in
// in the label map.
const LabelObjectType * labelObject = labelMap->GetLabelObject( label );
std::cout << label << "\t" << labelObject->GetPhysicalSize() << "\t" << labelObject->GetCentroid() << std::endl;
}
return 0;
}
......@@ -26,9 +26,13 @@
void RegisterTests()
{
REGISTER_TEST(OBIAImageToLabelToImageTest);
REGISTER_TEST(OBIAShapeAttributeComputationTest);
}
#undef main
#define main OBIAImageToLabelToImageTest
#include "ImageToLabelToImage.cxx"
#undef main
#define main OBIAShapeAttributeComputationTest
#include "ShapeAttributeComputation.cxx"
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