18 #ifndef __itkIOTestHelper_h
19 #define __itkIOTestHelper_h
20 #include "ITKIOImageBaseExport.h"
23 #include "itksys/SystemTools.hxx"
26 #include "vnl/vnl_random.h"
32 template <
typename TImage>
33 static typename TImage::Pointer
ReadImage(
const std::string &fileName,
34 const bool zeroOrigin =
false )
38 typename ReaderType::Pointer reader = ReaderType::New();
40 reader->SetFileName( fileName.c_str() );
47 std::cout <<
"Caught an exception: " << std::endl;
48 std::cout << err <<
" " << __FILE__ <<
" " << __LINE__ << std::endl;
53 std::cout <<
"Error while reading in image for patient " << fileName << std::endl;
57 typename TImage::Pointer image = reader->GetOutput();
60 double origin[TImage::ImageDimension];
61 for(
unsigned int i = 0; i < TImage::ImageDimension; i++)
65 image->SetOrigin(origin);
70 template <
typename ImageType,
typename ImageIOType>
73 const std::string &filename)
77 typename WriterType::Pointer writer = WriterType::New();
79 typename ImageIOType::Pointer imageio(ImageIOType::New());
81 writer->SetImageIO(imageio);
83 writer->SetFileName(filename.c_str());
85 writer->SetInput(image);
92 std::cerr <<
"Exception Object caught: " << std::endl
103 for(
unsigned int i = 0; i < 3; i++)
109 template <
typename TPixel>
130 return itksys::SystemTools::RemoveFile(fname);
133 template <
typename ImageType>
136 typename ImageType::DirectionType dir;
138 im->SetDirection(dir);
141 template <
typename ImageType>
142 static typename ImageType::Pointer
144 const typename ImageType::SpacingType &spacing)
146 typename ImageType::Pointer rval = ImageType::New();
147 SetIdentityDirection<ImageType>(rval);
148 rval->SetSpacing(spacing);
149 rval->SetRegions(region);
153 template <
typename ImageType>
154 static typename ImageType::Pointer
156 const typename ImageType::SpacingType &spacing,
159 typename ImageType::Pointer rval = ImageType::New();
160 rval->SetSpacing(spacing);
161 rval->SetRegions(region);
162 rval->SetVectorLength(vecLength);
168 #endif // __itkIOTestHelper_h
static void RandomPix(vnl_random &randgen, TPixel &pix)
static void RandomPix(vnl_random &randgen, float &pix)
static void RandomPix(vnl_random &randgen, itk::RGBPixel< unsigned char > &pix)
static TImage::Pointer ReadImage(const std::string &fileName, const bool zeroOrigin=false)
static ImageType::Pointer AllocateImageFromRegionAndSpacing(const typename ImageType::RegionType ®ion, const typename ImageType::SpacingType &spacing, int vecLength)
Standard exception handling object.
static void WriteImage(typename ImageType::Pointer &image, const std::string &filename)
static ImageType::Pointer AllocateImageFromRegionAndSpacing(const typename ImageType::RegionType ®ion, const typename ImageType::SpacingType &spacing)
Represent Red, Green and Blue components for color images.
static void RandomPix(vnl_random &randgen, double &pix)
Writes image data to a single file.
Data source that reads image data from a single file.
static void SetIdentityDirection(typename ImageType::Pointer &im)
Define additional traits for native types such as int or float.
static int Remove(const char *fname)