STIR  6.2.0
GIPL_ImageFormat.h
Go to the documentation of this file.
1 //
2 /*
3  Copyright (C) 2012 - 2013, King's College London
4  This file is part of STIR.
5 
6  SPDX-License-Identifier: Apache-2.0
7 
8  See STIR/LICENSE.txt for details
9  */
18 /*-----
19  Original Copyright (c) 2012, Division of Imaging Sciences & Biomedical Engineering,
20 King's College London
21 
22 All rights reserved.
23 
24 Redistribution and use in source and binary forms, with or without modification,
25 are permitted provided that the following conditions are met:
26 
27  * Redistributions of source code must retain the above copyright notice,
28  this list of conditions and the following disclaimer.
29  * Redistributions in binary form must reproduce the above copyright notice,
30  this list of conditions and the following disclaimer in the documentation
31  and/or other materials provided with the distribution.
32 
33 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
34 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
35 OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
36 SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
37 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
38 OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
39 HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
40 TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
41 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
42 -----*/
43 
44 // -------------------------------------------------------------------------
61 // -------------------------------------------------------------------------
62 
63 #ifndef __GIPL_IMAGE_H
64 # define __GIPL_IMAGE_H
65 
66 # include <vector>
67 # include <stdio.h>
68 # include <fstream>
69 
70 # define _SHORT 0
71 # define _FLOAT 1
72 
73 //#include "ByteSwap.h"
74 
75 // -------------------------------------------------------------------------
76 // Image class
77 // -------------------------------------------------------------------------
78 
79 class Image
80 {
81 public:
82  Image();
83  Image(const int num_voxels, const short data_type_case);
84 
85  ~Image();
86 
87  // Image data types
88  short* vData;
89  float* vData_f;
90 
91  // Dimensions of image in voxels and time (x,y,z,t). Bytes: 0 to 7.
92  short m_dim[4];
93 
94  // Image data type (binary, char, short etc). Bytes: 8 and 9.
95  short m_image_type;
96 
97  // Dimensions of individual image voxels (x,y,z,t). Bytes: 10 to 25.
98  float m_pixdim[4];
99 
100  // Patient description string. Bytes: 26 to 105.
101  char m_patDesc[80];
102 
103  // Matrix (transformation?) stored with image. Bytes: 106 to 153.
104  float m_matrixElements[12];
105 
106  // Image identification number. Bytes: 154 to 157.
107  int m_identifier;
108 
109  // Spare storage string. Bytes: 158 to 185.
110  char m_spare[28];
111 
112  // Orientation of the image (AP, lateral, axial etc). Byte 186.
113  char m_orientationFlag;
114 
115  // GIPL version number. Byte 187.
116  char m_flag1;
117 
118  // Minimum data value. Bytes: 188 to 195.
119  double m_min;
120 
121  // Maximum data value. Bytes: 196 to 203.
122  double m_max;
123 
124  // Image origin in mm. Bytes: 204 to 235.
125  double m_origin[4];
126 
127  // Pixel value offset. Bytes: 236 to 239.
128  float m_pixval_offset;
129 
130  // Pixel value calibration. Bytes: 240 to 243.
131  float m_pixval_cal;
132 
133  // User defined float 1. Bytes: 244 to 247.
134  float m_user_def1;
135 
136  // User defined float 2. Bytes: 248 to 251.
137  float m_user_def2;
138 
139  // GIPL magic number. Bytes: 252 to 255.
140  unsigned int m_magic_number;
141 
142  // Data dimension
143  int ImageDimension;
144 
145  // Parameter dimension
146  int ParametersDimension;
147 
148  // Data vector length
149  int MaxLength;
150 
151  // Max and min gray value
152  float iMax;
153  float iMin;
154 
155  // Offset vector
156  int ImageOffset[2];
157 
158  // Center of rotation
159  float vCenter[4];
160 
161  // Downscaling properties
162  short vDownsample[3];
163 
164  // Input output functions
165  void GiplRead(char* filename);
166  void ReadGiplHeader(std::fstream* myFile);
167  void GiplWrite(const char* filename);
168  void WriteGiplHeader(std::fstream* myFile);
169  void ByteSwapHeader();
170 
171  // Get minimum and maximum gray values
172  void GetMinMaxValue();
173 
174  // Initialize and copy images
175  void Initialize(Image* Input, short type);
176  void Initialize(Image* Input);
177  void Zeros(Image* Input, short type);
178  void Zeros();
179  void Ones(Image* Input, short type);
180  void Copy(Image* Input, short type);
181 
182  // Swap bytes if necessary
183  void ByteSwap(int* i);
184  void ByteSwap(short* s);
185  void ByteSwap(float* f);
186  void ByteSwap(double* d);
187 };
188 
189 #endif
190 
191 // -------------------------------------------------------------------------
192 // EOF
193 // -------------------------------------------------------------------------
void GetMinMaxValue()
Get minimum and maximum gray values in image.
Definition: GIPL_ImageFormat.cxx:247
void Initialize(Image *Input, short type)
Initialize image data by with the dimension of the input image.
Definition: GIPL_ImageFormat.cxx:556
void Zeros()
Initialize zero image.
Definition: GIPL_ImageFormat.cxx:493
void GiplWrite(const char *filename)
Write image data to GIPL output file.
Definition: GIPL_ImageFormat.cxx:319
void WriteGiplHeader(std::fstream *myFile)
Write GIPL header to output file.
Definition: GIPL_ImageFormat.cxx:388
void ReadGiplHeader(std::fstream *myFile)
Read GIPL header.
Definition: GIPL_ImageFormat.cxx:283
void Ones(Image *Input, short type)
Initialize one image.
Definition: GIPL_ImageFormat.cxx:525
void ByteSwapHeader()
Swap bytes (little/big endian conversion).
Definition: GIPL_ImageFormat.cxx:422
void Copy(Image *Input, short type)
Copy image.
Definition: GIPL_ImageFormat.cxx:650
Reading and writing gipl files.
Definition: GIPL_ImageFormat.h:79
void GiplRead(char *filename)
Read data from GIPL filename.
Definition: GIPL_ImageFormat.cxx:130