Commit 6590fb86 authored by Jordi Inglada's avatar Jordi Inglada

Exemples iterators

parent 09b1fd6a
......@@ -13,4 +13,5 @@ SUBDIRS(
Learning
Classification
Segmentation
Iterators
)
#
# Examples on the use of Iterators.
#
PROJECT(IteratorExamples)
INCLUDE_REGULAR_EXPRESSION("^.*$")
ADD_EXECUTABLE(ImageRandomConstIteratorWithIndex ImageRandomConstIteratorWithIndex.cxx)
TARGET_LINK_LIBRARIES(ImageRandomConstIteratorWithIndex OTBIO OTBCommon ITKIO )
ADD_EXECUTABLE(NeighborhoodIterators4 NeighborhoodIterators4.cxx)
TARGET_LINK_LIBRARIES(NeighborhoodIterators4 OTBIO OTBCommon ITKIO )
ADD_EXECUTABLE(NeighborhoodIterators5 NeighborhoodIterators5.cxx)
TARGET_LINK_LIBRARIES(NeighborhoodIterators5 OTBIO OTBCommon ITKIO )
IF(NOT BORLAND)
ADD_EXECUTABLE(NeighborhoodIterators1 NeighborhoodIterators1.cxx)
TARGET_LINK_LIBRARIES(NeighborhoodIterators1 OTBIO OTBCommon ITKIO )
ADD_EXECUTABLE(NeighborhoodIterators2 NeighborhoodIterators2.cxx)
TARGET_LINK_LIBRARIES(NeighborhoodIterators2 OTBIO OTBCommon ITKIO )
ADD_EXECUTABLE(NeighborhoodIterators3 NeighborhoodIterators3.cxx)
TARGET_LINK_LIBRARIES(NeighborhoodIterators3 OTBIO OTBCommon ITKIO )
ADD_EXECUTABLE(NeighborhoodIterators6 NeighborhoodIterators6.cxx)
TARGET_LINK_LIBRARIES(NeighborhoodIterators6 ITKAlgorithms ITKBasicFilters OTBIO OTBCommon ITKIO )
ADD_EXECUTABLE(ImageRegionIteratorWithIndex ImageRegionIteratorWithIndex.cxx)
TARGET_LINK_LIBRARIES(ImageRegionIteratorWithIndex OTBIO OTBCommon ITKIO )
ADD_EXECUTABLE(ImageRegionIterator ImageRegionIterator.cxx)
TARGET_LINK_LIBRARIES(ImageRegionIterator OTBIO OTBCommon ITKIO )
ADD_EXECUTABLE(ImageLinearIteratorWithIndex2 ImageLinearIteratorWithIndex2.cxx)
TARGET_LINK_LIBRARIES(ImageLinearIteratorWithIndex2 OTBIO OTBCommon ITKIO )
ADD_EXECUTABLE(ImageLinearIteratorWithIndex ImageLinearIteratorWithIndex.cxx)
TARGET_LINK_LIBRARIES(ImageLinearIteratorWithIndex OTBIO OTBCommon ITKIO )
ADD_EXECUTABLE(ImageSliceIteratorWithIndex ImageSliceIteratorWithIndex.cxx)
TARGET_LINK_LIBRARIES(ImageSliceIteratorWithIndex OTBIO OTBCommon ITKIO )
ADD_EXECUTABLE(ShapedNeighborhoodIterators1 ShapedNeighborhoodIterators1.cxx)
TARGET_LINK_LIBRARIES(ShapedNeighborhoodIterators1 ITKAlgorithms ITKBasicFilters OTBIO OTBCommon ITKIO )
ADD_EXECUTABLE(ShapedNeighborhoodIterators2 ShapedNeighborhoodIterators2.cxx)
TARGET_LINK_LIBRARIES(ShapedNeighborhoodIterators2 ITKAlgorithms ITKBasicFilters OTBIO OTBCommon ITKIO )
ADD_EXECUTABLE(IteratorsExamples IteratorsExamples.cxx )
TARGET_LINK_LIBRARIES(IteratorsExamples OTBIO OTBCommon ITKIO ITKBasicFilters )
ENDIF(NOT BORLAND)
/*=========================================================================
Program: Insight Segmentation & Registration Toolkit
Module: $RCSfile: ImageLinearIteratorWithIndex.cxx,v $
Language: C++
Date: $Date: 2005/02/08 03:59:00 $
Version: $Revision: 1.21 $
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.
=========================================================================*/
#if defined(_MSC_VER)
#pragma warning ( disable : 4786 )
#endif
// Software Guide : BeginLatex
//
// The \doxygen{itk}{ImageLinearIteratorWithIndex} is designed for line-by-line
// processing of an image. It walks a linear path along a selected image
// direction parallel to one of the coordinate axes of the image. This
// iterator conceptually breaks an image into a set of parallel lines
// that span the selected image dimension.
//
// \index{Iterators!and image lines}
//
// Like all image iterators, movement of the
// ImageLinearIteratorWithIndex is constrained within an
// image region $R$. The line $\ell$ through which the iterator moves is
// defined by selecting a direction and an origin. The line $\ell$
// extends from the origin to the upper boundary of $R$. The origin can be
// moved to any position along the lower boundary of $R$.
//
// Several additional methods are defined for this iterator to control movement
// of the iterator along the line $\ell$ and movement of the origin of $\ell$.
//
// %Might need a figure here to describe this iterator.
//
// \begin{itemize}
//
// \index{itk::ImageLinearIteratorWithIndex!NextLine()}
//
// \item \textbf{\code{NextLine()}} Moves the iterator to the beginning pixel
// location of the next line in the image. The origin of the next line is
// determined by incrementing the current origin along the fastest increasing
// dimension of the subspace of the image that excludes the selected dimension.
//
//
// \index{itk::ImageLinearIteratorWithIndex!PreviousLine()}
//
// \item \textbf{\code{PreviousLine()}} Moves the iterator to the \emph{last valid
// pixel location} in the previous line. The origin of the previous line is
// determined by decrementing the current origin along the fastest increasing
// dimension of the subspace of the image that excludes the selected dimension.
//
// \index{itk::ImageLinearIteratorWithIndex!GoToBeginOfLine()}
// \index{itk::ImageLinearIteratorWithIndex!GoToReverseBeginOfLine()}
//
// \item \textbf{\code{GoToBeginOfLine()}} Moves the iterator to the beginning
// pixel of the current line.
//
// \item \textbf{\code{GoToEndOfLine()}} Move the iterator to
// \emph{one past} the last valid pixel of the current line.
//
//
// \index{itk::ImageLinearIteratorWithIndex!IsAtReverseEndOfLine()}
// \index{itk::ImageLinearIteratorWithIndex!IsAtEndOfLine()}
//
// \item \textbf{\code{IsAtReverseEndOfLine()}}
// Returns true if the iterator points
// to \emph{one position before} the beginning pixel of the current line.
//
// \item \textbf{\code{IsAtEndOfLine()}}
// Returns true if the iterator points to
// \emph{one position past} the last valid pixel of the current line.
// \end{itemize}
//
// The following code example shows how to use the
// ImageLinearIteratorWithIndex. It implements the same algorithm as
// in the previous example, flipping an image across its $x$-axis. Two line
// iterators are iterated in opposite directions across the $x$-axis.
// After each line is traversed, the iterator origins are stepped along
// the $y$-axis to the
// next line.
//
// \index{itk::ImageLinearIteratorWithIndex!example of using|(}
//
// Headers for both the const and non-const versions are needed.
//
// Software Guide : EndLatex
#include "otbImage.h"
#include "itkRGBPixel.h"
// Software Guide : BeginCodeSnippet
#include "itkImageLinearConstIteratorWithIndex.h"
#include "itkImageLinearIteratorWithIndex.h"
// Software Guide : EndCodeSnippet
#include "otbImageFileReader.h"
#include "otbImageFileWriter.h"
int main( int argc, char *argv[] )
{
// Verify the number of parameters on the command line.
if ( argc < 3 )
{
std::cerr << "Missing parameters. " << std::endl;
std::cerr << "Usage: " << std::endl;
std::cerr << argv[0]
<< " inputImageFile outputImageFile"
<< std::endl;
return -1;
}
// Software Guide : BeginLatex
//
// The RGB image and pixel types are defined as in the previous example. The
// ImageLinearIteratorWithIndex class and its const version each have
// single template parameters, the image type.
//
// Software Guide : EndLatex
const unsigned int Dimension = 2;
typedef itk::RGBPixel< unsigned char > RGBPixelType;
typedef otb::Image< RGBPixelType, Dimension > ImageType;
// Software Guide : BeginCodeSnippet
typedef itk::ImageLinearIteratorWithIndex< ImageType > IteratorType;
typedef itk::ImageLinearConstIteratorWithIndex< ImageType > ConstIteratorType;
// Software Guide : EndCodeSnippet
typedef otb::ImageFileReader< ImageType > ReaderType;
typedef otb::ImageFileWriter< ImageType > WriterType;
ImageType::ConstPointer inputImage;
ReaderType::Pointer reader = ReaderType::New();
reader->SetFileName( argv[1] );
try
{
reader->Update();
inputImage = reader->GetOutput();
}
catch ( itk::ExceptionObject &err)
{
std::cout << "ExceptionObject caught a !" << std::endl;
std::cout << err << std::endl;
return -1;
}
// Software Guide : BeginLatex
//
// After reading the input image, we allocate an output image that of the same
// size, spacing, and origin.
//
// Software Guide : EndLatex
// Software Guide : BeginCodeSnippet
ImageType::Pointer outputImage = ImageType::New();
outputImage->SetRegions( inputImage->GetRequestedRegion() );
outputImage->CopyInformation( inputImage );
outputImage->Allocate();
// Software Guide : EndCodeSnippet
// Software Guide : BeginLatex
//
// Next we create the two iterators. The const iterator walks the input image,
// and the non-const iterator walks the output image. The iterators are
// initialized over the same region. The direction of iteration is set to 0,
// the $x$ dimension.
//
// Software Guide : EndLatex
// Software Guide : BeginCodeSnippet
ConstIteratorType inputIt( inputImage, inputImage->GetRequestedRegion() );
IteratorType outputIt( outputImage, inputImage->GetRequestedRegion() );
inputIt.SetDirection(0);
outputIt.SetDirection(0);
// Software Guide : EndCodeSnippet
// Software Guide: BeginLatex
//
// Each line in the input is copied to the output. The input iterator moves
// forward across columns while the output iterator moves backwards.
//
// Software Guide : EndLatex
// Software Guide : BeginCodeSnippet
for ( inputIt.GoToBegin(), outputIt.GoToBegin(); ! inputIt.IsAtEnd();
outputIt.NextLine(), inputIt.NextLine())
{
inputIt.GoToBeginOfLine();
outputIt.GoToEndOfLine();
--outputIt;
while ( ! inputIt.IsAtEndOfLine() )
{
outputIt.Set( inputIt.Get() );
++inputIt;
--outputIt;
}
}
// Software Guide : EndCodeSnippet
WriterType::Pointer writer = WriterType::New();
writer->SetFileName( argv[2] );
writer->SetInput(outputImage);
try
{
writer->Update();
}
catch ( itk::ExceptionObject &err)
{
std::cout << "ExceptionObject caught !" << std::endl;
std::cout << err << std::endl;
return -1;
}
// Software Guide : BeginLatex
//
// Running this example on \code{ROI\_QB\_MUL\_1.tif} produces
// the same output image shown in
// Figure~\ref{fig:ImageRegionIteratorWithIndexExample}.
//
// \index{itk::ImageLinearIteratorWithIndex!example of using|)}
// Software Guide : EndLatex
return 0;
}
/*=========================================================================
Program: Insight Segmentation & Registration Toolkit
Module: $RCSfile: ImageLinearIteratorWithIndex2.cxx,v $
Language: C++
Date: $Date: 2005/11/20 13:27:53 $
Version: $Revision: 1.10 $
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.
=========================================================================*/
#if defined(_MSC_VER)
#pragma warning ( disable : 4786 )
#endif
// Software Guide : BeginLatex
//
// This example shows how to use the \doxygen{itk}{ImageLinearIteratorWithIndex} for
// computing the mean across time of a 4D image where the first three
// dimensions correspond to spatial coordinates and the fourth dimension
// corresponds to time. The result of the mean across time is to be stored in a
// 3D image.
//
// \index{Iterators!and 4D images}
// \index{ImageLinearIteratorWithIndex!4D images}
//
// Software Guide : EndLatex
#include "itkImage.h"
// Software Guide : BeginCodeSnippet
#include "itkImageLinearConstIteratorWithIndex.h"
// Software Guide : EndCodeSnippet
#include "itkImageFileReader.h"
#include "itkImageFileWriter.h"
int main( int argc, char *argv[] )
{
// Verify the number of parameters on the command line.
if ( argc < 3 )
{
std::cerr << "Missing parameters. " << std::endl;
std::cerr << "Usage: " << std::endl;
std::cerr << argv[0]
<< " input4DImageFile output3DImageFile"
<< std::endl;
return EXIT_FAILURE;
}
// Software Guide : BeginLatex
//
// First we declare the types of the images
//
// Software Guide : EndLatex
// Software Guide : BeginCodeSnippet
typedef unsigned char PixelType;
typedef itk::Image< PixelType, 3 > Image3DType;
typedef itk::Image< PixelType, 4 > Image4DType;
typedef itk::ImageFileReader< Image4DType > Reader4DType;
typedef itk::ImageFileWriter< Image3DType > Writer3DType;
Reader4DType::Pointer reader4D = Reader4DType::New();
reader4D->SetFileName( argv[1] );
try
{
reader4D->Update();
}
catch( itk::ExceptionObject & excp )
{
std::cerr << "Error writing the image" << std::endl;
std::cerr << excp << std::endl;
return EXIT_FAILURE;
}
Image4DType::ConstPointer image4D = reader4D->GetOutput();
Image3DType::Pointer image3D = Image3DType::New();
typedef Image3DType::IndexType Index3DType;
typedef Image3DType::SizeType Size3DType;
typedef Image3DType::RegionType Region3DType;
typedef Image3DType::SpacingType Spacing3DType;
typedef Image3DType::PointType Origin3DType;
typedef Image4DType::IndexType Index4DType;
typedef Image4DType::SizeType Size4DType;
typedef Image4DType::RegionType Region4DType;
typedef Image4DType::SpacingType Spacing4DType;
typedef Image4DType::PointType Origin4DType;
Index3DType index3D;
Size3DType size3D;
Spacing3DType spacing3D;
Origin3DType origin3D;
Image4DType::RegionType region4D = image4D->GetBufferedRegion();
Index4DType index4D = region4D.GetIndex();
Size4DType size4D = region4D.GetSize();
Spacing4DType spacing4D = image4D->GetSpacing();
Origin4DType origin4D = image4D->GetOrigin();
for( unsigned int i=0; i < 3; i++)
{
size3D[i] = size4D[i];
index3D[i] = index4D[i];
spacing3D[i] = spacing4D[i];
origin3D[i] = origin4D[i];
}
image3D->SetSpacing( spacing3D );
image3D->SetOrigin( origin3D );
Region3DType region3D;
region3D.SetIndex( index3D );
region3D.SetSize( size3D );
image3D->SetRegions( region3D );
image3D->Allocate();
typedef itk::NumericTraits< PixelType >::AccumulateType SumType;
typedef itk::NumericTraits< SumType >::RealType MeanType;
const unsigned int timeLength = region4D.GetSize()[3];
typedef itk::ImageLinearConstIteratorWithIndex<
Image4DType > IteratorType;
IteratorType it( image4D, region4D );
it.SetDirection( 3 ); // Walk along time dimension
it.GoToBegin();
while( !it.IsAtEnd() )
{
SumType sum = itk::NumericTraits< SumType >::Zero;
it.GoToBeginOfLine();
index4D = it.GetIndex();
while( !it.IsAtEndOfLine() )
{
sum += it.Get();
++it;
}
MeanType mean = static_cast< MeanType >( sum ) /
static_cast< MeanType >( timeLength );
index3D[0] = index4D[0];
index3D[1] = index4D[1];
index3D[2] = index4D[2];
image3D->SetPixel( index3D, static_cast< PixelType >( mean ) );
it.NextLine();
}
// Software Guide : EndCodeSnippet
// Software Guide : BeginLatex
//
// As you can see, we avoid to use a 3D iterator to walk
// over the mean image. The reason is that there is no
// guarantee that the 3D iterator will walk in the same
// order as the 4D. Iterators just adhere to their contract
// of visiting all the pixel, but do not enforce any particular
// order for the visits. The linear iterator guarantees to
// visit the pixels along a line of the image in the order
// in which they are placed in the line, but do not states
// in what order one line will be visited with respect to
// other lines. Here we simply take advantage of knowing
// the first three components of the 4D iterator index,
// and use them to place the resulting mean value in the
// output 3D image.
//
// Software Guide : EndLatex
Writer3DType::Pointer writer3D = Writer3DType::New();
writer3D->SetFileName( argv[2] );
writer3D->SetInput( image3D );
try
{
writer3D->Update();
}
catch( itk::ExceptionObject & excp )
{
std::cerr << "Error writing the image" << std::endl;
std::cerr << excp << std::endl;
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}
/*=========================================================================
Program: Insight Segmentation & Registration Toolkit
Module: $RCSfile: ImageRandomConstIteratorWithIndex.cxx,v $
Language: C++
Date: $Date: 2005/02/08 03:59:00 $
Version: $Revision: 1.23 $
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.
=========================================================================*/
#if defined(_MSC_VER)
#pragma warning ( disable : 4786 )
#endif
// Software Guide : BeginLatex
//
// \doxygen{itk}{ImageRandomConstIteratorWithIndex} was developed to randomly
// sample pixel values. When incremented or decremented, it jumps to a random
// location in its image region.
//
// \index{itk::Image\-Random\-Const\-Iterator\-With\-Index!sample size}
// \index{itk::Image\-Random\-Const\-Iterator\-With\-Index!begin and end positions}
//
// The user must specify a sample size when creating this iterator. The sample
// size, rather than a specific image index, defines the end position for the
// iterator. \code{IsAtEnd()} returns
// \code{true} when the current sample number equals the sample size.
// \code{IsAtBegin()} returns \code{true} when the current sample number equals
// zero. An important difference from other image iterators is that
// ImageRandomConstIteratorWithIndex may visit the same pixel
// more than once.
//
// \index{itk::Image\-Random\-Const\-Iterator\-With\-Index!example of using|(}
// \index{itk::Image\-Random\-Const\-Iterator\-With\-Index!and statistics}
// Let's use the random iterator to estimate some simple image statistics. The next
// example calculates an estimate of the arithmetic mean of pixel values.
//
// First, include the appropriate header and declare pixel and image types.
//
// Software Guide : EndLatex
#include "otbImage.h"
// Software Guide : BeginCodeSnippet
#include "itkImageRandomConstIteratorWithIndex.h"
// Software Guide : EndCodeSnippet
#include "otbImageFileReader.h"
#include "otbImageFileWriter.h"
int main( int argc, char *argv[] )
{
// Verify the number of parameters on the command line.
if ( argc < 3 )
{
std::cerr << "Missing parameters. " << std::endl;
std::cerr << "Usage: " << std::endl;
std::cerr << argv[0]
<< " inputImageFile numberOfSamples"
<< std::endl;
return -1;
}
// Software Guide : BeginCodeSnippet
const unsigned int Dimension = 2;
typedef unsigned short PixelType;
typedef otb::Image< PixelType, Dimension > ImageType;
typedef itk::ImageRandomConstIteratorWithIndex< ImageType > ConstIteratorType;
// Software Guide : EndCodeSnippet
typedef otb::ImageFileReader< ImageType > ReaderType;
ImageType::ConstPointer inputImage;
ReaderType::Pointer reader = ReaderType::New();
reader->SetFileName( argv[1] );
try
{
reader->Update();
inputImage = reader->GetOutput();
}
catch ( itk::ExceptionObject &err)
{
std::cout << "ExceptionObject caught !" << std::endl;
std::cout << err << std::endl;
return -1;
}
// Software Guide : BeginLatex
//
// The input image has been read as \code{inputImage}. We now create an
// iterator with a number of samples set by command line argument. The call to
// \code{ReinitializeSeed} seeds the random number generator. The iterator is
// initialized over the entire valid image region.
//
// \index{itk::Image\-Random\-Const\-Iterator\-With\-Index!SetNumberOfSamples()}
// \index{itk::Image\-Random\-Const\-Iterator\-With\-Index!ReinitializeSeed()}
// Software Guide : EndLatex
// Software Guide : BeginCodeSnippet
ConstIteratorType inputIt( inputImage, inputImage->GetRequestedRegion() );
inputIt.SetNumberOfSamples( ::atoi( argv[2]) );
inputIt.ReinitializeSeed();
// Software Guide : EndCodeSnippet
// Software Guide: BeginLatex
//
// Now take the specified number of samples and calculate their average value.
//
// Software Guide : EndLatex
// Software Guide : BeginCodeSnippet
float mean = 0.0f;
for ( inputIt.GoToBegin(); ! inputIt.IsAtEnd(); ++inputIt)
{
mean += static_cast<float>( inputIt.Get() );
}
mean = mean / ::atof( argv[2] );
// Software Guide : EndCodeSnippet
std::cout << "Mean estimate with " << argv[2] << " samples is " << mean << std::endl;
// Software Guide : BeginLatex
//
// Table~\ref{fig:ImageRandomConstIteratorWithIndexExample} shows the results
// of running this example on several of the data files from
// \code{Examples/Data} with a range of sample sizes.
//
// \begin{table}
// \begin{center}
// \begin{tabular}[]{rc|c|c|c}
// & \multicolumn{4}{c}{\emph{Sample Size}} \\ & \code{\textbf{10}} & \code{\textbf{100}}
// & \code{\textbf{1000}}
// & \code{\textbf{10000}} \\ \cline{2-5}
// \code{RatLungSlice1.mha} & 50.5 & 52.4 & 53.0 & 52.4 \\ \code{RatLungSlice2.mha}
// & 46.7 & 47.5 & 47.4 & 47.6 \\ \code{BrainT1Slice.png}
// & 47.2 & 64.1 & 68.0 & 67.8 \\ \end{tabular}
// \protect\label{fig:ImageRandomConstIteratorWithIndexExample}
// \itkcaption[ImageRandomConstIteratorWithIndex usage]{Estimates of mean image pixel
// value using the ImageRandomConstIteratorWithIndex at different sample
// sizes.}
// \end{center}
// \end{table}
//
// \index{itk::Image\-Random\-Const\-Iterator\-With\-Index!example of using|)}
// Software Guide : EndLatex
return 0;
}
/*=========================================================================
Program: Insight Segmentation & Registration Toolkit
Module: $RCSfile: ImageRegionIterator.cxx,v $
Language: C++
Date: $Date: 2005/02/08 03:59:00 $
Version: $Revision: 1.24 $
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.
=========================================================================*/
#if defined(_MSC_VER)
#pragma warning ( disable : 4786 )
#endif
// Software Guide : BeginCommandLineArgs
// INPUTS: {QB_Suburb.png}
// OUTPUTS: {ImageRegionIteratorOutput.png}
// 10 10 110 140
// Software Guide : EndCommandLineArgs
// Software Guide : BeginLatex
//
// \index{Iterators!speed}
// The \doxygen{itk}{ImageRegionIterator} is optimized for
// iteration speed and is the first choice for iterative, pixel-wise operations
// when location in the image is not
// important. ImageRegionIterator is the least specialized of the ITK
// image iterator classes. It implements all of the methods described in the
// preceding section.
//
// The following example illustrates the use of
// \doxygen{itk}{ImageRegionConstIterator} and ImageRegionIterator.
// Most of the code constructs introduced apply to other ITK iterators as
// well. This simple application crops a subregion from an image by copying
// its pixel values into to a second, smaller image.
//
// \index{Iterators!and image regions}
// \index{itk::ImageRegionIterator!example of using|(}
// We begin by including the appropriate header files.
// Software Guide : EndLatex
#include "otbImage.h"
// Software Guide : BeginCodeSnippet
#include "itkImageRegionConstIterator.h"
#include "itkImageRegionIterator.h"
// Software Guide : EndCodeSnippet
#include "otbImageFileReader.h"
#include "otbImageFileWriter.h"
int main( int argc, char *argv[] )
{
// Verify the number of parameters on the command line.
if ( argc < 7 )
{
std::cerr << "Missing parameters. " << std::endl;
std::cerr << "Usage: " << std::endl;
std::cerr << argv[0]
<< " inputImageFile outputImageFile startX startY sizeX sizeY"
<< std::endl;
return -1;
}
// Software Guide : BeginLatex