1 /*****************************************************************************
5 ** Purpose: imagefile class header
6 ** Programmer: Kevin Rosenberg
7 ** Date Started: June 2000
9 ** This is part of the CTSim program
10 ** Copyright (c) 1983-2001 Kevin Rosenberg
12 ** $Id: imagefile.h,v 1.36 2001/09/24 09:40:42 kevin Exp $
14 ** This program is free software; you can redistribute it and/or modify
15 ** it under the terms of the GNU General Public License (version 2) as
16 ** published by the Free Software Foundation.
18 ** This program is distributed in the hope that it will be useful,
19 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
20 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 ** GNU General Public License for more details.
23 ** You should have received a copy of the GNU General Public License
24 ** along with this program; if not, write to the Free Software
25 ** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26 ******************************************************************************/
35 #include <sys/types.h>
38 #include "ctsupport.h"
39 #include "fnetorderstream.h"
40 #include "array2dfile.h"
46 class F32Image : public Array2dFile
49 F32Image (int nx, int ny, int dataType = Array2dFile::DATA_TYPE_REAL);
52 kfloat32** getArray (void)
53 { return (kfloat32**) (m_arrayData); }
55 kfloat32** const getArray (void) const
56 { return (kfloat32** const) (m_arrayData); }
58 kfloat32** getImaginaryArray (void)
59 { return (kfloat32**) (m_imaginaryArrayData); }
61 kfloat32** const getImaginaryArray (void) const
62 { return (kfloat32** const) (m_imaginaryArrayData); }
65 MPI::Datatype getMPIDataType (void) const
66 { return MPI::FLOAT; }
70 F32Image (const F32Image& rhs); //copy constructor
71 F32Image& operator= (const F32Image& rhs); // assignment operator
75 class F64Image : public Array2dFile
79 F64Image (int nx, int ny, int dataType = Array2dFile::DATA_TYPE_REAL);
82 kfloat64** getArray (void)
83 { return (kfloat64**) (m_arrayData); }
85 kfloat64** const getArray (void) const
86 { return (kfloat64** const) (m_arrayData); }
88 kfloat64** getImaginaryArray (void)
89 { return (kfloat64**) (m_imaginaryArrayData); }
91 kfloat64** const getImaginaryArray (void) const
92 { return (kfloat64** const) (m_imaginaryArrayData); }
95 MPI::Datatype getMPIDataType (void) const
96 { return MPI::DOUBLE; }
99 F64Image (const F64Image& rhs); //copy constructor
100 F64Image& operator= (const F64Image& rhs); // assignment operator
103 #undef IMAGEFILE_64_BITS
104 #ifdef IMAGEFILE_64_BITS
105 typedef F64Image ImageFileBase;
106 typedef kfloat64 ImageFileValue;
107 typedef kfloat64* ImageFileColumn;
108 typedef kfloat64** ImageFileArray;
109 typedef kfloat64** const ImageFileArrayConst;
110 typedef const kfloat64* ImageFileColumnConst;
112 typedef F32Image ImageFileBase;
113 typedef kfloat32 ImageFileValue;
114 typedef kfloat32* ImageFileColumn;
115 typedef kfloat32** ImageFileArray;
116 typedef kfloat32** const ImageFileArrayConst;
117 typedef const kfloat32* ImageFileColumnConst;
122 class ImageFile : public ImageFileBase
126 static const char* s_aszExportFormatName[];
127 static const char* s_aszExportFormatTitle[];
128 static const int s_iExportFormatCount;
129 static const char* s_aszImportFormatName[];
130 static const char* s_aszImportFormatTitle[];
131 static const int s_iImportFormatCount;
133 static void skipSpacePPM (FILE* fp); // skip space in a ppm file
137 static const int EXPORT_FORMAT_INVALID;
138 static const int IMPORT_FORMAT_INVALID;
139 static const int EXPORT_FORMAT_TEXT;
140 static const int EXPORT_FORMAT_PGM;
141 static const int EXPORT_FORMAT_PGMASCII;
142 static const int IMPORT_FORMAT_PPM;
144 static const int EXPORT_FORMAT_PNG;
145 static const int EXPORT_FORMAT_PNG16;
146 static const int IMPORT_FORMAT_PNG;
149 static const int EXPORT_FORMAT_DICOM;
150 static const int IMPORT_FORMAT_DICOM;
152 static const int EXPORT_FORMAT_RAW;
154 static const int getExportFormatCount() {return s_iExportFormatCount;}
155 static const char** getExportFormatNameArray() {return s_aszExportFormatName;}
156 static const char** getExportFormatTitleArray() {return s_aszExportFormatTitle;}
157 static int convertExportFormatNameToID (const char* const ExportFormatName);
158 static const char* convertExportFormatIDToName (const int ExportFormatID);
159 static const char* convertExportFormatIDToTitle (const int ExportFormatID);
161 static const int getImportFormatCount() {return s_iImportFormatCount;}
162 static const char** getImportFormatNameArray() {return s_aszImportFormatName;}
163 static const char** getImportFormatTitleArray() {return s_aszImportFormatTitle;}
164 static int convertImportFormatNameToID (const char* const ImportFormatName);
165 static const char* convertImportFormatIDToName (const int ImportFormatID);
166 static const char* convertImportFormatIDToTitle (const int ImportFormatID);
168 static const double s_dRedGrayscaleFactor;
169 static const double s_dGreenGrayscaleFactor;
170 static const double s_dBlueGrayscaleFactor;
172 ImageFile (int nx, int ny)
173 : ImageFileBase (nx, ny)
180 void getCenterCoordinates (unsigned int& iXCenter, unsigned int& iYCenter);
182 bool convertRealToComplex ();
183 bool convertComplexToReal ();
185 void filterResponse (const char* const domainName, double bw, const char* const filterName, double filt_param, double dInputScale = 1., double dOutputScale = 1.);
187 void statistics (double& min, double& max, double& mean, double& mode, double& median, double& stddev) const;
188 void statistics (ImageFileArrayConst v, double& min, double& max, double& mean, double& mode, double& median, double& stddev) const;
189 void getMinMax (double& min, double& max) const;
190 void printStatistics (std::ostream& os) const;
191 bool comparativeStatistics (const ImageFile& imComp, double& d, double& r, double& e) const;
192 bool printComparativeStatistics (const ImageFile& imComp, std::ostream& os) const;
194 bool subtractImages (const ImageFile& rRHS, ImageFile& result) const;
195 bool addImages (const ImageFile& rRHS, ImageFile& result) const;
196 bool multiplyImages (const ImageFile& rRHS, ImageFile& result) const;
197 bool divideImages (const ImageFile& rRHS, ImageFile& result) const;
199 bool scaleImage (ImageFile& result) const;
201 bool invertPixelValues (ImageFile& result) const;
202 bool sqrt (ImageFile& result) const;
203 bool square (ImageFile& result) const;
204 bool log (ImageFile& result) const;
205 bool exp (ImageFile& result) const;
206 bool fourier (ImageFile& result) const;
207 bool inverseFourier (ImageFile& result) const;
209 bool fft (ImageFile& result) const;
210 bool ifft (ImageFile& result) const;
211 bool fftRows (ImageFile& result) const;
212 bool ifftRows (ImageFile& result) const;
213 bool fftCols (ImageFile& result) const;
214 bool ifftCols (ImageFile& result) const;
216 bool magnitude (ImageFile& result) const;
217 bool phase (ImageFile& result) const;
218 bool real (ImageFile& result) const;
219 bool imaginary (ImageFile& result) const;
221 bool exportImage (const char* const pszFormat, const char* const pszFilename, int nxcell, int nycell, double densmin, double densmax);
223 bool importImage (const char* const pszFormat, const char* const pszFilename);
226 bool writeImagePNG (const char* const outfile, int bitdepth, int nxcell, int nycell, double densmin, double densmax);
227 bool readImagePNG (const char* const pszFile);
230 bool writeImageGIF (const char* const outfile, int nxcell, int nycell, double densmin, double densmax);
232 bool writeImagePGM (const char* const outfile, int nxcell, int nycell, double densmin, double densmax);
233 bool writeImagePGMASCII (const char* const outfile, int nxcell, int nycell, double densmin, double densmax);
234 bool readImagePPM (const char* const pszFile);
235 bool writeImageRaw(const char* const outfile, int nxcell, int nycell);
236 bool writeImageText (const char* const outfile);
238 static double redGrayscaleFactor() {return s_dRedGrayscaleFactor;}
239 static double greenGrayscaleFactor() {return s_dGreenGrayscaleFactor;}
240 static double blueGrayscaleFactor() {return s_dBlueGrayscaleFactor;}
241 static double colorToGrayscale (double r, double g, double b)
242 { return r * s_dRedGrayscaleFactor + g * s_dGreenGrayscaleFactor + b * s_dBlueGrayscaleFactor; }