<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <html><head><meta name="robots" content="noindex"> <meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1"> <title>ITK: DataRepresentation/Image/Image1.cxx</title> <link href="DoxygenStyle.css" rel="stylesheet" type="text/css"> </head><body bgcolor="#ffffff"> <!-- Section customized for INSIGHT : Tue Jul 17 01:02:45 2001 --> <center> <a href="index.html" class="qindex">Main Page</a> <a href="modules.html" class="qindex">Groups</a> <a href="namespaces.html" class="qindex">Namespace List</a> <a href="hierarchy.html" class="qindex">Class Hierarchy</a> <a href="classes.html" class="qindex">Alphabetical List</a> <a href="annotated.html" class="qindex">Compound List</a> <a href="files.html" class="qindex">File List</a> <a href="namespacemembers.html" class="qindex">Namespace Members</a> <a href="functions.html" class="qindex">Compound Members</a> <a href="globals.html" class="qindex">File Members</a> <a href="pages.html" class="qindex">Concepts</a></center> <!-- Generated by Doxygen 1.5.9 --> <div class="contents"> <h1>DataRepresentation/Image/Image1.cxx</h1><div class="fragment"><pre class="fragment"><span class="comment">/*=========================================================================</span> <span class="comment"></span> <span class="comment"> Program: Insight Segmentation & Registration Toolkit</span> <span class="comment"> Module: $RCSfile: Image1.cxx,v $</span> <span class="comment"> Language: C++</span> <span class="comment"> Date: $Date: 2005-02-08 03:51:52 $</span> <span class="comment"> Version: $Revision: 1.21 $</span> <span class="comment"></span> <span class="comment"> Copyright (c) Insight Software Consortium. All rights reserved.</span> <span class="comment"> See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.</span> <span class="comment"></span> <span class="comment"> This software is distributed WITHOUT ANY WARRANTY; without even </span> <span class="comment"> the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR </span> <span class="comment"> PURPOSE. See the above copyright notices for more information.</span> <span class="comment"></span> <span class="comment">=========================================================================*/</span> <span class="preprocessor">#if defined(_MSC_VER)</span> <span class="preprocessor"></span><span class="preprocessor">#pragma warning ( disable : 4786 )</span> <span class="preprocessor"></span><span class="preprocessor">#endif</span> <span class="preprocessor"></span> <span class="comment">// Software Guide : BeginLatex</span> <span class="comment">//</span> <span class="comment">// This example illustrates how to manually construct an \doxygen{Image}</span> <span class="comment">// class. The following is the minimal code needed to instantiate, declare</span> <span class="comment">// and create the image class.</span> <span class="comment">//</span> <span class="comment">// \index{itk::Image!Instantiation}</span> <span class="comment">// \index{itk::Image!Header}</span> <span class="comment">//</span> <span class="comment">// First, the header file of the Image class must be included.</span> <span class="comment">//</span> <span class="comment">// Software Guide : EndLatex </span> <span class="comment">// Software Guide : BeginCodeSnippet</span> <span class="preprocessor">#include "<a class="code" href="itkImage_8h.html">itkImage.h</a>"</span> <span class="comment">// Software Guide : EndCodeSnippet</span> <span class="keywordtype">int</span> <a name="a0"></a><a class="code" href="itkTestMain_8h.html#dacbe0175a79dff748855d8c9839f82b">main</a>(<span class="keywordtype">int</span>, <span class="keywordtype">char</span> *[]) { <span class="comment">// Software Guide : BeginLatex</span> <span class="comment">// </span> <span class="comment">// Then we must decide with what type to represent the pixels</span> <span class="comment">// and what the dimension of the image will be. With these two </span> <span class="comment">// parameters we can instantiate the image class. Here we create</span> <span class="comment">// a 3D image with \code{unsigned short} pixel data.</span> <span class="comment">//</span> <span class="comment">// Software Guide : EndLatex </span> <span class="comment">//</span> <span class="comment">// Software Guide : BeginCodeSnippet </span> <span class="keyword">typedef</span> <a name="_a1"></a><a class="code" href="classitk_1_1Image.html" title="Templated n-dimensional image class.">itk::Image< unsigned short, 3 ></a> ImageType; <span class="comment">// Software Guide : EndCodeSnippet </span> <span class="comment">// Software Guide : BeginLatex</span> <span class="comment">//</span> <span class="comment">// The image can then be created by invoking the \code{New()} operator</span> <span class="comment">// from the corresponding image type and assigning the result</span> <span class="comment">// to a \doxygen{SmartPointer}. </span> <span class="comment">//</span> <span class="comment">// \index{itk::Image!Pointer}</span> <span class="comment">// \index{itk::Image!New()}</span> <span class="comment">// </span> <span class="comment">// Software Guide : EndLatex </span> <span class="comment">//</span> <span class="comment">// Software Guide : BeginCodeSnippet </span> <a name="a2"></a><a class="code" href="itkFEMMacro_8h.html#539cce1a3282ba59952dedcbf9cdb23f">ImageType::Pointer</a> image = <a name="a3"></a><a class="code" href="namespaceHardConnectedComponentImageFilter.html#870262f145e0b45206db74df8053b59c">ImageType::New</a>(); <span class="comment">// Software Guide : EndCodeSnippet </span> <span class="comment">// Software Guide : BeginLatex</span> <span class="comment">//</span> <span class="comment">// In ITK, images exist in combination with one or more</span> <span class="comment">// \emph{regions}. A region is a subset of the image and indicates a</span> <span class="comment">// portion of the image that may be processed by other classes in</span> <span class="comment">// the system. One of the most common regions is the</span> <span class="comment">// \emph{LargestPossibleRegion}, which defines the image in its</span> <span class="comment">// entirety. Other important regions found in ITK are the</span> <span class="comment">// \emph{BufferedRegion}, which is the portion of the image actually</span> <span class="comment">// maintained in memory, and the \emph{RequestedRegion}, which is</span> <span class="comment">// the region requested by a filter or other class when operating on</span> <span class="comment">// the image.</span> <span class="comment">//</span> <span class="comment">// In ITK, manually creating an image requires that the image is</span> <span class="comment">// instantiated as previously shown, and that regions describing the image are</span> <span class="comment">// then associated with it.</span> <span class="comment">//</span> <span class="comment">// A region is defined by two classes: the \doxygen{Index} and</span> <span class="comment">// \doxygen{Size} classes. The origin of the region within the</span> <span class="comment">// image with which it is associated is defined by Index. The</span> <span class="comment">// extent, or size, of the region is defined by Size. Index</span> <span class="comment">// is represented by a n-dimensional array where each component is an</span> <span class="comment">// integer indicating---in topological image coordinates---the initial</span> <span class="comment">// pixel of the image. When an image is created manually, the user is</span> <span class="comment">// responsible for defining the image size and the index at which the image</span> <span class="comment">// grid starts. These two parameters make it possible to process selected</span> <span class="comment">// regions.</span> <span class="comment">// </span> <span class="comment">// The starting point of the image is defined by an Index class</span> <span class="comment">// that is an n-dimensional array where each component is an integer</span> <span class="comment">// indicating the grid coordinates of the initial pixel of the image.</span> <span class="comment">//</span> <span class="comment">// \index{itk::Image!Size}</span> <span class="comment">// \index{itk::Image!SizeType}</span> <span class="comment">//</span> <span class="comment">// Software Guide : EndLatex </span> <span class="comment">//</span> <span class="comment">// Software Guide : BeginCodeSnippet </span> <a name="a4"></a><a class="code" href="namespaceHardConnectedComponentImageFilter.html#be32dc19e71d40322ad9828b9ab40853">ImageType::IndexType</a> start; start[0] = 0; <span class="comment">// first index on X</span> start[1] = 0; <span class="comment">// first index on Y</span> start[2] = 0; <span class="comment">// first index on Z</span> <span class="comment">// Software Guide : EndCodeSnippet </span> <span class="comment">// Software Guide : BeginLatex</span> <span class="comment">//</span> <span class="comment">// The region size is represented by an array of the same dimension of the</span> <span class="comment">// image (using the Size class). The components of the array are</span> <span class="comment">// unsigned integers indicating the extent in pixels of the image along</span> <span class="comment">// every dimension.</span> <span class="comment">//</span> <span class="comment">// \index{itk::Image!Index}</span> <span class="comment">// \index{itk::Image!IndexType}</span> <span class="comment">//</span> <span class="comment">// Software Guide : EndLatex </span> <span class="comment">// </span> <span class="comment">// Software Guide : BeginCodeSnippet </span> <a name="a5"></a><a class="code" href="namespaceHardConnectedComponentImageFilter.html#5bf82236e1e50e653de84c8ead448599">ImageType::SizeType</a> size; size[0] = 200; <span class="comment">// size along X</span> size[1] = 200; <span class="comment">// size along Y</span> size[2] = 200; <span class="comment">// size along Z</span> <span class="comment">// Software Guide : EndCodeSnippet </span> <span class="comment">// Software Guide : BeginLatex</span> <span class="comment">//</span> <span class="comment">// Having defined the starting index and the image size, these two</span> <span class="comment">// parameters are used to create an ImageRegion object which basically</span> <span class="comment">// encapsulates both concepts. The region is initialized with the</span> <span class="comment">// starting index and size of the image.</span> <span class="comment">//</span> <span class="comment">// \index{itk::Image!itk::ImageRegion}</span> <span class="comment">// \index{itk::Image!RegionType}</span> <span class="comment">//</span> <span class="comment">// Software Guide : EndLatex </span> <span class="comment">// Software Guide : BeginCodeSnippet </span> <a name="a6"></a><a class="code" href="namespaceHardConnectedComponentImageFilter.html#ed8c4a40607d317c666eb96ea265e126">ImageType::RegionType</a> region; region.SetSize( size ); region.SetIndex( start ); <span class="comment">// Software Guide : EndCodeSnippet </span> <span class="comment">// Software Guide : BeginLatex</span> <span class="comment">//</span> <span class="comment">// Finally, the region is passed to the \code{Image} object in order to define its</span> <span class="comment">// extent and origin. The \code{SetRegions} method sets the</span> <span class="comment">// LargestPossibleRegion, BufferedRegion, and RequestedRegion</span> <span class="comment">// simultaneously. Note that none of the operations performed to this point</span> <span class="comment">// have allocated memory for the image pixel data. It is necessary to</span> <span class="comment">// invoke the \code{Allocate()} method to do this. Allocate does not</span> <span class="comment">// require any arguments since all the information needed for memory</span> <span class="comment">// allocation has already been provided by the region.</span> <span class="comment">//</span> <span class="comment">// \index{itk::Image!Allocate()}</span> <span class="comment">// \index{itk::Image!SetRegions()}</span> <span class="comment">//</span> <span class="comment">// Software Guide : EndLatex </span> <span class="comment">// Software Guide : BeginCodeSnippet </span> image->SetRegions( region ); image->Allocate(); <span class="comment">// Software Guide : EndCodeSnippet </span> <span class="keywordflow">return</span> 0; } </pre></div> </div> <hr><address><small> Generated at Thu May 7 22:04:07 2009 for ITK by <a href="http://www.stack.nl/~dimitri/doxygen/index.html"> <img src="http://www.stack.nl/~dimitri/doxygen/doxygen.png" alt="doxygen" align="middle" border=0 width=110 height=53> </a> 1.5.9 written by <a href="mailto:dimitri@stack.nl">Dimitri van Heesch</a>, © 1997-2000</small></address> </body> </html>