DGtal  0.9.3
Functions
testITKImage.cpp File Reference
#include <iostream>
#include "DGtal/base/Common.h"
#include "DGtal/kernel/SpaceND.h"
#include "DGtal/kernel/domains/HyperRectDomain.h"
#include "DGtal/images/ImageContainerByITKImage.h"
#include <boost/foreach.hpp>
#include <itkExtractImageFilter.h>
Include dependency graph for testITKImage.cpp:

Go to the source code of this file.

Functions

bool testITKImage ()
 
bool testITKMethod ()
 
int main (int argc, char **argv)
 

Detailed Description

This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.

Author
David Coeurjolly (david.nosp@m..coe.nosp@m.urjol.nosp@m.ly@l.nosp@m.iris..nosp@m.cnrs.nosp@m..fr ) Laboratoire d'InfoRmatique en Image et Systèmes d'information - LIRIS (CNRS, UMR 5205), CNRS, France
Date
2010/12/09

Functions for testing class ITKImage.

This file is part of the DGtal library.

Definition in file testITKImage.cpp.

Function Documentation

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 216 of file testITKImage.cpp.

References DGtal::Trace::beginBlock(), DGtal::Trace::emphase(), DGtal::Trace::endBlock(), DGtal::Trace::info(), testITKImage(), testITKMethod(), and DGtal::trace.

217 {
218  trace.beginBlock ( "Testing class ITKImage" );
219  trace.info() << "Args:";
220  for ( int i = 0; i < argc; ++i )
221  trace.info() << " " << argv[ i ];
222  trace.info() << endl;
223 
224  bool res = testITKImage() && testITKMethod();
225  trace.emphase() << ( res ? "Passed." : "Error." ) << endl;
226  trace.endBlock();
227  return res ? 0 : 1;
228 }
void beginBlock(const std::string &keyword="")
Trace trace
Definition: Common.h:137
double endBlock()
bool testITKImage()
std::ostream & emphase()
std::ostream & info()
bool testITKMethod()

◆ testITKImage()

bool testITKImage ( )

Example of a test. To be completed.

Definition at line 67 of file testITKImage.cpp.

References DGtal::Trace::beginBlock(), DGtal::Trace::endBlock(), DGtal::Trace::info(), DGtal::Image< TImageContainer >::setValue(), DGtal::trace, and DGtal::Trace::warning().

Referenced by main().

68 {
69  unsigned int nbok = 0;
70  unsigned int nb = 0;
71 
72  trace.beginBlock ( "ITK Image init..." );
73 
74  typedef DGtal::int32_t Integer;
75  typedef SpaceND<3, Integer > Space3Type;
77  typedef Domain::Point Point;
78 
80 
81  const Integer t[ ] = { 1, 1, 1};
82  const Integer t2[ ] = { 5, 5, 5};
83  const Integer t3[ ] = { 2, 2, 2};
84  Point a ( t );
85  Point b ( t2 );
86  Point c ( t3 );
87  Integer val;
88 
89  Image myImage ( Domain(a, b) );
90 
91  trace.info() << myImage << std::endl;
92  trace.info() << "getvalue= " << myImage(c) << endl;
93  trace.info() << "set value 23 " << endl;
94  myImage.setValue( c, 23);
95 
96  val = myImage(c);
97 
98  if (val == 23)
99  nbok++;
100  trace.info() << "getvalue= " << val << endl;
101  nb++;
102 
103  //Iterator test
104  trace.info() << "Simple Iterator=";
105  for (Image::ConstIterator it = myImage.begin(), itend = myImage.end();
106  it != itend;
107  ++it)
108  trace.warning() << myImage(it) << " ";
109  trace.info() << endl;
110 
111  //We rewrite the image
112  int nbVal = 0;
113  for (Image::Iterator it = myImage.begin(), itend = myImage.end();
114  it != itend;
115  ++it)
116  myImage.setValue(it, nbVal++);
117 
118  trace.info() << "Set Iterator=";
119  for (Image::ConstIterator it = myImage.begin(), itend = myImage.end();
120  it != itend;
121  ++it)
122  trace.warning() << myImage(it) << " ";
123  trace.info() << endl;
124 
125 
126  trace.info() << "(" << nbok << "/" << nb << ") "
127  << "true == true" << std::endl;
128  trace.endBlock();
129 
130  return nbok == nb;
131 }
void beginBlock(const std::string &keyword="")
DGtal::int32_t Integer
Definition: StdDefs.h:74
HyperRectDomain< Space > Domain
Trace trace
Definition: Common.h:137
Aim: SpaceND is a utility class that defines the fundamental structure of a Digital Space in ND...
Definition: SpaceND.h:95
Aim: Parallelepidec region of a digital space, model of a &#39;CDomain&#39;.
double endBlock()
MyPointD Point
Definition: testClone2.cpp:383
std::ostream & warning()
std::ostream & info()
ImageContainerBySTLVector< Domain, Value > Image
boost::int32_t int32_t
signed 32-bit integer.
Definition: BasicTypes.h:72
Aim: implements a model of CImageContainer using a ITK Image.

