1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145
|
/*=========================================================================
Program: Insight Segmentation & Registration Toolkit
Module: $RCSfile: itkTIFFImageIOTest.cxx,v $
Language: C++
Date: $Date: 2009-11-13 17:50:20 $
Version: $Revision: 1.9 $
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.
=========================================================================*/
#include "itkImageFileReader.h"
#include "itkImageFileWriter.h"
#include "itkImage.h"
#include <fstream>
template<class T> int DoIt( int, char * argv[], typename T::Pointer)
{
typename itk::ImageFileReader<T>::Pointer reader
= itk::ImageFileReader<T>::New();
typename itk::ImageFileWriter<T>::Pointer writer
= itk::ImageFileWriter<T>::New();
reader->SetFileName(argv[1]);
try
{
reader->Update();
}
catch (itk::ExceptionObject & e)
{
std::cerr << "exception in file reader " << std::endl;
std::cerr << e << std::endl;
return EXIT_FAILURE;
}
typename T::Pointer image = reader->GetOutput();
image->Print(std::cout );
typename T::RegionType region = image->GetLargestPossibleRegion();
std::cout << "region " << region;
// Generate test image
writer->SetInput( reader->GetOutput() );
writer->SetFileName(argv[2]);
try
{
writer->Update();
}
catch (itk::ExceptionObject & e)
{
std::cerr << "exception in file writer " << std::endl;
std::cerr << e << std::endl;
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}
int itkTIFFImageIOTest( int argc, char* argv[] )
{
unsigned int dimension = 2;
unsigned int pixelType = 1;
if(argc < 3)
{
std::cerr << "Usage: " << argv[0]
<< " Input Output [dimensionality:default 2]"
<< "[pixeltype: 1:uchar(default) 2:ushort 3: short]\n";
return EXIT_FAILURE;
}
else if (argc == 4)
{
dimension = atoi(argv[3]);
}
else if (argc == 5)
{
dimension = atoi(argv[3]);
pixelType = atoi(argv[4]);
}
if (dimension == 2 && pixelType == 1)
{
typedef itk::RGBPixel<unsigned char> PixelType;
itk::Image<PixelType, 2>::Pointer dummy;
return DoIt<itk::Image<PixelType, 2> >( argc, argv, dummy);
}
else if (dimension == 2 && pixelType == 2)
{
typedef itk::RGBPixel<unsigned short> PixelType;
itk::Image<PixelType, 2>::Pointer dummy;
return DoIt<itk::Image<PixelType, 2> >( argc, argv, dummy);
}
else if (dimension == 2 && pixelType == 3)
{
typedef itk::RGBPixel<short> PixelType;
itk::Image<PixelType, 2>::Pointer dummy;
return DoIt<itk::Image<PixelType, 2> >( argc, argv, dummy);
}
else if (dimension == 3 && pixelType == 1)
{
itk::Image<unsigned char, 3>::Pointer dummy;
return DoIt<itk::Image<unsigned char, 3> >( argc, argv, dummy);
}
else if (dimension == 3 && pixelType == 2)
{
itk::Image<unsigned short, 3>::Pointer dummy;
return DoIt<itk::Image<unsigned short, 3> >( argc, argv, dummy);
}
else if (dimension == 3 && pixelType == 3)
{
itk::Image<short, 3>::Pointer dummy;
return DoIt<itk::Image<short, 3> >( argc, argv, dummy);
}
else if (dimension == 4 && pixelType == 1)
{
itk::Image<unsigned char, 4>::Pointer dummy;
return DoIt<itk::Image<unsigned char, 4> >( argc, argv, dummy);
}
else if (dimension == 4 && pixelType == 2)
{
itk::Image<unsigned short, 4>::Pointer dummy;
return DoIt<itk::Image<unsigned short, 4> >( argc, argv, dummy);
}
else if (dimension == 4 && pixelType == 3)
{
itk::Image<short, 4>::Pointer dummy;
return DoIt<itk::Image<short, 4> >( argc, argv, dummy);
}
else
{
std::cerr << "Usage: " << argv[0]
<< " Input Output [dimensionality:default 2]"
<< "[pixeltype: 1:uchar(default) 2:ushort 3: short]\n";
return EXIT_FAILURE;
}
}
|