Commit cb455f987f19e090f47b5d856b5863642807c97e
1 parent
f6aa45e7
removed old ENVI files
Showing
7 changed files
with
103 additions
and
469 deletions
Show diff stats
envi/EnviClose.h deleted
1 | -#ifndef ENVICLOSE_H | |
2 | -#define ENVICLOSE_H | |
3 | - | |
4 | - | |
5 | -#include <fstream> | |
6 | -#include <stdio.h> | |
7 | -#include "EnviHeader.h" | |
8 | -#include "EnviFid.h" | |
9 | -#include "EnviOpen.h" | |
10 | - | |
11 | -// this is to close all the opened files and to create a header file for the written files | |
12 | - | |
13 | -static void EnviClose(EnviFidClass &fid, int dimX=0) | |
14 | -{ | |
15 | - | |
16 | - float* zeroPtr = (float*) malloc(sizeof(float) * fid.header.nF); | |
17 | - memset(zeroPtr, 0, sizeof(float) * fid.header.nF); | |
18 | - | |
19 | - if(fid.mode=="r") | |
20 | - { | |
21 | - fclose(fid.file); | |
22 | - } | |
23 | - | |
24 | - else | |
25 | - { | |
26 | - int totalPixels = fid.header.sX; | |
27 | - int dimY = totalPixels/dimX; | |
28 | - | |
29 | - if(totalPixels % dimX > 0) | |
30 | - { | |
31 | - dimY++; | |
32 | - | |
33 | - int padding = dimY*dimX-totalPixels; | |
34 | - | |
35 | - for(int p=0; p < padding; p++) | |
36 | - fwrite(zeroPtr, sizeof(float), fid.header.nF, fid.file); | |
37 | - } | |
38 | - | |
39 | - //write the calculated values to the header object | |
40 | - fid.header.sX = dimX; | |
41 | - fid.header.sY = dimY; | |
42 | - | |
43 | - | |
44 | - //write the header file to disk | |
45 | - //TODO | |
46 | - | |
47 | - | |
48 | - //close the binary file | |
49 | - fclose(fid.file); | |
50 | - | |
51 | - } | |
52 | - | |
53 | - | |
54 | - | |
55 | - | |
56 | -} | |
57 | -#endif | |
58 | - |
envi/EnviFid.h deleted
1 | -#ifndef ENVIFID_H | |
2 | -#define ENVIFID_H | |
3 | - | |
4 | -#include <string> | |
5 | -#include <iostream> | |
6 | -#include <fstream> | |
7 | -#include <ctime> | |
8 | -#include <sstream> | |
9 | -#include "EnviHeader.h" | |
10 | -using namespace std; | |
11 | - | |
12 | -class EnviFidClass | |
13 | -{ | |
14 | -public: | |
15 | - //binary file name | |
16 | - string fileName; | |
17 | - | |
18 | - //header structure | |
19 | - EnviHeaderClass header; | |
20 | - | |
21 | - //valid flag (is the current file valid) | |
22 | - int isValid; | |
23 | - | |
24 | - //file mask (NULL if the whole file is to be read) | |
25 | - char* mask; | |
26 | - | |
27 | - //current position (in pixels) in the file | |
28 | - int filePos; | |
29 | - | |
30 | - //read/write mode ("r" or "w") | |
31 | - string mode; | |
32 | - | |
33 | - //create a variable to store a pointer to the binary file | |
34 | - FILE * file; | |
35 | - | |
36 | - //constructor, set default values | |
37 | - EnviFidClass() | |
38 | - { | |
39 | - isValid = 0; | |
40 | - filePos = 0; | |
41 | - } | |
42 | - | |
43 | - | |
44 | -}; | |
45 | - | |
46 | - | |
47 | -#endif |
envi/EnviHeader.h deleted
1 | -#ifndef ENVIHEADER_H | |
2 | -#define ENVIHEADER_H | |
3 | -#include <string> | |
4 | -#include <iostream> | |
5 | -#include <fstream> | |
6 | -#include <ctime> | |
7 | -#include <sstream> | |
8 | -using namespace std; | |
9 | - | |
10 | -enum InterleaveType {bip, bil, bsq}; | |
11 | -class EnviHeaderClass //"EnviheaderClass" will be used to store data into variables sX, sY, etc. | |
12 | -{ | |
13 | -public: | |
14 | - unsigned int sX; //samples = "sX" | |
15 | - unsigned int sY; //lines = "sY" | |
16 | - unsigned int nF; //bands = "nF" | |
17 | - unsigned int headersize; //header offset = "headersize" | |
18 | - unsigned int datatype; //data type = "datatype" | |
19 | - InterleaveType type; | |
20 | - string units; //wavelength units = "units" (Usully in Wavenumber or Wavelength) | |
21 | - int LoadHeader(string filename) | |
22 | - { | |
23 | - ifstream inFile; | |
24 | - //Load the header file in the same directory, for future note, might want to modify code to either "cin" the file name of have a feature in the GUI which take into account different fileneames | |
25 | - inFile.open (filename.c_str()); | |
26 | - | |
27 | - //If or not there is a file | |
28 | - if (!inFile) | |
29 | - { | |
30 | - cout<<"Error"<<endl; | |
31 | - return 1; | |
32 | - } | |
33 | - | |
34 | - string line; | |
35 | - getline(inFile,line); | |
36 | - | |
37 | - //If the 1st line of text file does not read ENVI, spit out an error. | |
38 | - if (line.compare("ENVI")) | |
39 | - { | |
40 | - cout<<"Error, not an ENVI file"<<endl; | |
41 | - return 1; | |
42 | - } | |
43 | - | |
44 | - while(inFile) //Loops through entire file | |
45 | - { | |
46 | - getline(inFile,line); | |
47 | - if(line.find("samples")==0) | |
48 | - { | |
49 | - sX=getNumber(line); //Calls getNumber function for "samples", stores in header.sX | |
50 | - } | |
51 | - if(line.find("lines")==0) | |
52 | - { | |
53 | - sY=getNumber(line); //Calls getNumber function for "lines", stores in header.sY | |
54 | - } | |
55 | - if(line.find("bands")==0) | |
56 | - { | |
57 | - nF=getNumber(line); //Calls getNumber function for "bands", stores in header.nF | |
58 | - } | |
59 | - if(line.find("header offset")==0) | |
60 | - { | |
61 | - headersize=getNumber(line); //Calls getNumber function for "header offset", stores in header.headersize | |
62 | - } | |
63 | - if(line.find("data type")==0) | |
64 | - { | |
65 | - datatype=getNumber(line); //Calls getNumber function for "data type", stores in header.datatype | |
66 | - } | |
67 | - | |
68 | - line.find("interleave"); | |
69 | - if(line.find("interleave")==0) | |
70 | - { | |
71 | - string typeStr; | |
72 | - typeStr=getString(line); | |
73 | - if (typeStr.find("bip")==0) | |
74 | - type=bip; | |
75 | - else if(typeStr.find("bsq")==0) | |
76 | - type=bsq; | |
77 | - else if(typeStr.find("bil")==0) | |
78 | - type=bil; | |
79 | - else | |
80 | - { | |
81 | - //throw an error and exit | |
82 | - cout<<"Type not recognized"<<endl; | |
83 | - return 1; | |
84 | - } | |
85 | - | |
86 | - } | |
87 | - if(line.find("wavelength units")==0) | |
88 | - { | |
89 | - //Calls getString function for "wavelength units", stores in header.units | |
90 | - units=getString(line); | |
91 | - } | |
92 | - } | |
93 | - return 0; | |
94 | - } | |
95 | - | |
96 | - | |
97 | -private: | |
98 | - //retrieves a numerical parameter from a line of text | |
99 | - int getNumber(string line) | |
100 | - { | |
101 | - int result=0; | |
102 | - int position; | |
103 | - position=line.find("="); //Finds the position of the equal sign | |
104 | - | |
105 | - string numStr; //Creates a string for storing data called "numStr" | |
106 | - numStr=line.substr(position+2); //Moves from the position of "=" 2 spaces to the right... | |
107 | - istringstream convert(numStr); //...and converts the string into numbers using "istringstream" | |
108 | - | |
109 | - convert>>result; //converts result from previous line | |
110 | - | |
111 | - return result; | |
112 | - } | |
113 | - //retrieves a string parameter from a line of text | |
114 | - string getString(string line) | |
115 | - { | |
116 | - int position; | |
117 | - position=line.find("="); //Finds the position of the equal sign | |
118 | - | |
119 | - string word; //Creates a string for storing word data called "word" | |
120 | - word=line.substr(position+2); //Moves from the position of "=" 2 spaces to the right | |
121 | - //Note: We do not need to convert word using "istringstream" | |
122 | - | |
123 | - return word; | |
124 | - } | |
125 | -}; | |
126 | -#endif |
envi/EnviOpen.h deleted
1 | -#ifndef ENVIOPEN_H | |
2 | -#define ENVIOPEN_H | |
3 | -#include <string> | |
4 | -#include <iostream> | |
5 | -#include <fstream> | |
6 | -#include <ctime> | |
7 | -#include <sstream> | |
8 | -#include <stdio.h> | |
9 | -#include "EnviHeader.h" | |
10 | -#include "EnviFid.h" | |
11 | -using namespace std; | |
12 | - | |
13 | - | |
14 | - | |
15 | -//return value is incorrect | |
16 | -static EnviFidClass EnviOpen(string filename, char* mask = NULL, string mode = "r", int nBands = 0, int sX = 0) | |
17 | -{ | |
18 | - //create a file ID object | |
19 | - EnviFidClass fid; | |
20 | - | |
21 | - //set the file read/write mode | |
22 | - fid.mode = mode; | |
23 | - | |
24 | - //set the mask (if specified) | |
25 | - fid.mask = mask; | |
26 | - | |
27 | - // load the header file only while reading | |
28 | - if(mode=="r") | |
29 | - { | |
30 | - //load the header file | |
31 | - int error = fid.header.LoadHeader(filename); | |
32 | - | |
33 | - //if the LoadHeader function is not zero, the header is invalid | |
34 | - if (error != 0) | |
35 | - { | |
36 | - fid.isValid = 0; | |
37 | - return fid; | |
38 | - } | |
39 | - | |
40 | - } | |
41 | - | |
42 | - //default header to be used in case of writing a file | |
43 | - else | |
44 | - { | |
45 | - | |
46 | - fid.header.datatype= 4; | |
47 | - fid.header.nF= nBands; | |
48 | - fid.header.sX=0; | |
49 | - fid.header.sY=1; | |
50 | - fid.header.headersize=0; | |
51 | - } | |
52 | - //load the binary file associated with this header | |
53 | - //get the binary file name | |
54 | - | |
55 | - //find the binary file name | |
56 | - | |
57 | - //locate the position of the extension | |
58 | - int pos = filename.find(".hdr"); | |
59 | - string binaryname = filename.substr(0, pos); | |
60 | - //load the binary file using fopen() | |
61 | - //store the resulting FILE pointer in the EnviFidClass variable | |
62 | - mode += "b"; | |
63 | - fid.file = fopen (binaryname.c_str(), mode.c_str()); | |
64 | - if(fid.file == NULL) | |
65 | - { | |
66 | - cout<<"Error opening binary file."<<endl; | |
67 | - fid.isValid = 0; | |
68 | - return fid; | |
69 | - } | |
70 | - | |
71 | - //set the file name | |
72 | - fid.fileName = binaryname; | |
73 | - | |
74 | - fid.isValid = 1; | |
75 | - return fid; | |
76 | -} | |
77 | - | |
78 | -static EnviFidClass EnviOpen(EnviFidClass fid, char* mask = NULL, string mode = "r") | |
79 | -{ | |
80 | - string filename = fid.fileName; | |
81 | - filename += ".hdr"; | |
82 | - | |
83 | - return EnviOpen(filename, mask, mode); | |
84 | -} | |
85 | - | |
86 | -#endif | |
87 | - |
envi/EnviRead.h deleted
1 | -#ifndef ENVIREAD_H | |
2 | -#define ENVIREAD_H | |
3 | - | |
4 | -#include <string> | |
5 | -#include <iostream> | |
6 | -#include <fstream> | |
7 | -#include <ctime> | |
8 | -#include <sstream> | |
9 | -#include <stdio.h> | |
10 | -#include "EnviHeader.h" | |
11 | -#include "EnviFid.h" | |
12 | -#include "EnviOpen.h" | |
13 | -using namespace std; | |
14 | - | |
15 | - | |
16 | -static int EnviRead(float* ptr, int nPixels, EnviFidClass &fid) | |
17 | -{ | |
18 | - //number of values to read from the file | |
19 | - int totalPixels = fid.header.sX * fid.header.sY; | |
20 | - | |
21 | - //ERROR TEST: make sure that fid.file is a valid file pointer | |
22 | - if (fid.file == NULL) | |
23 | - { | |
24 | - cout<<"Binary file isn't open."<<endl; | |
25 | - return 0; | |
26 | - } | |
27 | - | |
28 | - //---------MASK implementation | |
29 | - | |
30 | - | |
31 | - int i=0; | |
32 | - unsigned int sizeRead; | |
33 | - //iterate through every pixel in the image | |
34 | - //while we have not encountered the end of the file AND we have not read nPixels pixels | |
35 | - while(fid.filePos < totalPixels && i < nPixels) | |
36 | - { | |
37 | - //if there is no mask OR the current pixel is valid, read it | |
38 | - if(fid.mask == NULL || fid.mask[fid.filePos] == 1) | |
39 | - { | |
40 | - //read the pixel directly from disk | |
41 | - sizeRead = fread(&ptr[fid.header.nF * i], sizeof(float), fid.header.nF, fid.file); | |
42 | - | |
43 | - //catch an error if one occurs | |
44 | - if (sizeRead != fid.header.nF) | |
45 | - { | |
46 | - cout<<"Error during read # "<<i<<endl; | |
47 | - return 0; | |
48 | - } | |
49 | - i++; | |
50 | - } | |
51 | - | |
52 | - | |
53 | - //otherwise, skip it | |
54 | - else | |
55 | - fseek(fid.file, sizeof(float) * fid.header.nF, SEEK_CUR); | |
56 | - | |
57 | - //increment the file position (used to index into the mask) | |
58 | - fid.filePos++; | |
59 | - | |
60 | - } | |
61 | - | |
62 | - return i; | |
63 | -} | |
64 | - | |
65 | -#endif |
envi/EnviWrite.h deleted
1 | -#ifndef ENVIWRITE_H | |
2 | -#define ENVIWRITE_H | |
3 | -#include <fstream> | |
4 | -#include <stdio.h> | |
5 | -#include "EnviHeader.h" | |
6 | -#include "EnviFid.h" | |
7 | -#include "EnviOpen.h" | |
8 | - | |
9 | -// Take a memory pointer, and copy all of that data to disk. | |
10 | -static int EnviWrite(float* ptr, int npixels, EnviFidClass &fid) | |
11 | -{ | |
12 | - if(fid.mode == "r") return 0; | |
13 | - | |
14 | - //open a binary file for writing | |
15 | - if (fid.file == NULL) | |
16 | - { | |
17 | - cout<<"Binary file isn't open."<<endl; | |
18 | - return 1; | |
19 | - } | |
20 | - | |
21 | - //allocate an array of zeros equal to the size of a single pixel | |
22 | - float* zeroPtr = (float*) malloc(sizeof(float) * fid.header.nF); | |
23 | - memset(zeroPtr, 0, sizeof(float) * fid.header.nF); | |
24 | - | |
25 | - | |
26 | - int j = 0; | |
27 | - //for each pixel send to the EnviRead function | |
28 | - for(int p = 0; p<npixels; p++) | |
29 | - { | |
30 | - | |
31 | - //while the mask is zero | |
32 | - while(fid.mask[fid.filePos] == 0) | |
33 | - { | |
34 | - //increment filePos | |
35 | - fid.filePos++; | |
36 | - fid.header.sX++; | |
37 | - j++; | |
38 | - | |
39 | - //write a sequence of zeros | |
40 | - size_t results= fwrite(zeroPtr, sizeof(float), fid.header.nF, fid.file); | |
41 | - //check for errors | |
42 | - if (results != fid.header.nF) | |
43 | - { | |
44 | - cout<<"Error during read # "<<j<<endl; | |
45 | - return 0; | |
46 | - } | |
47 | - } | |
48 | - | |
49 | - //write a pixel | |
50 | - size_t results= fwrite(&ptr[fid.header.nF * p], sizeof(float), fid.header.nF, fid.file); | |
51 | - if (results != fid.header.nF) | |
52 | - { | |
53 | - cout<<"Error during read # "<<j<<endl; | |
54 | - return 0; | |
55 | - } | |
56 | - | |
57 | - //increment filePos | |
58 | - fid.filePos++; | |
59 | - fid.header.sX++; | |
60 | - j++; | |
61 | - } | |
62 | - | |
63 | - return j; | |
64 | - | |
65 | -} | |
66 | - | |
67 | - | |
68 | - | |
69 | - | |
70 | - | |
71 | -#endif |
envi/envi.h
... | ... | @@ -10,7 +10,11 @@ |
10 | 10 | |
11 | 11 | namespace stim{ |
12 | 12 | |
13 | -//container class for an ENVI binary file reader | |
13 | +/** This class implements reading of ENVI hyperspectral files. These files can be stored in multiple orientations | |
14 | + (including BSQ, BIP, and BIL) in order to optimize streaming speed depending on applications. Basic ENVI | |
15 | + files are stored on disk as a large binary file with a corresponding header. Code for reading and processing | |
16 | + ENVI header files is in the envi_header class. | |
17 | +*/ | |
14 | 18 | class envi{ |
15 | 19 | |
16 | 20 | void* file; //void pointer to the relevant file reader (bip, bsq, or bil - with appropriate data type) |
... | ... | @@ -19,6 +23,7 @@ public: |
19 | 23 | |
20 | 24 | envi_header header; |
21 | 25 | |
26 | + /// Allocate memory for a new ENVI file based on the current interleave format (BIP, BIL, BSQ) and data type. | |
22 | 27 | bool allocate(){ |
23 | 28 | |
24 | 29 | file = NULL; //set file to a NULL pointer |
... | ... | @@ -46,6 +51,10 @@ public: |
46 | 51 | |
47 | 52 | } |
48 | 53 | |
54 | + /// Open an existing ENVI file given the file and header names. | |
55 | + | |
56 | + /// @param filename is the name of the ENVI binary file | |
57 | + /// @param headername is the name of the ENVI header file | |
49 | 58 | bool open(std::string filename, std::string headername){ |
50 | 59 | |
51 | 60 | //allocate memory |
... | ... | @@ -95,7 +104,11 @@ public: |
95 | 104 | |
96 | 105 | } |
97 | 106 | |
98 | - //perform normalization | |
107 | + /// Normalize a hyperspectral ENVI file given a band number and threshold. | |
108 | + | |
109 | + /// @param outfile is the name of the normalized file to be output | |
110 | + /// @param band is the band label to be output | |
111 | + /// @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) | |
99 | 112 | bool normalize(std::string outfile, double band, double threshold = 0.0){ |
100 | 113 | |
101 | 114 | if(header.interleave == envi_header::BSQ){ //if the infile is bsq file |
... | ... | @@ -132,7 +145,10 @@ public: |
132 | 145 | return false; |
133 | 146 | } |
134 | 147 | |
135 | - //perform baseline correction | |
148 | + /// Performs piecewise linear baseline correction of a hyperspectral file/ | |
149 | + | |
150 | + /// @param outfile is the file name for the baseline corrected output | |
151 | + /// @param w is a list of band labels to serve as baseline points (zero values) | |
136 | 152 | bool baseline(std::string outfile, std::vector<double> w){ |
137 | 153 | |
138 | 154 | if(header.interleave == envi_header::BSQ){ //if the infile is bsq file |
... | ... | @@ -174,7 +190,10 @@ public: |
174 | 190 | } |
175 | 191 | } |
176 | 192 | |
177 | - //perform conversion | |
193 | + /// Converts ENVI files between interleave types (BSQ, BIL, and BIP) | |
194 | + | |
195 | + /// @param outfile is the file name for the converted output | |
196 | + /// @param interleave is the interleave format for the destination file | |
178 | 197 | bool convert(std::string outfile, stim::envi_header::interleaveType interleave){ |
179 | 198 | |
180 | 199 | if(header.interleave == envi_header::BSQ){ //if the infile is bsq file |
... | ... | @@ -275,7 +294,11 @@ public: |
275 | 294 | |
276 | 295 | } |
277 | 296 | |
278 | - //create a mask based on a band and threshold, save it to p (if p is not NULL) | |
297 | + /// Builds a mask from a band image and threshold value | |
298 | + | |
299 | + /// @param mask_band is the label for the band that will be used to build the mask | |
300 | + /// @param threshold is a value selected such that all band values greater than threshold will have a mask value of 'true' | |
301 | + /// @param p is memory of size X*Y that will store the resulting mask | |
279 | 302 | bool build_mask(double mask_band, double threshold, unsigned char* p = NULL) { |
280 | 303 | |
281 | 304 | if(header.interleave == envi_header::BSQ){ //if the infile is bsq file |
... | ... | @@ -308,7 +331,10 @@ public: |
308 | 331 | return false; |
309 | 332 | } |
310 | 333 | |
311 | - //apply mask | |
334 | + /// Applies a mask to the ENVI file. | |
335 | + | |
336 | + /// @param outfile is the name of the resulting masked output file | |
337 | + /// @param p is memory of size X*Y containing the mask (0 = false, all other values are true) | |
312 | 338 | bool apply_mask(std::string outfile, unsigned char* p) |
313 | 339 | { |
314 | 340 | |
... | ... | @@ -346,7 +372,15 @@ public: |
346 | 372 | return false; |
347 | 373 | } |
348 | 374 | |
349 | - //peak height to peak height ratio | |
375 | + /// Compute the ratio of two baseline-corrected peaks. The result is stored in a pre-allocated array. | |
376 | + | |
377 | + /// @param lb1 is the label value for the left baseline point for the first peak (numerator) | |
378 | + /// @param rb1 is the label value for the right baseline point for the first peak (numerator) | |
379 | + /// @param pos1 is the label value for the first peak (numerator) position | |
380 | + /// @param lb2 is the label value for the left baseline point for the second peak (denominator) | |
381 | + /// @param rb2 is the label value for the right baseline point for the second peak (denominator) | |
382 | + /// @param pos2 is the label value for the second peak (denominator) position | |
383 | + /// @param result is a pointer to a pre-allocated array at least X * Y * sizeof(T) in size | |
350 | 384 | bool ph_to_ph(double lb1, double rb1, double pos1, double lb2, double rb2, double pos2, void * result){ |
351 | 385 | if(header.interleave == envi_header::BSQ){ //if the infile is bsq file |
352 | 386 | if(header.data_type ==envi_header::float32) |
... | ... | @@ -382,7 +416,15 @@ public: |
382 | 416 | return false; |
383 | 417 | } |
384 | 418 | |
385 | - //peak area to peak height ratio | |
419 | + /// Compute the ratio between a peak area and peak height. | |
420 | + | |
421 | + /// @param lb1 is the label value for the left baseline point for the first peak (numerator) | |
422 | + /// @param rb1 is the label value for the right baseline point for the first peak (numerator) | |
423 | + /// @param pos1 is the label value for the first peak (numerator) position | |
424 | + /// @param lb2 is the label value for the left baseline point for the second peak (denominator) | |
425 | + /// @param rb2 is the label value for the right baseline point for the second peak (denominator) | |
426 | + /// @param pos2 is the label value for the second peak (denominator) position | |
427 | + /// @param result is a pointer to a pre-allocated array at least X * Y * sizeof(T) in size | |
386 | 428 | bool pa_to_ph(double lb1, double rb1, double lab1, double rab1, double lb2, double rb2, double pos, void * result){ |
387 | 429 | if(header.interleave == envi_header::BSQ){ //if the infile is bsq file |
388 | 430 | if(header.data_type ==envi_header::float32) |
... | ... | @@ -418,7 +460,17 @@ public: |
418 | 460 | return false; |
419 | 461 | } |
420 | 462 | |
421 | - //peak area to peak area ratio | |
463 | + /// Compute the ratio between two peak areas. | |
464 | + | |
465 | + /// @param lb1 is the label value for the left baseline point for the first peak (numerator) | |
466 | + /// @param rb1 is the label value for the right baseline point for the first peak (numerator) | |
467 | + /// @param lab1 is the label value for the left bound (start of the integration) of the first peak (numerator) | |
468 | + /// @param rab1 is the label value for the right bound (end of the integration) of the first peak (numerator) | |
469 | + /// @param lb2 is the label value for the left baseline point for the second peak (denominator) | |
470 | + /// @param rb2 is the label value for the right baseline point for the second peak (denominator) | |
471 | + /// @param lab2 is the label value for the left bound (start of the integration) of the second peak (denominator) | |
472 | + /// @param rab2 is the label value for the right bound (end of the integration) of the second peak (denominator) | |
473 | + /// @param result is a pointer to a pre-allocated array at least X * Y * sizeof(T) in size | |
422 | 474 | bool pa_to_pa(double lb1, double rb1, double lab1, double rab1, |
423 | 475 | double lb2, double rb2, double lab2, double rab2, void* result){ |
424 | 476 | if(header.interleave == envi_header::BSQ){ //if the infile is bsq file |
... | ... | @@ -455,7 +507,13 @@ public: |
455 | 507 | return false; |
456 | 508 | } |
457 | 509 | |
458 | - //center of gravity | |
510 | + /// Compute the centroid of a baseline corrected peak. | |
511 | + | |
512 | + /// @param lb is the label value for the left baseline point | |
513 | + /// @param rb is the label value for the right baseline point | |
514 | + /// @param lab is the label for the start of the peak | |
515 | + /// @param rab is the label for the end of the peak | |
516 | + /// @param result is a pointer to a pre-allocated array at least X * Y * sizeof(T) in size | |
459 | 517 | bool cpoint(double lb1, double rb1, double lab1, double rab1, void* result){ |
460 | 518 | if(header.interleave == envi_header::BSQ){ //if the infile is bsq file |
461 | 519 | if(header.data_type ==envi_header::float32) |
... | ... | @@ -491,6 +549,7 @@ public: |
491 | 549 | return false; |
492 | 550 | } |
493 | 551 | |
552 | + /// Closes the ENVI file. | |
494 | 553 | bool close(){ |
495 | 554 | if(header.interleave == envi_header::BSQ){ |
496 | 555 | if(header.data_type ==envi_header::float32) |
... | ... | @@ -526,7 +585,11 @@ public: |
526 | 585 | } |
527 | 586 | return false; |
528 | 587 | } |
529 | - //get one pixel from binary file | |
588 | + | |
589 | + /// Retrieve a single pixel and stores it in pre-allocated memory. | |
590 | + | |
591 | + /// @param p is a pointer to pre-allocated memory at least sizeof(T) in size. | |
592 | + /// @param n is an integer index to the pixel using linear array indexing. | |
530 | 593 | bool pixel(void * p, unsigned n){ |
531 | 594 | if(header.interleave == envi_header::BSQ){ |
532 | 595 | if(header.data_type ==envi_header::float32) |
... | ... | @@ -561,6 +624,7 @@ public: |
561 | 624 | return false; |
562 | 625 | } |
563 | 626 | |
627 | + /// Saves a header file describing the current ENVI file parameters. | |
564 | 628 | bool save_header(std::string filename){ |
565 | 629 | |
566 | 630 | //save the header file here |
... | ... | @@ -569,6 +633,10 @@ public: |
569 | 633 | return true; |
570 | 634 | } |
571 | 635 | |
636 | + /// Retrieve a single band (by numerical label) and stores it in pre-allocated memory. | |
637 | + | |
638 | + /// @param p is a pointer to an allocated region of memory at least X * Y * sizeof(T) in size. | |
639 | + /// @param wavelength is a floating point value (usually a wavelength in spectral data) used as a label for the band to be copied. | |
572 | 640 | bool band(void* ptr, double wavelength){ |
573 | 641 | |
574 | 642 | if(header.interleave == envi_header::BSQ){ //if the infile is bsq file |
... | ... | @@ -604,6 +672,10 @@ public: |
604 | 672 | return false; |
605 | 673 | } |
606 | 674 | |
675 | + /// Retrieve a single band (based on index) and stores it in pre-allocated memory. | |
676 | + | |
677 | + /// @param p is a pointer to an allocated region of memory at least X * Y * sizeof(T) in size. | |
678 | + /// @param page <= B is the integer number of the band to be copied. | |
607 | 679 | bool band_index(void* ptr, unsigned int b){ |
608 | 680 | if (header.interleave == envi_header::BSQ){ //if the infile is bsq file |
609 | 681 | if (header.data_type == envi_header::float32) |
... | ... | @@ -638,7 +710,10 @@ public: |
638 | 710 | return false; |
639 | 711 | } |
640 | 712 | |
641 | - //load mask from maskfile and save it into memory | |
713 | + /// Helper function that loads a mask into memory given a filename. | |
714 | + | |
715 | + /// @param mask is a pointer to pre-allocated memory of size X*Y | |
716 | + /// @param maskname is the file name for the image that will serve as the mask | |
642 | 717 | bool load_mask(unsigned char * mask, std::string maskname){ |
643 | 718 | //open the mask file |
644 | 719 | stim::image<unsigned char> mask_image(maskname); |
... | ... | @@ -693,7 +768,10 @@ public: |
693 | 768 | return true; |
694 | 769 | } |
695 | 770 | |
696 | - //calculate band average | |
771 | + /// Calculate the mean value for all masked (or valid) pixels in a band and returns the average spectrum | |
772 | + | |
773 | + /// @param p is a pointer to pre-allocated memory of size [B * sizeof(T)] that stores the mean spectrum | |
774 | + /// @param mask is a pointer to memory of size [X * Y] that stores the mask value at each pixel location | |
697 | 775 | bool avg_band(void * p, unsigned char* mask){ |
698 | 776 | if (header.interleave == envi_header::BSQ){ |
699 | 777 | if (header.data_type == envi_header::float32) |
... | ... | @@ -728,7 +806,11 @@ public: |
728 | 806 | return false; |
729 | 807 | } |
730 | 808 | |
731 | - //calculate correlation coefficient matrix with mask | |
809 | + /// Calculate the covariance matrix for all masked pixels in the image. | |
810 | + | |
811 | + /// @param co is a pointer to pre-allocated memory of size [B * B] that stores the resulting covariance matrix | |
812 | + /// @param avg is a pointer to memory of size B that stores the average spectrum | |
813 | + /// @param mask is a pointer to memory of size [X * Y] that stores the mask value at each pixel location | |
732 | 814 | bool co_matrix(void* co, void* avg, unsigned char* mask){ |
733 | 815 | if (header.interleave == envi_header::BSQ){ |
734 | 816 | if (header.data_type == envi_header::float32) |
... | ... | @@ -764,7 +846,13 @@ public: |
764 | 846 | } |
765 | 847 | |
766 | 848 | |
767 | - //crop specified area the of the original file | |
849 | + /// Crop a region of the image and save it to a new file. | |
850 | + | |
851 | + /// @param outfile is the file name for the new cropped image | |
852 | + /// @param x0 is the lower-left x pixel coordinate to be included in the cropped image | |
853 | + /// @param y0 is the lower-left y pixel coordinate to be included in the cropped image | |
854 | + /// @param x1 is the upper-right x pixel coordinate to be included in the cropped image | |
855 | + /// @param y1 is the upper-right y pixel coordinate to be included in the cropped image | |
768 | 856 | bool crop(std::string outfile,unsigned x0, unsigned y0, unsigned x1, unsigned y1){ |
769 | 857 | |
770 | 858 | if (header.interleave == envi_header::BSQ){ | ... | ... |