◆ testITKMethod()

bool testITKMethod ( )

Definition at line 133 of file testITKImage.cpp.

References DGtal::Trace::beginBlock(), domain(), DGtal::Trace::endBlock(), index(), DGtal::Trace::info(), DGtal::Image< TImageContainer >::setValue(), DGtal::trace, and DGtal::Trace::warning().

Referenced by main().

134 {
135  unsigned int nbok = 0;
136  unsigned int nb = 0;
137 
138  trace.beginBlock ( "Test the use of a pure ITK method..." );
139 
140  typedef DGtal::int32_t Integer;
143  typedef Domain::Point Point;
144 
145 
147 
148  Point a ( 0, 0 );
149  Point b ( 9, 9);
150  Domain domain(a, b);
151 
152  Image myImage(domain);
153  trace.info() << myImage << std::endl;
154 
155  //We fill the image
156  Integer nbVal = 0;
157  for (Image::Iterator it = myImage.begin(), itend = myImage.end();
158  it != itend;
159  ++it)
160  myImage.setValue(it, nbVal++);
161 
162  trace.info() << "Input image=";
163  for (Image::ConstIterator it = myImage.begin(), itend = myImage.end();
164  it != itend;
165  ++it)
166  trace.warning() << myImage(it) << " ";
167  trace.info() << endl;
168 
169 
170  // We define a cropFilter
171  typedef itk::ExtractImageFilter< Image::ITKImage, Image::ITKImage > CropFilter;
172 
173  // Crop filter region
174  Image::ITKImage::SizeType size;
175  size[0] = 5;
176  size[1] = 5;
177 
178  Image::ITKImage::IndexType index;
179  index[0] = 2;
180  index[1] = 2;
181 
182  Image::ITKImage::RegionType regionToExtract(index,size);
183 
184  // Crop filter process
185  CropFilter::Pointer cropFilter = CropFilter::New();
186  cropFilter->SetInput( myImage.getITKImagePointer() );
187  cropFilter->SetExtractionRegion( regionToExtract );
188  cropFilter->Update();
189 
190  // Pointer to the filter output
191  Image::ITKImagePointer handleOut = cropFilter->GetOutput();
192  Image myImageOut ( handleOut );
193 
194 
195  trace.info() << "Output image=";
196 
197  for (Image::ConstIterator it = myImageOut.begin(), itend = myImageOut.end();
198  it != itend;
199  ++it)
200  {
201  nbok += (it.Value() == (it.GetIndex()[1]*10 + it.GetIndex()[0]));
202  nb++;
203  trace.warning() << it.Value() << "(" << (it.GetIndex()[1]*10 + it.GetIndex()[0]) << ")" << " ";
204  }
205  trace.info() << endl;
206 
207  trace.info() << "(" << nbok << "/" << nb << ") " << "true == true" << std::endl;
208  trace.endBlock();
209 
210  return nbok == 25 && nb == 25;
211 }
void beginBlock(const std::string &keyword="")
DGtal::int32_t Integer
Definition: StdDefs.h:74
HyperRectDomain< Space > Domain
const Domain domain(Point(1, 2), Point(6, 5))
unsigned int index(DGtal::uint32_t n, unsigned int b)
Definition: testBits.cpp:44
Trace trace
Definition: Common.h:137
SpaceND< 2, int > Space2Type
Aim: Parallelepidec region of a digital space, model of a &#39;CDomain&#39;.
double endBlock()
MyPointD Point
Definition: testClone2.cpp:383
std::ostream & warning()
std::ostream & info()
ImageContainerBySTLVector< Domain, Value > Image
boost::int32_t int32_t
signed 32-bit integer.
Definition: BasicTypes.h:72
Aim: implements a model of CImageContainer using a ITK Image.