e8eb202f
David Mayerich
added a new ENVI ...
|
1
2
3
4
5
6
7
|
#ifndef STIM_ENVI_H
#define STIM_ENVI_H
#include "../envi/envi_header.h"
#include "../envi/bsq.h"
#include "../envi/bip.h"
#include "../envi/bil.h"
|
bfe9c6db
heziqi
added feature_mat...
|
8
|
#include <iostream>
|
7b3948ab
David Mayerich
added support for...
|
9
|
#include "../image/image.h"
|
e8eb202f
David Mayerich
added a new ENVI ...
|
10
|
|
8a86bd56
David Mayerich
changed rts names...
|
11
|
namespace stim{
|
e8eb202f
David Mayerich
added a new ENVI ...
|
12
|
|
cb455f98
David Mayerich
removed old ENVI ...
|
13
14
15
16
17
|
/** This class implements reading of ENVI hyperspectral files. These files can be stored in multiple orientations
(including BSQ, BIP, and BIL) in order to optimize streaming speed depending on applications. Basic ENVI
files are stored on disk as a large binary file with a corresponding header. Code for reading and processing
ENVI header files is in the envi_header class.
*/
|
4a6f666c
heziqi
Added mask method
|
18
|
class envi{
|
e8eb202f
David Mayerich
added a new ENVI ...
|
19
20
21
22
23
|
void* file; //void pointer to the relevant file reader (bip, bsq, or bil - with appropriate data type)
public:
|
4a6f666c
heziqi
Added mask method
|
24
25
|
envi_header header;
|
cb455f98
David Mayerich
removed old ENVI ...
|
26
|
/// Allocate memory for a new ENVI file based on the current interleave format (BIP, BIL, BSQ) and data type.
|
e8eb202f
David Mayerich
added a new ENVI ...
|
27
28
29
30
|
bool allocate(){
file = NULL; //set file to a NULL pointer
|
6708cc25
heziqi
Ziqi added envi c...
|
31
|
if(header.interleave == envi_header::BSQ){
|
e8eb202f
David Mayerich
added a new ENVI ...
|
32
33
|
if(header.data_type ==envi_header::float32)
return(file = new bsq<float>());
|
6708cc25
heziqi
Ziqi added envi c...
|
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
else if(header.data_type == envi_header::float64)
return(file = new bsq<double>());
}
else if(header.interleave == envi_header::BIP){
if(header.data_type ==envi_header::float32)
return(file = new bip<float>());
else if(header.data_type == envi_header::float64)
return(file = new bip<double>());
}
else if(header.interleave == envi_header::BIL){
if(header.data_type ==envi_header::float32)
return(file = new bil<float>());
else if(header.data_type == envi_header::float64)
return(file = new bil<double>());
}
|
e8eb202f
David Mayerich
added a new ENVI ...
|
49
50
51
52
53
|
exit(1); //if the function hasn't already returned, we don't handle this state
}
|
cb455f98
David Mayerich
removed old ENVI ...
|
54
55
56
57
|
/// Open an existing ENVI file given the file and header names.
/// @param filename is the name of the ENVI binary file
/// @param headername is the name of the ENVI header file
|
e8eb202f
David Mayerich
added a new ENVI ...
|
58
59
60
61
62
63
64
65
66
|
bool open(std::string filename, std::string headername){
//allocate memory
allocate();
//load the header
header.load(headername);
//load the file
|
6708cc25
heziqi
Ziqi added envi c...
|
67
68
|
if(header.interleave == envi_header::BSQ) { //if the infile is bsq file
if(header.data_type == envi_header::float32) {
|
e8eb202f
David Mayerich
added a new ENVI ...
|
69
|
return ((bsq<float>*)file)->open(filename, header.samples, header.lines, header.bands, header.header_offset, header.wavelength);
|
6708cc25
heziqi
Ziqi added envi c...
|
70
71
72
73
74
75
76
|
}
else if(header.data_type == envi_header::float64) {
return ((bsq<double>*)file)->open(filename, header.samples, header.lines, header.bands, header.header_offset, header.wavelength);
}
else
return false;
}
|
e8eb202f
David Mayerich
added a new ENVI ...
|
77
|
|
6708cc25
heziqi
Ziqi added envi c...
|
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
|
else if(header.interleave == envi_header::BIL) { //if the infile is bil file
if(header.data_type == envi_header::float32) {
return ((bil<float>*)file)->open(filename, header.samples, header.lines, header.bands, header.header_offset, header.wavelength);
}
else if(header.data_type == envi_header::float64) {
return ((bil<double>*)file)->open(filename, header.samples, header.lines, header.bands, header.header_offset, header.wavelength);
}
else
return false;
}
else if(header.interleave == envi_header::BIP) { //if the infile is bip file
if(header.data_type == envi_header::float32) {
return ((bip<float>*)file)->open(filename, header.samples, header.lines, header.bands, header.header_offset, header.wavelength);
}
else if(header.data_type == envi_header::float64) {
return ((bip<double>*)file)->open(filename, header.samples, header.lines, header.bands, header.header_offset, header.wavelength);
}
else
return false;
}
else{
|
84a4e0f1
David Mayerich
fixed a cout bug
|
101
|
std::cout<<"ERROR: unidentified type file "<<headername<<std::endl;
|
e8eb202f
David Mayerich
added a new ENVI ...
|
102
|
exit(1);
|
6708cc25
heziqi
Ziqi added envi c...
|
103
104
|
}
|
e8eb202f
David Mayerich
added a new ENVI ...
|
105
106
|
}
|
cb455f98
David Mayerich
removed old ENVI ...
|
107
108
109
110
111
|
/// Normalize a hyperspectral ENVI file given a band number and threshold.
/// @param outfile is the name of the normalized file to be output
/// @param band is the band label to be output
/// @param threshold is a threshold value specified such that normalization will only be done to values in the band > threshold (preventing division by small numbers)
|
93503ec6
David Mayerich
allowed masking d...
|
112
|
bool normalize(std::string outfile, double band, double threshold = 0.0){
|
6708cc25
heziqi
Ziqi added envi c...
|
113
114
|
if(header.interleave == envi_header::BSQ){ //if the infile is bsq file
|
e8eb202f
David Mayerich
added a new ENVI ...
|
115
|
if(header.data_type ==envi_header::float32)
|
93503ec6
David Mayerich
allowed masking d...
|
116
|
return ((bsq<float>*)file)->normalize(outfile, band, threshold);
|
6708cc25
heziqi
Ziqi added envi c...
|
117
|
else if(header.data_type == envi_header::float64)
|
93503ec6
David Mayerich
allowed masking d...
|
118
|
return ((bsq<double>*)file)->normalize(outfile,band, threshold);
|
6708cc25
heziqi
Ziqi added envi c...
|
119
120
121
|
else
std::cout<<"ERROR: unidentified data type"<<std::endl;
}
|
e8eb202f
David Mayerich
added a new ENVI ...
|
122
|
|
6708cc25
heziqi
Ziqi added envi c...
|
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
|
else if(header.interleave == envi_header::BIL){ //if the infile is bil file
if(header.data_type ==envi_header::float32)
return ((bil<float>*)file)->normalize(outfile, band);
else if(header.data_type == envi_header::float64)
return ((bil<double>*)file)->normalize(outfile,band);
else
std::cout<<"ERROR: unidentified data type"<<std::endl;
}
else if(header.interleave == envi_header::BIP){ //if the infile is bip file
if(header.data_type ==envi_header::float32)
return ((bip<float>*)file)->normalize(outfile, band);
else if(header.data_type == envi_header::float64)
return ((bip<double>*)file)->normalize(outfile,band);
else
std::cout<<"ERROR: unidentified data type"<<std::endl;
}
else{
std::cout<<"ERROR: unidentified file type"<<std::endl;
exit(1);
}
|
e933c14e
David Mayerich
cleaned up the code
|
145
|
return false;
|
6708cc25
heziqi
Ziqi added envi c...
|
146
147
|
}
|
cb455f98
David Mayerich
removed old ENVI ...
|
148
149
150
151
|
/// Performs piecewise linear baseline correction of a hyperspectral file/
/// @param outfile is the file name for the baseline corrected output
/// @param w is a list of band labels to serve as baseline points (zero values)
|
6708cc25
heziqi
Ziqi added envi c...
|
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
|
bool baseline(std::string outfile, std::vector<double> w){
if(header.interleave == envi_header::BSQ){ //if the infile is bsq file
if(header.data_type ==envi_header::float32)
return ((bsq<float>*)file)->baseline(outfile, w);
else if(header.data_type == envi_header::float64)
return ((bsq<double>*)file)->baseline(outfile,w);
else{
std::cout<<"ERROR: unidentified data type"<<std::endl;
exit(1);
}
}
else if(header.interleave == envi_header::BIL){ //if the infile is bil file
if(header.data_type ==envi_header::float32)
return ((bil<float>*)file)->baseline(outfile, w);
else if(header.data_type == envi_header::float64)
return ((bil<double>*)file)->baseline(outfile, w);
else{
std::cout<<"ERROR: unidentified data type"<<std::endl;
exit(1);
}
}
else if(header.interleave == envi_header::BIP){ //if the infile is bip file
if(header.data_type ==envi_header::float32)
return ((bip<float>*)file)->baseline(outfile, w);
else if(header.data_type == envi_header::float64)
return ((bip<double>*)file)->baseline(outfile, w);
else{
std::cout<<"ERROR: unidentified data type"<<std::endl;
exit(1);
}
}
else{
std::cout<<"ERROR: unidentified file type"<<std::endl;
exit(1);
}
}
|
cb455f98
David Mayerich
removed old ENVI ...
|
193
194
195
196
|
/// Converts ENVI files between interleave types (BSQ, BIL, and BIP)
/// @param outfile is the file name for the converted output
/// @param interleave is the interleave format for the destination file
|
8a86bd56
David Mayerich
changed rts names...
|
197
|
bool convert(std::string outfile, stim::envi_header::interleaveType interleave){
|
6708cc25
heziqi
Ziqi added envi c...
|
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
|
if(header.interleave == envi_header::BSQ){ //if the infile is bsq file
if(header.data_type ==envi_header::float32){ //if the data type of infile is float
if(interleave == envi_header::BSQ){
std::cout<<"ERROR: is already BSQ file"<<std::endl;
exit(1);
}
else if(interleave == envi_header::BIL) //if the target file is bil file
return ((bsq<float>*)file)->bil(outfile);
else if(interleave == envi_header::BIP) //if the target file is bip file
return ((bsq<float>*)file)->bip(outfile);
}
else if(header.data_type == envi_header::float64){ //if the data type is float
if(interleave == envi_header::BSQ){
std::cout<<"ERROR: is already BSQ file"<<std::endl;
exit(1);
}
else if(interleave == envi_header::BIL)
return ((bsq<double>*)file)->bil(outfile);
else if(interleave == envi_header::BIP)
return ((bsq<double>*)file)->bip(outfile);
}
else{
std::cout<<"ERROR: unidentified data type"<<std::endl;
exit(1);
}
}
else if(header.interleave == envi_header::BIL){
if(header.data_type ==envi_header::float32){ //if the data type of infile is float
if(interleave == envi_header::BIL){
std::cout<<"ERROR: is already BIL file"<<std::endl;
exit(1);
}
else if(interleave == envi_header::BSQ) //if the target file is bsq file
return ((bil<float>*)file)->bsq(outfile);
else if(interleave == envi_header::BIP) //if the target file is bip file
return ((bil<float>*)file)->bip(outfile);
}
else if(header.data_type == envi_header::float64){ //if the data type is float
if(interleave == envi_header::BIL){
std::cout<<"ERROR: is already BIL file"<<std::endl;
exit(1);
}
else if(interleave == envi_header::BSQ)
return ((bil<double>*)file)->bsq(outfile);
else if(interleave == envi_header::BIP)
return ((bil<double>*)file)->bip(outfile);
}
else{
std::cout<<"ERROR: unidentified data type"<<std::endl;
exit(1);
}
}
else if(header.interleave == envi_header::BIP){
if(header.data_type ==envi_header::float32){ //if the data type of infile is float
if(interleave == envi_header::BIP){
std::cout<<"ERROR: is already BIP file"<<std::endl;
exit(1);
}
else if(interleave == envi_header::BIL) //if the target file is bil file
return ((bip<float>*)file)->bil(outfile);
else if(interleave == envi_header::BSQ) //if the target file is bsq file
return ((bip<float>*)file)->bsq(outfile);
}
else if(header.data_type == envi_header::float64){ //if the data type is float
if(interleave == envi_header::BIP){
std::cout<<"ERROR: is already BIP file"<<std::endl;
exit(1);
}
else if(interleave == envi_header::BIL) //if the target file is bil file
return ((bip<double>*)file)->bil(outfile);
else if(interleave == envi_header::BSQ) //if the target file is bsq file
return ((bip<double>*)file)->bsq(outfile);
}
else{
std::cout<<"ERROR: unidentified data type"<<std::endl;
exit(1);
}
}
else{
std::cout<<"ERROR: unidentified interleave type"<<std::endl;
exit(1);
}
|
e933c14e
David Mayerich
cleaned up the code
|
293
|
return false;
|
6708cc25
heziqi
Ziqi added envi c...
|
294
295
296
|
}
|
cb455f98
David Mayerich
removed old ENVI ...
|
297
298
299
300
301
|
/// Builds a mask from a band image and threshold value
/// @param mask_band is the label for the band that will be used to build the mask
/// @param threshold is a value selected such that all band values greater than threshold will have a mask value of 'true'
/// @param p is memory of size X*Y that will store the resulting mask
|
f4c5d71b
David Mayerich
started working w...
|
302
|
bool build_mask(double mask_band, double threshold, unsigned char* p = NULL) {
|
4a6f666c
heziqi
Added mask method
|
303
304
305
|
if(header.interleave == envi_header::BSQ){ //if the infile is bsq file
if(header.data_type ==envi_header::float32)
|
f4c5d71b
David Mayerich
started working w...
|
306
|
return ((bsq<float>*)file)->build_mask(mask_band, threshold, p);
|
4a6f666c
heziqi
Added mask method
|
307
|
else if(header.data_type == envi_header::float64)
|
f4c5d71b
David Mayerich
started working w...
|
308
|
return ((bsq<double>*)file)->build_mask(mask_band, threshold, p);
|
4a6f666c
heziqi
Added mask method
|
309
310
311
312
313
314
|
else
std::cout<<"ERROR: unidentified data type"<<std::endl;
}
else if(header.interleave == envi_header::BIL){ //if the infile is bil file
if(header.data_type ==envi_header::float32)
|
f4c5d71b
David Mayerich
started working w...
|
315
|
return ((bil<float>*)file)->build_mask(mask_band, threshold, p);
|
4a6f666c
heziqi
Added mask method
|
316
|
else if(header.data_type == envi_header::float64)
|
f4c5d71b
David Mayerich
started working w...
|
317
|
return ((bil<double>*)file)->build_mask(mask_band, threshold, p);
|
4a6f666c
heziqi
Added mask method
|
318
319
320
|
else
std::cout<<"ERROR: unidentified data type"<<std::endl;
}
|
cacc3cdc
heziqi
attempt to fix CImg
|
321
|
|
4a6f666c
heziqi
Added mask method
|
322
323
|
else if(header.interleave == envi_header::BIP){ //if the infile is bip file
if(header.data_type ==envi_header::float32)
|
f4c5d71b
David Mayerich
started working w...
|
324
|
return ((bip<float>*)file)->build_mask(mask_band, threshold, p);
|
4a6f666c
heziqi
Added mask method
|
325
|
else if(header.data_type == envi_header::float64)
|
f4c5d71b
David Mayerich
started working w...
|
326
|
return ((bip<double>*)file)->build_mask(mask_band, threshold, p);
|
4a6f666c
heziqi
Added mask method
|
327
328
329
|
else
std::cout<<"ERROR: unidentified data type"<<std::endl;
}
|
bba4f4d9
David Mayerich
minor warning fixes
|
330
331
|
return false;
|
740f8cd2
heziqi
added apply_mask
|
332
333
|
}
|
cb455f98
David Mayerich
removed old ENVI ...
|
334
335
336
337
|
/// Applies a mask to the ENVI file.
/// @param outfile is the name of the resulting masked output file
/// @param p is memory of size X*Y containing the mask (0 = false, all other values are true)
|
e843658b
Brad Deutsch
Previous push did...
|
338
|
bool apply_mask(std::string outfile, unsigned char* p)
|
740f8cd2
heziqi
added apply_mask
|
339
340
|
{
|
e843658b
Brad Deutsch
Previous push did...
|
341
342
|
if (header.interleave == envi_header::BSQ){ //if the infile is bsq file
if (header.data_type == envi_header::float32)
|
740f8cd2
heziqi
added apply_mask
|
343
|
return ((bsq<float>*)file)->apply_mask(outfile, p);
|
e843658b
Brad Deutsch
Previous push did...
|
344
|
else if (header.data_type == envi_header::float64)
|
740f8cd2
heziqi
added apply_mask
|
345
346
|
return ((bsq<double>*)file)->apply_mask(outfile, p);
else
|
e843658b
Brad Deutsch
Previous push did...
|
347
|
std::cout << "ERROR: unidentified data type" << std::endl;
|
740f8cd2
heziqi
added apply_mask
|
348
349
|
}
|
e843658b
Brad Deutsch
Previous push did...
|
350
351
|
else if (header.interleave == envi_header::BIL){ //if the infile is bil file
if (header.data_type == envi_header::float32)
|
740f8cd2
heziqi
added apply_mask
|
352
|
return ((bil<float>*)file)->apply_mask(outfile, p);
|
e843658b
Brad Deutsch
Previous push did...
|
353
|
else if (header.data_type == envi_header::float64)
|
740f8cd2
heziqi
added apply_mask
|
354
355
|
return ((bil<double>*)file)->apply_mask(outfile, p);
else
|
e843658b
Brad Deutsch
Previous push did...
|
356
|
std::cout << "ERROR: unidentified data type" << std::endl;
|
740f8cd2
heziqi
added apply_mask
|
357
358
|
}
|
e843658b
Brad Deutsch
Previous push did...
|
359
360
|
else if (header.interleave == envi_header::BIP){ //if the infile is bip file
if (header.data_type == envi_header::float32)
|
740f8cd2
heziqi
added apply_mask
|
361
|
return ((bip<float>*)file)->apply_mask(outfile, p);
|
e843658b
Brad Deutsch
Previous push did...
|
362
|
else if (header.data_type == envi_header::float64)
|
740f8cd2
heziqi
added apply_mask
|
363
364
|
return ((bip<double>*)file)->apply_mask(outfile, p);
else
|
e843658b
Brad Deutsch
Previous push did...
|
365
|
std::cout << "ERROR: unidentified data type" << std::endl;
|
740f8cd2
heziqi
added apply_mask
|
366
|
}
|
4a6f666c
heziqi
Added mask method
|
367
368
|
else{
|
e843658b
Brad Deutsch
Previous push did...
|
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
|
std::cout << "ERROR: unidentified file type" << std::endl;
exit(1);
}
return false;
}
/// sift-mask saves in an array only those spectra corresponding to nonzero values of the mask.
bool sift_mask(std::string outfile, unsigned char* p)
{
if (header.interleave == envi_header::BSQ){ //if the infile is bsq file
if (header.data_type == envi_header::float32)
return ((bsq<float>*)file)->sift_mask(outfile, p);
else if (header.data_type == envi_header::float64)
return ((bsq<double>*)file)->sift_mask(outfile, p);
else
std::cout << "ERROR: unidentified data type" << std::endl;
}
else if (header.interleave == envi_header::BIL){ //if the infile is bil file
if (header.data_type == envi_header::float32)
return ((bil<float>*)file)->sift_mask(outfile, p);
else if (header.data_type == envi_header::float64)
return ((bil<double>*)file)->sift_mask(outfile, p);
else
std::cout << "ERROR: unidentified data type" << std::endl;
}
else if (header.interleave == envi_header::BIP){ //if the infile is bip file
if (header.data_type == envi_header::float32)
return ((bip<float>*)file)->sift_mask(outfile, p);
else if (header.data_type == envi_header::float64)
return ((bip<double>*)file)->sift_mask(outfile, p);
else
std::cout << "ERROR: unidentified data type" << std::endl;
}
else{
std::cout << "ERROR: unidentified file type" << std::endl;
|
4a6f666c
heziqi
Added mask method
|
408
409
410
|
exit(1);
}
return false;
|
cacc3cdc
heziqi
attempt to fix CImg
|
411
412
|
}
|
cb455f98
David Mayerich
removed old ENVI ...
|
413
414
415
416
417
418
419
420
421
|
/// Compute the ratio of two baseline-corrected peaks. The result is stored in a pre-allocated array.
/// @param lb1 is the label value for the left baseline point for the first peak (numerator)
/// @param rb1 is the label value for the right baseline point for the first peak (numerator)
/// @param pos1 is the label value for the first peak (numerator) position
/// @param lb2 is the label value for the left baseline point for the second peak (denominator)
/// @param rb2 is the label value for the right baseline point for the second peak (denominator)
/// @param pos2 is the label value for the second peak (denominator) position
/// @param result is a pointer to a pre-allocated array at least X * Y * sizeof(T) in size
|
70407ea9
heziqi
Ziqi completed he...
|
422
|
bool ph_to_ph(double lb1, double rb1, double pos1, double lb2, double rb2, double pos2, void * result){
|
20c212c0
heziqi
Ziqi added functi...
|
423
424
|
if(header.interleave == envi_header::BSQ){ //if the infile is bsq file
if(header.data_type ==envi_header::float32)
|
70407ea9
heziqi
Ziqi completed he...
|
425
|
return ((bsq<float>*)file)->ph_to_ph(lb1, rb1, pos1, lb2, rb2, pos2, (float*)result);
|
20c212c0
heziqi
Ziqi added functi...
|
426
|
else if(header.data_type == envi_header::float64)
|
70407ea9
heziqi
Ziqi completed he...
|
427
|
return ((bsq<double>*)file)->ph_to_ph(lb1, rb1, pos1, lb2, rb2, pos2, (double*)result);
|
20c212c0
heziqi
Ziqi added functi...
|
428
429
430
431
432
433
|
else
std::cout<<"ERROR: unidentified data type"<<std::endl;
}
else if(header.interleave == envi_header::BIL){ //if the infile is bil file
if(header.data_type ==envi_header::float32)
|
70407ea9
heziqi
Ziqi completed he...
|
434
|
return ((bil<float>*)file)->ph_to_ph(lb1, rb1, pos1, lb2, rb2, pos2, (float*)result);
|
20c212c0
heziqi
Ziqi added functi...
|
435
|
else if(header.data_type == envi_header::float64)
|
70407ea9
heziqi
Ziqi completed he...
|
436
|
return ((bil<double>*)file)->ph_to_ph(lb1, rb1, pos1, lb2, rb2, pos2, (double*)result);
|
20c212c0
heziqi
Ziqi added functi...
|
437
438
439
440
441
442
|
else
std::cout<<"ERROR: unidentified data type"<<std::endl;
}
else if(header.interleave == envi_header::BIP){ //if the infile is bip file
if(header.data_type ==envi_header::float32)
|
70407ea9
heziqi
Ziqi completed he...
|
443
|
return ((bip<float>*)file)->ph_to_ph(lb1, rb1, pos1, lb2, rb2, pos2, (float*)result);
|
20c212c0
heziqi
Ziqi added functi...
|
444
|
else if(header.data_type == envi_header::float64)
|
70407ea9
heziqi
Ziqi completed he...
|
445
446
447
448
449
450
451
452
453
454
455
456
|
return ((bip<double>*)file)->ph_to_ph(lb1, rb1, pos1, lb2, rb2, pos2, (double*)result);
else
std::cout<<"ERROR: unidentified data type"<<std::endl;
}
else{
std::cout<<"ERROR: unidentified file type"<<std::endl;
exit(1);
}
return false;
}
|
cb455f98
David Mayerich
removed old ENVI ...
|
457
458
459
460
461
462
463
464
465
|
/// Compute the ratio between a peak area and peak height.
/// @param lb1 is the label value for the left baseline point for the first peak (numerator)
/// @param rb1 is the label value for the right baseline point for the first peak (numerator)
/// @param pos1 is the label value for the first peak (numerator) position
/// @param lb2 is the label value for the left baseline point for the second peak (denominator)
/// @param rb2 is the label value for the right baseline point for the second peak (denominator)
/// @param pos2 is the label value for the second peak (denominator) position
/// @param result is a pointer to a pre-allocated array at least X * Y * sizeof(T) in size
|
70407ea9
heziqi
Ziqi completed he...
|
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
|
bool pa_to_ph(double lb1, double rb1, double lab1, double rab1, double lb2, double rb2, double pos, void * result){
if(header.interleave == envi_header::BSQ){ //if the infile is bsq file
if(header.data_type ==envi_header::float32)
return ((bsq<float>*)file)->pa_to_ph(lb1, rb1, lab1, rab1, lb2, rb2, pos, (float*)result);
else if(header.data_type == envi_header::float64)
return ((bsq<double>*)file)->pa_to_ph(lb1, rb1, lab1, rab1, lb2, rb2, pos, (double*)result);
else
std::cout<<"ERROR: unidentified data type"<<std::endl;
}
else if(header.interleave == envi_header::BIL){ //if the infile is bil file
if(header.data_type ==envi_header::float32)
return ((bil<float>*)file)->pa_to_ph(lb1, rb1, lab1, rab1, lb2, rb2, pos, (float*)result);
else if(header.data_type == envi_header::float64)
return ((bil<double>*)file)->pa_to_ph(lb1, rb1, lab1, rab1, lb2, rb2, pos, (double*)result);
else
std::cout<<"ERROR: unidentified data type"<<std::endl;
}
else if(header.interleave == envi_header::BIP){ //if the infile is bip file
if(header.data_type ==envi_header::float32)
return ((bip<float>*)file)->pa_to_ph(lb1, rb1, lab1, rab1, lb2, rb2, pos, (float*)result);
else if(header.data_type == envi_header::float64)
return ((bip<double>*)file)->pa_to_ph(lb1, rb1, lab1, rab1, lb2, rb2, pos, (double*)result);
else
std::cout<<"ERROR: unidentified data type"<<std::endl;
}
else{
std::cout<<"ERROR: unidentified file type"<<std::endl;
exit(1);
}
return false;
}
|
cb455f98
David Mayerich
removed old ENVI ...
|
501
502
503
504
505
506
507
508
509
510
511
|
/// Compute the ratio between two peak areas.
/// @param lb1 is the label value for the left baseline point for the first peak (numerator)
/// @param rb1 is the label value for the right baseline point for the first peak (numerator)
/// @param lab1 is the label value for the left bound (start of the integration) of the first peak (numerator)
/// @param rab1 is the label value for the right bound (end of the integration) of the first peak (numerator)
/// @param lb2 is the label value for the left baseline point for the second peak (denominator)
/// @param rb2 is the label value for the right baseline point for the second peak (denominator)
/// @param lab2 is the label value for the left bound (start of the integration) of the second peak (denominator)
/// @param rab2 is the label value for the right bound (end of the integration) of the second peak (denominator)
/// @param result is a pointer to a pre-allocated array at least X * Y * sizeof(T) in size
|
70407ea9
heziqi
Ziqi completed he...
|
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
|
bool pa_to_pa(double lb1, double rb1, double lab1, double rab1,
double lb2, double rb2, double lab2, double rab2, void* result){
if(header.interleave == envi_header::BSQ){ //if the infile is bsq file
if(header.data_type ==envi_header::float32)
return ((bsq<float>*)file)->pa_to_pa(lb1, rb1, lab1, rab1, lb2, rb2, lab2, rab2, (float*)result);
else if(header.data_type == envi_header::float64)
return ((bsq<double>*)file)->pa_to_pa(lb1, rb1, lab1, rab1, lb2, rb2, lab2, rab2, (double*)result);
else
std::cout<<"ERROR: unidentified data type"<<std::endl;
}
else if(header.interleave == envi_header::BIL){ //if the infile is bil file
if(header.data_type ==envi_header::float32)
return ((bil<float>*)file)->pa_to_pa(lb1, rb1, lab1, rab1, lb2, rb2, lab2, rab2, (float*)result);
else if(header.data_type == envi_header::float64)
return ((bil<double>*)file)->pa_to_pa(lb1, rb1, lab1, rab1, lb2, rb2, lab2, rab2, (double*)result);
else
std::cout<<"ERROR: unidentified data type"<<std::endl;
}
else if(header.interleave == envi_header::BIP){ //if the infile is bip file
if(header.data_type ==envi_header::float32)
return ((bip<float>*)file)->pa_to_pa(lb1, rb1, lab1, rab1, lb2, rb2, lab2, rab2, (float*)result);
else if(header.data_type == envi_header::float64)
return ((bip<double>*)file)->pa_to_pa(lb1, rb1, lab1, rab1, lb2, rb2, lab2, rab2, (double*)result);
|
20c212c0
heziqi
Ziqi added functi...
|
537
538
539
540
541
542
543
544
545
546
547
|
else
std::cout<<"ERROR: unidentified data type"<<std::endl;
}
else{
std::cout<<"ERROR: unidentified file type"<<std::endl;
exit(1);
}
return false;
}
|
cb455f98
David Mayerich
removed old ENVI ...
|
548
549
550
551
552
553
554
|
/// Compute the centroid of a baseline corrected peak.
/// @param lb is the label value for the left baseline point
/// @param rb is the label value for the right baseline point
/// @param lab is the label for the start of the peak
/// @param rab is the label for the end of the peak
/// @param result is a pointer to a pre-allocated array at least X * Y * sizeof(T) in size
|
517876d6
heziqi
metrics finished ...
|
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
|
bool cpoint(double lb1, double rb1, double lab1, double rab1, void* result){
if(header.interleave == envi_header::BSQ){ //if the infile is bsq file
if(header.data_type ==envi_header::float32)
return ((bsq<float>*)file)->cpoint(lb1, rb1, lab1, rab1, (float*)result);
else if(header.data_type == envi_header::float64)
return ((bsq<double>*)file)->cpoint(lb1, rb1, lab1, rab1, (double*)result);
else
std::cout<<"ERROR: unidentified data type"<<std::endl;
}
else if(header.interleave == envi_header::BIL){ //if the infile is bil file
if(header.data_type ==envi_header::float32)
return ((bil<float>*)file)->cpoint(lb1, rb1, lab1, rab1, (float*)result);
else if(header.data_type == envi_header::float64)
return ((bil<double>*)file)->cpoint(lb1, rb1, lab1, rab1, (double*)result);
else
std::cout<<"ERROR: unidentified data type"<<std::endl;
}
else if(header.interleave == envi_header::BIP){ //if the infile is bip file
if(header.data_type ==envi_header::float32)
return ((bip<float>*)file)->cpoint(lb1, rb1, lab1, rab1,(float*)result);
else if(header.data_type == envi_header::float64)
return ((bip<double>*)file)->cpoint(lb1, rb1, lab1, rab1, (double*)result);
else
std::cout<<"ERROR: unidentified data type"<<std::endl;
}
else{
std::cout<<"ERROR: unidentified file type"<<std::endl;
exit(1);
}
return false;
}
|
cb455f98
David Mayerich
removed old ENVI ...
|
590
|
/// Closes the ENVI file.
|
6708cc25
heziqi
Ziqi added envi c...
|
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
|
bool close(){
if(header.interleave == envi_header::BSQ){
if(header.data_type ==envi_header::float32)
return ((bsq<float>*)file)->close();
else if(header.data_type == envi_header::float64)
return ((bsq<double>*)file)->close();
else{
std::cout<<"ERROR: unidentified data type"<<std::endl;
exit(1);
}
}
else if(header.interleave == envi_header::BIL){
if(header.data_type ==envi_header::float32)
return ((bil<float>*)file)->close();
else if(header.data_type == envi_header::float64)
return ((bil<double>*)file)->close();
else{
std::cout<<"ERROR: unidentified data type"<<std::endl;
exit(1);
}
}
else if(header.interleave == envi_header::BIP){
if(header.data_type ==envi_header::float32)
return ((bip<float>*)file)->close();
else if(header.data_type == envi_header::float64)
return ((bip<double>*)file)->close();
else{
std::cout<<"ERROR: unidentified data type"<<std::endl;
exit(1);
}
}
|
e933c14e
David Mayerich
cleaned up the code
|
624
|
return false;
|
e8eb202f
David Mayerich
added a new ENVI ...
|
625
|
}
|
cb455f98
David Mayerich
removed old ENVI ...
|
626
627
628
629
630
|
/// Retrieve a single pixel and stores it in pre-allocated memory.
/// @param p is a pointer to pre-allocated memory at least sizeof(T) in size.
/// @param n is an integer index to the pixel using linear array indexing.
|
bfe9c6db
heziqi
added feature_mat...
|
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
|
bool pixel(void * p, unsigned n){
if(header.interleave == envi_header::BSQ){
if(header.data_type ==envi_header::float32)
return ((bsq<float>*)file)->pixel((float*)p, n);
else if(header.data_type == envi_header::float64)
return ((bsq<double>*)file)->pixel((double*)p, n);
else{
std::cout<<"ERROR: unidentified data type"<<std::endl;
exit(1);
}
}
else if(header.interleave == envi_header::BIL){
if(header.data_type ==envi_header::float32)
return ((bil<float>*)file)->pixel((float*)p, n);
else if(header.data_type == envi_header::float64)
return ((bil<double>*)file)->pixel((double*)p, n);
else{
std::cout<<"ERROR: unidentified data type"<<std::endl;
exit(1);
}
}
else if(header.interleave == envi_header::BIP){
if(header.data_type ==envi_header::float32)
return ((bip<float>*)file)->pixel((float*)p, n);
else if(header.data_type == envi_header::float64)
return ((bip<double>*)file)->pixel((double*)p, n);
else{
std::cout<<"ERROR: unidentified data type"<<std::endl;
exit(1);
}
}
return false;
}
|
e8eb202f
David Mayerich
added a new ENVI ...
|
664
|
|
cb455f98
David Mayerich
removed old ENVI ...
|
665
|
/// Saves a header file describing the current ENVI file parameters.
|
e8eb202f
David Mayerich
added a new ENVI ...
|
666
667
668
669
670
671
672
673
|
bool save_header(std::string filename){
//save the header file here
header.save(filename);
return true;
}
|
cb455f98
David Mayerich
removed old ENVI ...
|
674
675
676
677
|
/// Retrieve a single band (by numerical label) and stores it in pre-allocated memory.
/// @param p is a pointer to an allocated region of memory at least X * Y * sizeof(T) in size.
/// @param wavelength is a floating point value (usually a wavelength in spectral data) used as a label for the band to be copied.
|
d1d8ef91
David Mayerich
added band readin...
|
678
679
680
681
682
|
bool band(void* ptr, double wavelength){
if(header.interleave == envi_header::BSQ){ //if the infile is bsq file
if(header.data_type ==envi_header::float32)
return ((bsq<float>*)file)->band((float*)ptr, wavelength);
|
081f2c9f
heziqi
made bip bil file...
|
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
|
else if (header.data_type == envi_header::float64)
return ((bsq<double>*)file)->band((double*)ptr, wavelength);
else{
std::cout << "ERROR: unidentified data type" << std::endl;
exit(1);
}
}
else if (header.interleave == envi_header::BIL){
if (header.data_type == envi_header::float32)
return ((bil<float>*)file)->band((float*)ptr, wavelength);
else if (header.data_type == envi_header::float64)
return ((bil<double>*)file)->band((double*)ptr, wavelength);
else{
std::cout << "ERROR: unidentified data type" << std::endl;
exit(1);
}
}
else if (header.interleave == envi_header::BIP){
if (header.data_type == envi_header::float32)
return ((bip<float>*)file)->band((float*)ptr, wavelength);
else if (header.data_type == envi_header::float64)
return ((bip<double>*)file)->band((double*)ptr, wavelength);
else{
std::cout << "ERROR: unidentified data type" << std::endl;
exit(1);
}
|
d1d8ef91
David Mayerich
added band readin...
|
709
|
}
|
ee4dea28
David Mayerich
fixed errors in c...
|
710
|
return false;
|
1582ce07
David Mayerich
added band_index(...
|
711
712
|
}
|
cb455f98
David Mayerich
removed old ENVI ...
|
713
714
715
716
|
/// Retrieve a single band (based on index) and stores it in pre-allocated memory.
/// @param p is a pointer to an allocated region of memory at least X * Y * sizeof(T) in size.
/// @param page <= B is the integer number of the band to be copied.
|
1582ce07
David Mayerich
added band_index(...
|
717
|
bool band_index(void* ptr, unsigned int b){
|
081f2c9f
heziqi
made bip bil file...
|
718
719
|
if (header.interleave == envi_header::BSQ){ //if the infile is bsq file
if (header.data_type == envi_header::float32)
|
1582ce07
David Mayerich
added band_index(...
|
720
|
return ((bsq<float>*)file)->band_index((float*)ptr, b);
|
081f2c9f
heziqi
made bip bil file...
|
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
|
else if (header.data_type == envi_header::float64)
return ((bsq<double>*)file)->band_index((double*)ptr, b);
else{
std::cout << "ERROR: unidentified data type" << std::endl;
exit(1);
}
}
else if (header.interleave == envi_header::BIL){
if (header.data_type == envi_header::float32)
return ((bil<float>*)file)->band_index((float*)ptr, b);
else if (header.data_type == envi_header::float64)
return ((bil<double>*)file)->band_index((double*)ptr, b);
else{
std::cout << "ERROR: unidentified data type" << std::endl;
exit(1);
}
}
else if (header.interleave == envi_header::BIP){
if (header.data_type == envi_header::float32)
return ((bip<float>*)file)->band_index((float*)ptr, b);
else if (header.data_type == envi_header::float64)
return ((bip<double>*)file)->band_index((double*)ptr, b);
else{
std::cout << "ERROR: unidentified data type" << std::endl;
exit(1);
}
|
1582ce07
David Mayerich
added band_index(...
|
747
748
|
}
return false;
|
d1d8ef91
David Mayerich
added band readin...
|
749
|
}
|
9f489bb3
heziqi
Added load_mask a...
|
750
|
|
cb455f98
David Mayerich
removed old ENVI ...
|
751
752
753
754
|
/// Helper function that loads a mask into memory given a filename.
/// @param mask is a pointer to pre-allocated memory of size X*Y
/// @param maskname is the file name for the image that will serve as the mask
|
bfe9c6db
heziqi
added feature_mat...
|
755
756
|
bool load_mask(unsigned char * mask, std::string maskname){
//open the mask file
|
7b3948ab
David Mayerich
added support for...
|
757
|
stim::image<unsigned char> mask_image(maskname);
|
32504c2c
David Mayerich
fixed some functi...
|
758
|
mask_image.data_noninterleaved(mask);
|
bfe9c6db
heziqi
added feature_mat...
|
759
|
//save mask file into memory
|
32504c2c
David Mayerich
fixed some functi...
|
760
|
//memcpy(mask, mask_image.data_noninterleaved(), mask_image.size());
|
7b3948ab
David Mayerich
added support for...
|
761
|
//mask_image.clear();
|
bfe9c6db
heziqi
added feature_mat...
|
762
|
return true;
|
9f489bb3
heziqi
Added load_mask a...
|
763
|
}
|
d1d8ef91
David Mayerich
added band readin...
|
764
|
|
bfe9c6db
heziqi
added feature_mat...
|
765
|
//p:start positon; N: number of pixels saved in X;
|
9f489bb3
heziqi
Added load_mask a...
|
766
|
bool feature_matrix(void * X, unsigned char * mask, unsigned start, unsigned N)
|
bfe9c6db
heziqi
added feature_mat...
|
767
|
{
|
4b37859f
heziqi
added predict
|
768
769
|
//save pixels in X as floating numbers: float * p
float * p = (float*)malloc(header.bands * sizeof(float)); //save pixel information
|
c9fd97f0
David Mayerich
edits for classif...
|
770
|
unsigned pixels = header.samples * header.lines; //calculate pixel numbers in a band
|
bfe9c6db
heziqi
added feature_mat...
|
771
772
773
|
unsigned count = 0; //for counting use
unsigned j = 0; //memory the pointer location in X
|
c9fd97f0
David Mayerich
edits for classif...
|
774
775
776
777
778
779
780
781
782
783
784
|
//create two indices into the mask (mask index and pixel index)
unsigned mi = 0; //valid pixel index
unsigned pi = 0; //actual pixel in the mask
//find the actual pixel index for the mask index "start"
while(mi < start){
if(mask[pi])
mi++;
pi++;
}
|
c9fd97f0
David Mayerich
edits for classif...
|
785
786
|
for(unsigned i = pi; i < pixels; i++){
|
bfe9c6db
heziqi
added feature_mat...
|
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
|
if(mask[i] != 0){
pixel(p, i);
//copy p to X
for(unsigned k = 0; k < header.bands; k++){
((float *)X)[j] = p[k];
j++;
}
count++;
if(count == N)
break;
}
else
continue;
}
if(count < N){
std::cout << "number of valid pixels in the mask : " << count <<"is less than N: "<< N;
exit(1);
}
|
b0fee590
heziqi
convert long int ...
|
805
|
free(p);
|
bfe9c6db
heziqi
added feature_mat...
|
806
807
|
return true;
}
|
e8eb202f
David Mayerich
added a new ENVI ...
|
808
|
|
cb455f98
David Mayerich
removed old ENVI ...
|
809
810
811
812
|
/// Calculate the mean value for all masked (or valid) pixels in a band and returns the average spectrum
/// @param p is a pointer to pre-allocated memory of size [B * sizeof(T)] that stores the mean spectrum
/// @param mask is a pointer to memory of size [X * Y] that stores the mask value at each pixel location
|
a43c4fe1
heziqi
Added crop in env...
|
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
|
bool avg_band(void * p, unsigned char* mask){
if (header.interleave == envi_header::BSQ){
if (header.data_type == envi_header::float32)
return ((bsq<float>*)file)->avg_band((float*)p, mask);
else if (header.data_type == envi_header::float64)
return ((bsq<double>*)file)->avg_band((double*)p, mask);
else{
std::cout << "ERROR: unidentified data type" << std::endl;
exit(1);
}
}
else if (header.interleave == envi_header::BIL){
if (header.data_type == envi_header::float32)
return ((bil<float>*)file)->avg_band((float*)p, mask);
else if (header.data_type == envi_header::float64)
return ((bil<double>*)file)->avg_band((double*)p, mask);
else{
std::cout << "ERROR: unidentified data type" << std::endl;
exit(1);
}
}
else if (header.interleave == envi_header::BIP){
if (header.data_type == envi_header::float32)
return ((bip<float>*)file)->avg_band((float*)p, mask);
else if (header.data_type == envi_header::float64)
return ((bip<double>*)file)->avg_band((double*)p, mask);
else{
std::cout << "ERROR: unidentified data type" << std::endl;
exit(1);
}
}
return false;
}
|
e8eb202f
David Mayerich
added a new ENVI ...
|
846
|
|
cb455f98
David Mayerich
removed old ENVI ...
|
847
848
849
850
851
|
/// Calculate the covariance matrix for all masked pixels in the image.
/// @param co is a pointer to pre-allocated memory of size [B * B] that stores the resulting covariance matrix
/// @param avg is a pointer to memory of size B that stores the average spectrum
/// @param mask is a pointer to memory of size [X * Y] that stores the mask value at each pixel location
|
a43c4fe1
heziqi
Added crop in env...
|
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
|
bool co_matrix(void* co, void* avg, unsigned char* mask){
if (header.interleave == envi_header::BSQ){
if (header.data_type == envi_header::float32)
return ((bsq<float>*)file)->co_matrix((float*)co, (float*)avg, mask);
else if (header.data_type == envi_header::float64)
return ((bsq<double>*)file)->co_matrix((double*)co, (double*)avg, mask);
else{
std::cout << "ERROR: unidentified data type" << std::endl;
exit(1);
}
}
else if (header.interleave == envi_header::BIL){
if (header.data_type == envi_header::float32)
return ((bil<float>*)file)->co_matrix((float*)co, (float*)avg, mask);
else if (header.data_type == envi_header::float64)
return ((bil<double>*)file)->co_matrix((double*)co, (double*)avg, mask);
else{
std::cout << "ERROR: unidentified data type" << std::endl;
exit(1);
}
}
else if (header.interleave == envi_header::BIP){
if (header.data_type == envi_header::float32)
return ((bip<float>*)file)->co_matrix((float*)co, (float*)avg, mask);
else if (header.data_type == envi_header::float64)
return ((bip<double>*)file)->co_matrix((double*)co, (double*)avg, mask);
else{
std::cout << "ERROR: unidentified data type" << std::endl;
exit(1);
}
}
return false;
}
|
0df38ff3
heziqi
fixed head detached
|
885
|
|
e8eb202f
David Mayerich
added a new ENVI ...
|
886
|
|
cb455f98
David Mayerich
removed old ENVI ...
|
887
888
889
890
891
892
893
|
/// Crop a region of the image and save it to a new file.
/// @param outfile is the file name for the new cropped image
/// @param x0 is the lower-left x pixel coordinate to be included in the cropped image
/// @param y0 is the lower-left y pixel coordinate to be included in the cropped image
/// @param x1 is the upper-right x pixel coordinate to be included in the cropped image
/// @param y1 is the upper-right y pixel coordinate to be included in the cropped image
|
a43c4fe1
heziqi
Added crop in env...
|
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
|
bool crop(std::string outfile,unsigned x0, unsigned y0, unsigned x1, unsigned y1){
if (header.interleave == envi_header::BSQ){
if (header.data_type == envi_header::float32)
return ((bsq<float>*)file)->crop(outfile, x0, y0, x1, y1);
else if (header.data_type == envi_header::float64)
return ((bsq<double>*)file)->crop(outfile, x0, y0, x1, y1);
else{
std::cout << "ERROR: unidentified data type" << std::endl;
exit(1);
}
}
else if (header.interleave == envi_header::BIL){
if (header.data_type == envi_header::float32)
return ((bil<float>*)file)->crop(outfile, x0, y0, x1, y1);
else if (header.data_type == envi_header::float64)
return ((bil<double>*)file)->crop(outfile, x0, y0, x1, y1);
else{
std::cout << "ERROR: unidentified data type" << std::endl;
exit(1);
}
}
else if (header.interleave == envi_header::BIP){
if (header.data_type == envi_header::float32)
return ((bip<float>*)file)->crop(outfile, x0, y0, x1, y1);
else if (header.data_type == envi_header::float64)
return ((bip<double>*)file)->crop(outfile, x0, y0, x1, y1);
else{
std::cout << "ERROR: unidentified data type" << std::endl;
exit(1);
}
}
return false;
}
|
0df38ff3
heziqi
fixed head detached
|
928
|
|
e8eb202f
David Mayerich
added a new ENVI ...
|
929
930
931
932
933
|
};
} //end namespace rts
#endif
|