freImageIO.h

Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   F.R.E.E. - flexible registration evaluation engine
00004   Version:   v.1.0.0
00005   Date:      $Date: 2006/09/01 12:00:00 $
00006   Module:    $RCSfile: freImageIO.h,v $
00007   Language:  C++
00008 
00009 
00010 
00011   Copyright (c) 2007 Ralf o Floca (Department of Medical Informatics,
00012   Institute for Medical Biometry and Informatics, University of Heidelberg,
00013   Germany). All rights reserved.
00014   See FREECopyright.txt or http://www.mi.med.uni-hd.de/free/copyright.htm
00015   for details.
00016 
00017      This software is distributed WITHOUT ANY WARRANTY; without even 
00018      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
00019      PURPOSE.  See the above copyright notices for more information.
00020 
00021 =========================================================================*/
00022 #ifndef __freImageIO_h
00023 #define __freImageIO_h
00024 
00025 #include "freElementals.h"
00026 
00027 #include "itkImageFileReader.h"
00028 #include "itkImageFileWriter.h"
00029 
00030 #include "itkImageSeriesReader.h"
00031 #include "itkImageSeriesWriter.h"
00032 #include "itkDICOMSeriesFileNames.h"
00033 #include "itkNumericSeriesFileNames.h"
00034 
00035 #include "itkResampleImageFilter.h"
00036 #include "itkScaleTransform.h"
00037 #include "itkLinearInterpolateImageFunction.h"
00038 #include "itkRescaleIntensityImageFilter.h"
00039 #include "itkCastImageFilter.h"
00040 #include "itkFixedArray.h"
00041 
00042 #include <iostream>
00043 #include <locale>
00044 
00045 namespace FREE
00046 {
00047 
00068 template <typename TInputPixel,typename TOutputPixel, unsigned int iDimension=2>
00069 class ImageWriter
00070 {
00071 public:  
00072   typedef itk::Image<TInputPixel,iDimension>  InputImageType;
00073   typedef itk::Image<TOutputPixel,iDimension> OutputImageType;
00074         
00075   virtual const char *GetNameOfClass() const
00076         {return "ImageWriter";};
00077 
00078 private:
00080   InputImageType* m_Image;
00082   std::string  m_FileName;
00084   bool m_bForceIsoVoxel;
00086   bool m_bRescaleImage;
00088   double m_dRescaleMin;
00090   double m_dRescaleMax;
00091 
00092   InputImageType* ConvertImageToIsoSpacing();
00093 
00094   void Save2D();
00095 
00096   void Save3D();
00097 
00098 public:
00102   const std::string  GetFileName() const;
00103 
00107   void SetFileName(const std::string  sFileName);
00108 
00109 
00113   const bool GetForceIsoVoxel() const;
00114 
00118   void SetForceIsoVoxel(const bool bForceIsoVoxel);
00119 
00123   const double GetRescaleMinimum() const;
00124 
00128   void SetRescaleMinimum(const double dRescaleMin);
00129 
00133   const double GetRescaleMaximum() const;
00134 
00138   void SetRescaleMaximum(const double dRescaleMax);
00139   
00143   const bool GetRescaleImage() const;
00144 
00148   void SetRescaleImage(const bool bRescaleImage);
00149 
00152   void SetInput (InputImageType* pImage);
00153 
00155   void Update ();
00156 
00157   ImageWriter();
00158 
00159   virtual ~ImageWriter();
00160 };
00161 
00183 template <typename TInputPixel,typename TOutputPixel, unsigned int iDimension=2>
00184 class ImageReader
00185 {
00186 public:  
00187   typedef itk::Image<TInputPixel,iDimension>  InputImageType;
00188   typedef itk::Image<TOutputPixel,iDimension> OutputImageType;
00189 
00190   virtual const char *GetNameOfClass() const 
00191     {return "ImageReader";}
00192         
00193 private:
00195   typename OutputImageType::Pointer m_Image;
00197   std::string  m_FileName;
00199   bool m_bForceIsoVoxel;
00201   int m_iUpperSeriesLimit;
00203   bool m_bUpToDate;
00205   bool m_bRescaleImage;
00207   double m_dRescaleMin;
00209   double m_dRescaleMax;
00210 
00211   void ConvertImageToIsoSpacing();
00212 
00213   void SetSpacingOfDicomSeries(const std::vector<std::string>& fileNames);
00214 
00215 
00216   void Load2D();
00217 
00218   void Load3D();
00219 
00220 public:
00224   const std::string  GetFileName() const;
00225 
00229   void SetFileName(const std::string  sFileName);
00230 
00234   const double GetRescaleMinimum() const;
00235 
00239   void SetRescaleMinimum(const double dRescaleMin);
00240 
00244   const double GetRescaleMaximum() const;
00245 
00249   void SetRescaleMaximum(const double dRescaleMax);
00250   
00254   const bool GetRescaleImage() const;
00255 
00259   void SetRescaleImage(const bool bRescaleImage);
00260 
00264   const int GetUpperSeriesLimit() const;
00265 
00269   void SetUpperSeriesLimit(const int iUpperLimit);
00270 
00274   const bool GetForceIsoVoxel() const;
00275 
00279   void SetForceIsoVoxel(const bool bForceIsoVoxel);
00280 
00283   OutputImageType*  GetOutput (void);
00284 
00285   ImageReader();
00286 
00287   virtual ~ImageReader();
00288 
00289         static typename OutputImageType::Pointer LoadImage(const std::string  sFile, const bool& bRescale = false, const TOutputPixel& rescaleMin = 0, const TOutputPixel& rescaleMax = 255)
00290         {
00291                         ImageReader<TInputPixel ,TOutputPixel,iDimension> imageReader;
00292                         imageReader.SetFileName(sFile);
00293                         imageReader.SetForceIsoVoxel(false);
00294                         imageReader.SetRescaleImage(bRescale);
00295                         imageReader.SetRescaleMaximum(rescaleMax);
00296                         imageReader.SetRescaleMinimum(rescaleMin);
00297                         imageReader.SetUpperSeriesLimit(40);
00298                         typename OutputImageType::Pointer rImage = imageReader.GetOutput();
00299                         return rImage;
00300         };
00301 
00302 };
00303 
00304 } //end of namespace free
00305 
00306 #ifndef ITK_MANUAL_INSTANTIATION
00307 #include "freImageIO.txx"
00308 #endif
00309 
00310 #endif

Generated at Sat Oct 13 16:02:28 2007 for f.r.e.e. - Flexible Registration and Evaluation Engine by doxygen 1.5.3 written by Dimitri van Heesch, © 1997-2000