Skip to content
Snippets Groups Projects
Commit 105717d1 authored by Jordi Inglada's avatar Jordi Inglada
Browse files

Ajout exemple VectorImagee

parent 8586d6ce
No related branches found
No related tags found
No related merge requests found
......@@ -19,7 +19,7 @@ TARGET_LINK_LIBRARIES(Image4 OTBCommon ITKCommon)
#TARGET_LINK_LIBRARIES(Image5 ITKCommon ITKIO)
ADD_EXECUTABLE(RGBImage RGBImage.cxx )
TARGET_LINK_LIBRARIES(RGBImage ITKCommon ITKIO)
TARGET_LINK_LIBRARIES(RGBImage OTBCommon OTBIO ITKCommon ITKIO)
ADD_EXECUTABLE(VectorImage VectorImage.cxx )
TARGET_LINK_LIBRARIES(VectorImage ITKCommon)
......
......@@ -20,7 +20,7 @@
// Software Guide : BeginLatex
//
// This example illustrates how to manually construct an \doxygen{Image}
// This example illustrates how to manually construct an \doxygen{otb::Image}
// class. The following is the minimal code needed to instantiate, declare
// and create the image class.
//
......@@ -59,7 +59,7 @@ int main(int, char *[])
//
// The image can then be created by invoking the \code{New()} operator
// from the corresponding image type and assigning the result
// to a \doxygen{SmartPointer}.
// to a \doxygen{itk::SmartPointer}.
//
// \index{Image!Pointer}
// \index{Image!New()}
......@@ -88,8 +88,8 @@ int main(int, char *[])
// instantiated as previously shown, and that regions describing the image are
// then associated with it.
//
// A region is defined by two classes: the \doxygen{Index} and
// \doxygen{Size} classes. The origin of the region within the
// A region is defined by two classes: the \doxygen{itk::Index} and
// \doxygen{itk::Size} classes. The origin of the region within the
// image with which it is associated is defined by Index. The
// extent, or size, of the region is defined by Size. Index
// is represented by a n-dimensional array where each component is an
......
......@@ -74,7 +74,7 @@ int main( int , char * argv[])
// Software Guide : BeginLatex
//
// The reader type can now be used to create one reader object. A
// \doxygen{SmartPointer} (defined by the \code{::Pointer}
// \doxygen{itk::SmartPointer} (defined by the \code{::Pointer}
// notation) is used to receive the reference to the newly created
// reader. The \code{New()}
// method is invoked to create an instance of the image reader.
......@@ -95,7 +95,7 @@ int main( int , char * argv[])
// of the image to be loaded in memory. This is provided through
// the \code{SetFileName()} method. The file format here is inferred
// from the filename extension. The user may also explicitly specify the
// data format explicitly using the \doxygen{ImageIO} (See
// data format explicitly using the \doxygen{itk::ImageIO} (See
// Chapter~\ref{sec:ImagReadWrite} \pageref{sec:ImagReadWrite} for more
// information
//
......
......@@ -72,7 +72,7 @@ int main(int, char *[])
// unique index. An index is an array of integers that defines the position
// of the pixel along each coordinate dimension of the image. The IndexType
// is automatically defined by the image and can be accessed using the
// scope operator like \doxygen{Index}. The length of the array will match
// scope operator like \doxygen{itk::Index}. The length of the array will match
// the dimensions of the associated image.
//
// The following code illustrates the declaration of an index variable and
......
......@@ -200,7 +200,7 @@ int main(int, char *[])
// space can be mapped into an image index for the purpose of reading the
// content of the closest pixel.
//
// First, a \doxygen{Point} type must be declared. The point type is
// First, a \doxygen{itk::Point} type must be declared. The point type is
// templated over the type used to represent coordinates and over the
// dimension of the space. In this particular case, the dimension of the
// point must match the dimension of the image.
......
......@@ -19,19 +19,19 @@
#endif
#include "itkImage.h"
#include "itkImageFileReader.h"
#include "otbImageFileReader.h"
// Software Guide : BeginLatex
//
// Thanks to the flexibility offered by the
// \href{http://www.boost.org/more/generic_programming.html}{Generic
// Programming} style on which ITK is based, it is possible to
// Programming} style on which OTB is based, it is possible to
// instantiate images of arbitrary pixel type. The following example
// illustrates how a color image with RGB pixels can be defined.
//
// A class intended to support the RGB pixel type is available in ITK. You
// could also define your own pixel class and use it to instantiate a
// custom image type. In order to use the \doxygen{RGBPixel} class, it is
// custom image type. In order to use the \doxygen{itk::RGBPixel} class, it is
// necessary to include its header file.
//
// \index{itk::RGBPixel}
......@@ -69,22 +69,22 @@ int main( int , char * argv[] )
// Software Guide : EndLatex
// Software Guide : BeginCodeSnippet
typedef itk::Image< PixelType, 3 > ImageType;
typedef itk::Image< PixelType, 2 > ImageType;
// Software Guide : EndCodeSnippet
// Software Guide : BeginLatex
//
// The image type can be used to instantiate other filter, for example,
// an \doxygen{ImageFileReader} object that will read the image from a
// an \doxygen{otb::ImageFileReader} object that will read the image from a
// file.
//
// \index{itk::ImageFileReader!RGB Image}
// \index{otb::ImageFileReader!RGB Image}
//
// Software Guide : EndLatex
// Software Guide : BeginCodeSnippet
typedef itk::ImageFileReader< ImageType > ReaderType;
typedef otb::ImageFileReader< ImageType > ReaderType;
// Software Guide : EndCodeSnippet
......@@ -99,7 +99,6 @@ int main( int , char * argv[] )
pixelIndex[0] = 25;
pixelIndex[1] = 35;
pixelIndex[2] = 0;
// Software Guide : BeginLatex
......@@ -135,8 +134,8 @@ int main( int , char * argv[] )
// Software Guide : BeginLatex
//
// The subindex notation can also be used since the \doxygen{RGBPixel} inherits the
// \code{[]} operator from the \doxygen{FixedArray} class.
// The subindex notation can also be used since the \doxygen{itk::RGBPixel} inherits the
// \code{[]} operator from the \doxygen{itk::FixedArray} class.
//
// Software Guide : EndLatex
......
......@@ -21,11 +21,10 @@
// Software Guide : BeginLatex
//
// Many image processing tasks require images of non-scalar pixel type. A
// typical example is an image of vectors. This is the image type required to
// represent the gradient of a scalar image. The following code illustrates
// typical example is a multispectral image. The following code illustrates
// how to instantiate and use an image whose pixels are of vector type.
//
// For convenience we use the \doxygen{Vector} class to define the pixel
// We could use the \doxygen{itk::Vector} class to define the pixel
// type. The Vector class is intended to represent a geometrical vector in
// space. It is not intended to be used as an array container like the
// \href{http://www.sgi.com/tech/stl/Vector.html}{\code{std::vector}} in
......@@ -36,37 +35,39 @@
// \index{itk::Vector}
// \index{itk::Vector!header}
//
// However, the \doxygen{itk::Vector} is a fixed size array and it
// assumes that the number of channels of the image is known at
// compile time. Therefore, we prefer to use the
// \doxygen{otb::VectorImage} class which allows to choose the number
// of channels of the image at runtime. The pixels will be of type
// \doxygen{itk::VariableLengthVector}.
//
// The first step is to include the header file of the Vector class.
//
// Software Guide : EndLatex
// Software Guide : BeginCodeSnippet
#include "itkVector.h"
#include "itkVectorImage.h"
// Software Guide : EndCodeSnippet
#include "itkImage.h"
int main(int, char *[])
{
// Software Guide : BeginLatex
//
// The Vector class is templated over the type used to represent
// the coordinate in space and over the dimension of the space. In this example,
// we want the vector dimension to match the image dimension, but this is by
// no means a requirement. We could have defined a four-dimensional image
// with three-dimensional vectors as pixels.
// The VectorImage class is templated over the type used to represent
// the coordinate in space and over the dimension of the space. In
// this example,
// we want to represent Pléiades images which have 4 bands.
//
// \index{itk::Vector!Instantiation}
// \index{itk::Vector!itk::Image}
// \index{itk::Image!Vector pixel}
// \index{itk::VectorImage!Instantiation}
//
// Software Guide : EndLatex
// Software Guide : BeginCodeSnippet
typedef itk::Vector< float, 3 > PixelType;
typedef itk::Image< PixelType, 3 > ImageType;
typedef unsigned char PixelType;
typedef itk::VectorImage< PixelType, 2 > ImageType;
// Software Guide : EndCodeSnippet
// Then the image object can be created
......@@ -78,11 +79,9 @@ int main(int, char *[])
size[0] = 200; // size along X
size[1] = 200; // size along Y
size[2] = 200; // size along Z
start[0] = 0; // first index on X
start[1] = 0; // first index on Y
start[2] = 0; // first index on Z
ImageType::RegionType region;
region.SetSize( size );
......@@ -90,40 +89,44 @@ int main(int, char *[])
// Pixel data is allocated
image->SetRegions( region );
image->Allocate();
// The image buffer is initialized to a particular value
ImageType::PixelType initialValue;
// Software Guide : BeginLatex
// Since the pixel dimensionality is choosen at runtime, one has to
// pass this parameter to the image before memory allocation.
// Software Guide : EndLatex
// Software Guide : BeginCodeSnippet
image->SetNumberOfComponentsPerPixel(4);
image->Allocate();
// A vector can initialize all its components to the
// same value by using the Fill() method.
initialValue.Fill( 0.0 );
// Software Guide : EndCodeSnippet
// Now the image buffer can be initialized with this
// vector value.
image->FillBuffer( initialValue );
ImageType::IndexType pixelIndex;
pixelIndex[0] = 27; // x position
pixelIndex[1] = 29; // y position
pixelIndex[2] = 37; // z position
// Software Guide : BeginLatex
//
// The Vector class inherits the operator \code{[]} from the
// \doxygen{FixedArray} class. This makes it possible to access the
// Vector's components using index notation.
// The VariableLengthVector class overloads the operator
// \code{[]}. This makes it possible to access the
// Vector's components using index notation. The user must not
// forget to allocate the memory for each individual pixel by using
// the \code{Reserve} method.
//
// Software Guide : EndLatex
// Software Guide : BeginCodeSnippet
ImageType::PixelType pixelValue;
pixelValue.Reserve( 4 );
pixelValue[0] = 1.345; // x component
pixelValue[1] = 6.841; // y component
pixelValue[2] = 3.295; // x component
pixelValue[0] = 1; // Blue component
pixelValue[1] = 6; // Red component
pixelValue[2] = 100; // Green component
pixelValue[3] = 100; // NIR component
// Software Guide : EndCodeSnippet
......@@ -138,16 +141,25 @@ int main(int, char *[])
image->SetPixel( pixelIndex, pixelValue );
// Software Guide : EndCodeSnippet
// Software Guide : BeginLatex
// The GetPixel method can also be used to read Vectors
// pixels from the image
ImageType::PixelType value = image->GetPixel( pixelIndex );
// Software Guide : EndLatex
// Software Guide : BeginCodeSnippet
ImageType::PixelType value = image->GetPixel( pixelIndex );
// Software Guide : EndCodeSnippet
// Software Guide : BeginLatex
//
// Lets repeat that both \code{SetPixel()} and \code{GetPixel()} are
// inefficient and should only be used for debugging purposes or for
// implementing interactions with a graphical user interface such as
// querying pixel value by clicking with the mouse.
//
// Software Guide : EndLatex
return 0;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment