forked from kalxas/mseg
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmsegio.h
218 lines (171 loc) · 6.24 KB
/
msegio.h
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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* msegio.h: Image base classes *
* Version: 0.9.x *
* Last revised: 05/08/2009 *
* *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* MSEG algorithm by Angelos Tzotsos ([email protected]) *
* Remote Sensing Lab NTUA - GCpp August 2009 *
* *
* Copyright (C) Angelos Tzotsos <[email protected]> *
* *
* This program is free software: you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation, either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
* *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
#ifndef MSEGIO_H
#define MSEGIO_H
#define TRUE 1
#define FALSE 0
#include <string>
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <math.h>
#include <map>
#include <queue>
#include "FreeImage.h"
#include <stdio.h>
#include <string.h>
using namespace std;
//typedef unsigned char CELL_TYPE;
typedef unsigned char uchar;
typedef unsigned short ushort;
typedef signed short sshort;
string find_cell_type(string HeaderName);
int D1(int imglines, int imgcolumns, int line, int column);
struct Coordinate {
string Datum;
string Projection;
string CoordinateType;
string Units;
string Rotation;
};
struct Macroblock {
int size;
int LineStart;
int LineEnd;
int ColumnStart;
int ColumnEnd;
};
struct pixel {
int line;
int column;
};
struct point {
double x;
double y;
double z;
};
struct CoPair {
int first;
int second;
};
typedef vector<CoPair> CoDistribution;
pixel D2(int d, int imgcolumns);
class Image { //Virtual class
public:
//Image basic components
int Bands; //Number of Bands
int Lines; //Number of Lines
int Columns; //Number of Columns
int Bytes;
//size_t CELL_TYPE; //Spectral depth of image data
string FileName;
string CellType;
//Raw data file
ifstream file; //or FILE* if necesary
//Memory Buffer
vector<uchar> Buffer8; //in case of 1D array
vector<ushort> Buffer16;
vector<sshort> Buffer16s;
vector<float> Buffer32;
//CELL_TYPE ***Buffer; //in case of 3D array
int BuffLineStart;
int BuffLineEnd;
//Band Weights for heterogeneity calculation
vector<float> BandWeight;
//Macroblock list
int MacroSize;
int MacroLines;
int MacroColumns;
vector<struct Macroblock> Macroblocks;
Image(); //Constructor
~Image(); //Destructor
};//Image End
class ERS_Image : public Image {
public:
int NullValue;
//ERS Header strings
string HeaderName;
string ERSVersion;
string DataType;
string ByteOrder;
string LastUpdated;
//ERS Band names
vector<string> BandID;
//ERS Geocoding Information
Coordinate CoordinateSpace;
point RegistrationPoint;
point RegistrationCell;
double GroundSizeX;
double GroundSizeY;
//Data Input Functions
float Buffer(int line, int column, int band);//Returns one pixel value in 3D representation
float Buffer(int indx);//Returns one pixel value in 1D representation
//void FillBuffer(int LineStart, int LineEnd); //Fills the Buffer with several lines
//void FillBuffer(Macroblock* macro); //Fills the buffer with one macroblock
void FullBuffer(); //Loads the whole image on memory
void SaveAs(string); //Saves the image in ERS format
void SaveAs(string, int); //Saves the image with null value
int D1(int line, int column, int band);
//Constructors and Destructors
ERS_Image(string, int); //Constructor accepting the Header Filename as an argument
ERS_Image(string NAME, int BANDS, int LINES, int COLUMNS, string cell_type);
ERS_Image(string NAME, int BANDS, int LINES, int COLUMNS, int BYTES);
//Generic constructor for output images
~ERS_Image();
};//ERS_Image End
class Texture_Image : public Image {
public:
//Buffer stuff
vector<int> YBuffer;
int BuffMin;
int BuffMax;
int bitdepth;
int quant;
int distance;
ERS_Image *Img;
void FullYBuffer();
int Transform(int p);
vector<unsigned long> hist;
//unsigned long hist[256];
void BuildHistogram();
//LUT stuff
//vector<CELL_TYPE> LUT;
uchar LUT[256];
void CalculateLUT();
//co-occurence cube stuff
vector<CoDistribution> CoCube;
void BuildCoCube();
void CheckCoCube();
bool CoCubeBuilt;
//Constructors and Destructors
Texture_Image(); //Constructor
Texture_Image(ERS_Image& Img, int quantizer, int distance);
~Texture_Image(); //Destructor
};
#endif /* MSEGIO_H */