diff --git a/Code/BasicFilters/otbMeanShiftImageFilter.h b/Code/BasicFilters/otbMeanShiftImageFilter.h index 4ded01df843ac29f292b1d58c03f860c6f00bca2..9b2797ffb4432752c2eeb9682137c219d967c184 100644 --- a/Code/BasicFilters/otbMeanShiftImageFilter.h +++ b/Code/BasicFilters/otbMeanShiftImageFilter.h @@ -67,7 +67,7 @@ namespace otb * Mean shift can be used for edge-preserving smoothing, or for clustering. The GetOutput() method will allow * you to get the smoothed image, whereas the * GetClusteredOuptut() methods returns the clustered output. The GetLabeledClusteredOutput() returns - * a labeled clustered images, and the GetClusterBoundariesOutput() + * a labeled clustered image, and the GetClusterBoundariesOutput() * an image of the cluster boundaries. * * The MinimumRegionSize parameter allows you to prune small clustered regions. diff --git a/Code/BasicFilters/otbMeanShiftVectorImageFilter.h b/Code/BasicFilters/otbMeanShiftVectorImageFilter.h index b0f77638197dd680fa8b697a55d0c8901d75b977..d0e542e12d22b2b7703a979e7fcef4996b3e375d 100644 --- a/Code/BasicFilters/otbMeanShiftVectorImageFilter.h +++ b/Code/BasicFilters/otbMeanShiftVectorImageFilter.h @@ -59,7 +59,7 @@ namespace otb * * This is the implementation of the mean shift clustering and edge-preserving smoothing filter adapted to * otb::VectorImage or itk::VectorImage. For the full documentation, please refer to the - * base class otb::MeanShiftImageFilterBase. + * base class otb::MeanShiftImageFilter. * * \sa MeanShiftImageFilter * \ingroup ImageEnhancement diff --git a/Code/IO/otbGDALImageIO.cxx b/Code/IO/otbGDALImageIO.cxx index fec8bbed91788acbd4114b196d32fcfdefdfb534..afa980d28a5d79227448324abea122877f8e4e4b 100644 --- a/Code/IO/otbGDALImageIO.cxx +++ b/Code/IO/otbGDALImageIO.cxx @@ -148,7 +148,6 @@ namespace otb "GDALOpen failed - %d\n%s\n", CPLGetLastErrorNo(), CPLGetLastErrorMsg() ); - GDALDumpOpenDatasets( stderr ); GDALDestroyDriverManager(); CPLDumpSharedList( NULL ); itkDebugMacro(<<"No dataset "); diff --git a/Examples/BasicFilters/CMakeLists.txt b/Examples/BasicFilters/CMakeLists.txt index b111577f0c3d80d360919d09d4f737824ecf423c..ff9ea4483997cb0a31baaa4f0cb0ae4852b30d16 100644 --- a/Examples/BasicFilters/CMakeLists.txt +++ b/Examples/BasicFilters/CMakeLists.txt @@ -16,6 +16,10 @@ TARGET_LINK_LIBRARIES(PrintableImageFilterExample OTBCommon OTBIO) ADD_EXECUTABLE(IndexedToRGBExample IndexedToRGBExample.cxx ) TARGET_LINK_LIBRARIES(IndexedToRGBExample OTBCommon OTBIO) +ADD_EXECUTABLE(MeanShiftVectorImageFilterExample MeanShiftVectorImageFilterExample.cxx ) +TARGET_LINK_LIBRARIES(MeanShiftVectorImageFilterExample OTBCommon OTBIO OTBBasicFilters) + + IF( NOT OTB_DISABLE_CXX_TESTING AND BUILD_TESTING ) SET(BASELINE ${OTB_DATA_ROOT}/Baseline/Examples/BasicFilters) diff --git a/Examples/BasicFilters/IndexedToRGBExample.cxx b/Examples/BasicFilters/IndexedToRGBExample.cxx index ab619b81901122a6bfcf63d1d5fe980ca3f8ad5b..4c99cbb7e10e8f2399e1414d1ad192918122d26b 100644 --- a/Examples/BasicFilters/IndexedToRGBExample.cxx +++ b/Examples/BasicFilters/IndexedToRGBExample.cxx @@ -30,7 +30,7 @@ // Software Guide : BeginLatex // -// Some algorithm produces as an output an indexed image. In such images, +// Some algorithms produce as an output an indexed image. In such images, // each pixel is given a value according to the region number it belongs to. // This value starting at 0 or 1 is usually an integer value. // Often, such images are produced by segmentation or classification algorithm. diff --git a/Examples/BasicFilters/MeanShiftVectorImageFilterExample.cxx b/Examples/BasicFilters/MeanShiftVectorImageFilterExample.cxx new file mode 100644 index 0000000000000000000000000000000000000000..d30b66bf24be831d16affc7b09c885a40672105a --- /dev/null +++ b/Examples/BasicFilters/MeanShiftVectorImageFilterExample.cxx @@ -0,0 +1,221 @@ +/*========================================================================= + + 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. + +=========================================================================*/ + +#if defined(_MSC_VER) +#pragma warning ( disable : 4786 ) +#endif + +#ifdef __BORLANDC__ +#define ITK_LEAN_AND_MEAN +#endif + +// Software Guide : BeginCommandLineArgs +// INPUTS: {ROI_QB_MUL_1.png} +// OUTPUTS: {MSFilteredOutput.png}, {MSClusteredOutput.png}, {MSLabelledOutput.png}, {MSBoundariesOutput.png} +// 5 50 20 +// Software Guide : EndCommandLineArgs + +// Software Guide : BeginLatex +// +// This example demonstrates the use of the +// \doxygen{otb}{MeanShiftVectorImageFilter} class which implements +// filtering and clustering using the mean shift algorithm +// \cite{Comaniciu2002}. // For a given pixel, the mean shift will +// build a set of neighboring pixels within a given spatial radius +// and a color range. The spatial and color center of this set is +// then computed and the algorithm iterates with this new spatial and +// color center. The Mean shift can be used for edge-preserving +// smoothing, or for clustering. +// +// Software Guide : EndLatex + +#include "itkExceptionObject.h" +#include "otbVectorImage.h" +#include "otbImageFileReader.h" +#include "otbStreamingImageFileWriter.h" +#include "otbPrintableImageFilter.h" + +// Software Guide : BeginLatex +// +// Two implementations for the filter exist, one for scalar images +// (\doxygen{otb}{MeanShiftImageFilter}). And another one (the one +// presented in this example) for vector images. They have the same +// interface, so they can be used in the same way. We start by +// including the needed header file. +// +// Software Guide : EndLatex + +// Software Guide : BeginCodeSnippet +#include "otbMeanShiftVectorImageFilter.h" +// Software Guide : EndCodeSnippet +int main(int argc, char * argv[]) +{ + if(argc != 12) + { + std::cerr<<"Usage: "<<argv[0]<<" infname filteredfname clusteredfname labeledclusteredfname clusterboundariesfname filteredPretty clusteredPretty spatialRadius rangeRadius minregionsize scale"<<std::endl; + return EXIT_FAILURE; + } + + const char * infname = argv[1]; + const char * filteredfname = argv[2]; + const char * clusteredfname = argv[3]; + const char * labeledclusteredfname = argv[4]; + const char * clusterboundariesfname = argv[5]; + const char * filteredPretty = argv[6]; + const char * clusteredPretty = argv[7]; + const unsigned int spatialRadius = atoi(argv[8]); + const double rangeRadius = atof(argv[9]); + const unsigned int minRegionSize = atoi(argv[10]); + const double scale = atoi(argv[11]); + + // Software Guide : BeginLatex +// +// We start by the classical \code{typedef}s needed for reading and +// writing the images. The EDISON code upon which OTB's +// implementation is based, uses float pixel precision, so we choose +// to work with a float pixel type. +// +// Software Guide : EndLatex + +// Software Guide : BeginCodeSnippet + const unsigned int Dimension = 2; + typedef float PixelType; + typedef otb::VectorImage<PixelType,Dimension> ImageType; + typedef otb::ImageFileReader<ImageType> ReaderType; + typedef otb::StreamingImageFileWriter<ImageType> WriterType; +// Software Guide : EndCodeSnippet + + // Software Guide : BeginLatex +// +// We can now define the type for the filter, and also the type for +// the labeled output image, which is needed for the corresponding writer: +// +// Software Guide : EndLatex + +// Software Guide : BeginCodeSnippet + typedef otb::MeanShiftVectorImageFilter<ImageType,ImageType> FilterType; + typedef FilterType::LabeledOutputType LabeledImageType; + typedef otb::StreamingImageFileWriter<LabeledImageType> LabeledWriterType; + + // Software Guide : EndCodeSnippet + + // Software Guide : BeginLatex +// +// We instantiate the filter, the reader, and 4 writers (2 for the +// filetered and clustered images and 2 more for the labeled and +// boundaries images): +// +// Software Guide : EndLatex + +// Software Guide : BeginCodeSnippet + FilterType::Pointer filter = FilterType::New(); + ReaderType::Pointer reader = ReaderType::New(); + WriterType::Pointer writer1 = WriterType::New(); + WriterType::Pointer writer2 = WriterType::New(); + LabeledWriterType::Pointer writer3 = LabeledWriterType::New(); + LabeledWriterType::Pointer writer4 = LabeledWriterType::New(); + + // Software Guide : EndCodeSnippet + + // Software Guide : BeginLatex +// +// We set the file names for the reader and the writers: +// +// Software Guide : EndLatex + +// Software Guide : BeginCodeSnippet + reader->SetFileName(infname); + writer1->SetFileName(filteredfname); + writer2->SetFileName(clusteredfname); + writer3->SetFileName(labeledclusteredfname); + writer4->SetFileName(clusterboundariesfname); + + // Software Guide : EndCodeSnippet + + // Software Guide : BeginLatex +// +// We can now set the parameters for the filter. There are 3 main +// parameters: the spatial radius used for defining the neighborhood, +// the range radius used for defining the interval in the color space +// and the minimum size for the regions to be kept after clustering. +// +// Software Guide : EndLatex + +// Software Guide : BeginCodeSnippet + filter->SetSpatialRadius(spatialRadius); + filter->SetRangeRadius(rangeRadius); + filter->SetMinimumRegionSize(minRegionSize); + // Software Guide : EndCodeSnippet + // Software Guide : BeginLatex +// +// OTB's implementation adds another parameter -- the scale -- which +// allows to stretch the image before processing. This is useful when +// pixel values are in the \[0-1\] range. +// +// Software Guide : EndLatex + +// Software Guide : BeginCodeSnippet + filter->SetScale(scale); + // Software Guide : EndCodeSnippet + // Software Guide : BeginLatex +// +// We can now plug the pipeline and run it. +// +// Software Guide : EndLatex + +// Software Guide : BeginCodeSnippet + + filter->SetInput(reader->GetOutput()); + writer1->SetInput(filter->GetOutput()); + writer2->SetInput(filter->GetClusteredOutput()); + writer3->SetInput(filter->GetLabeledClusteredOutput()); + writer4->SetInput(filter->GetClusterBoundariesOutput()); + + + writer1->Update(); + writer2->Update(); + writer3->Update(); + writer4->Update(); + // Software Guide : EndCodeSnippet + + typedef otb::PrintableImageFilter< ImageType > PrintableFilterType; + PrintableFilterType::Pointer printableImageFilter = PrintableFilterType::New(); + + printableImageFilter->SetChannel(1); + printableImageFilter->SetChannel(2); + printableImageFilter->SetChannel(3); + + typedef PrintableFilterType::OutputImageType OutputImageType; + typedef otb::StreamingImageFileWriter< OutputImageType > + PrettyWriterType; + PrettyWriterType::Pointer prettyWriter = PrettyWriterType::New(); + + printableImageFilter->SetInput( filter->GetOutput() ); + prettyWriter->SetFileName( filteredPretty ); + prettyWriter->SetInput( printableImageFilter->GetOutput() ); + prettyWriter->Update(); + + printableImageFilter->SetInput( filter->GetClusteredOutput() ); + prettyWriter->SetFileName( clusteredPretty ); + prettyWriter->SetInput( printableImageFilter->GetOutput() ); + prettyWriter->Update(); + + + return EXIT_SUCCESS; +} +