Commit a23c4132c77f7ece12411d70570a50d13fd89c3d

Authored by David Mayerich
1 parent e0c22b85

Doxygen comments for bil, bsq, bip. Removed JPEG library from image.h

Showing 4 changed files with 293 additions and 49 deletions   Show diff stats
@@ -8,6 +8,15 @@ @@ -8,6 +8,15 @@
8 8
9 namespace stim{ 9 namespace stim{
10 10
  11 +/**
  12 + The BIL class represents a 3-dimensional binary file stored using band interleaved by line (BIL) image encoding. The binary file is stored
  13 + such that X-Z "frames" are stored sequentially to form an image stack along the y-axis. When accessing the data sequentially on disk,
  14 + the dimensions read, from fastest to slowest, are X, Z, Y.
  15 +
  16 + This class is optimized for data streaming, and therefore supports extremely large (terabyte-scale) files. Data is loaded from disk
  17 + on request. Functions used to access data are written to support efficient reading.
  18 +*/
  19 +
11 template <typename T> 20 template <typename T>
12 21
13 class bil: public binary<T> { 22 class bil: public binary<T> {
@@ -22,7 +31,14 @@ public: @@ -22,7 +31,14 @@ public:
22 using binary<T>::file; 31 using binary<T>::file;
23 using binary<T>::R; 32 using binary<T>::R;
24 33
25 - //open a file, given the file and its header's names 34 + /// Open a data file for reading using the class interface.
  35 +
  36 + /// @param filename is the name of the binary file on disk
  37 + /// @param X is the number of samples along dimension 1
  38 + /// @param Y is the number of samples (lines) along dimension 2
  39 + /// @param B is the number of samples (bands) along dimension 3
  40 + /// @param header_offset is the number of bytes (if any) in the binary header
  41 + /// @param wavelengths is an optional STL vector of size B specifying a numerical label for each band
26 bool open(std::string filename, unsigned int X, unsigned int Y, unsigned int B, unsigned int header_offset, std::vector<double> wavelengths){ 42 bool open(std::string filename, unsigned int X, unsigned int Y, unsigned int B, unsigned int header_offset, std::vector<double> wavelengths){
27 43
28 w = wavelengths; 44 w = wavelengths;
@@ -31,7 +47,10 @@ public: @@ -31,7 +47,10 @@ public:
31 47
32 } 48 }
33 49
34 - //save one band of the file into the memory, and return the pointer 50 + /// Retrieve a single band (based on index) and stores it in pre-allocated memory.
  51 +
  52 + /// @param p is a pointer to an allocated region of memory at least X * Y * sizeof(T) in size.
  53 + /// @param page <= B is the integer number of the band to be copied.
35 bool band_index( T * p, unsigned int page){ 54 bool band_index( T * p, unsigned int page){
36 55
37 unsigned int L = R[0] * sizeof(T); //caculate the number of bytes in a sample line 56 unsigned int L = R[0] * sizeof(T); //caculate the number of bytes in a sample line
@@ -52,6 +71,10 @@ public: @@ -52,6 +71,10 @@ public:
52 return true; 71 return true;
53 } 72 }
54 73
  74 + /// Retrieve a single band (by numerical label) and stores it in pre-allocated memory.
  75 +
  76 + /// @param p is a pointer to an allocated region of memory at least X * Y * sizeof(T) in size.
  77 + /// @param wavelength is a floating point value (usually a wavelength in spectral data) used as a label for the band to be copied.
55 bool band( T * p, double wavelength){ 78 bool band( T * p, double wavelength){
56 79
57 //if there are no wavelengths in the BSQ file 80 //if there are no wavelengths in the BSQ file
@@ -151,7 +174,11 @@ public: @@ -151,7 +174,11 @@ public:
151 return true; 174 return true;
152 } 175 }
153 176
154 - //save one pixel of the BIP file into the memory, and return the pointer 177 + /// Retrieve a single spectrum (B-axis line) at a given (x, y) location and stores it in pre-allocated memory.
  178 +
  179 + /// @param p is a pointer to pre-allocated memory at least B * sizeof(T) in size.
  180 + /// @param x is the x-coordinate (dimension 1) of the spectrum.
  181 + /// @param y is the y-coordinate (dimension 2) of the spectrum.
155 bool spectrum(T * p, unsigned x, unsigned y){ 182 bool spectrum(T * p, unsigned x, unsigned y){
156 183
157 if ( x >= R[0] || y >= R[1]){ //make sure the sample and line number is right 184 if ( x >= R[0] || y >= R[1]){ //make sure the sample and line number is right
@@ -173,7 +200,10 @@ public: @@ -173,7 +200,10 @@ public:
173 return true; 200 return true;
174 } 201 }
175 202
176 - //save one pixel into memory 203 + /// Retrieve a single pixel and stores it in pre-allocated memory.
  204 +
  205 + /// @param p is a pointer to pre-allocated memory at least sizeof(T) in size.
  206 + /// @param n is an integer index to the pixel using linear array indexing.
177 bool pixel(T * p, unsigned n){ 207 bool pixel(T * p, unsigned n){
178 208
179 //calculate the corresponding x, y 209 //calculate the corresponding x, y
@@ -199,7 +229,10 @@ public: @@ -199,7 +229,10 @@ public:
199 229
200 } 230 }
201 231
202 - //(BIL) baseline correction 232 + /// Perform baseline correction given a list of baseline points and stores the result in a new BSQ file.
  233 +
  234 + /// @param outname is the name of the output file used to store the resulting baseline-corrected data.
  235 + /// @param wls is the list of baseline points based on band labels.
203 bool baseline(std::string outname, std::vector<double> wls){ 236 bool baseline(std::string outname, std::vector<double> wls){
204 237
205 unsigned N = wls.size(); //get the number of baseline points 238 unsigned N = wls.size(); //get the number of baseline points
@@ -308,7 +341,11 @@ public: @@ -308,7 +341,11 @@ public:
308 341
309 } 342 }
310 343
311 - // normalize the BIL file 344 + /// Normalize all spectra based on the value of a single band, storing the result in a new BSQ file.
  345 +
  346 + /// @param outname is the name of the output file used to store the resulting baseline-corrected data.
  347 + /// @param w is the label specifying the band that the hyperspectral image will be normalized to.
  348 + /// @param t is a threshold specified such that a spectrum with a value at w less than t is set to zero. Setting this threshold allows the user to limit division by extremely small numbers.
312 bool normalize(std::string outname, double w, double t = 0.0) 349 bool normalize(std::string outname, double w, double t = 0.0)
313 { 350 {
314 unsigned int B = R[2]; //calculate the number of bands 351 unsigned int B = R[2]; //calculate the number of bands
@@ -352,7 +389,9 @@ public: @@ -352,7 +389,9 @@ public:
352 return true; 389 return true;
353 } 390 }
354 391
355 - //convert BIL file to BSQ file and save it 392 + /// Convert the current BIL file to a BSQ file with the specified file name.
  393 +
  394 + /// @param outname is the name of the output BSQ file to be saved to disk.
356 bool bsq(std::string outname) 395 bool bsq(std::string outname)
357 { 396 {
358 unsigned int S = R[0] * R[1] * sizeof(T); //calculate the number of bytes in a band 397 unsigned int S = R[0] * R[1] * sizeof(T); //calculate the number of bytes in a band
@@ -374,7 +413,9 @@ public: @@ -374,7 +413,9 @@ public:
374 return true; 413 return true;
375 } 414 }
376 415
377 - //convert bil file to bip file and save it 416 + /// Convert the current BIL file to a BIP file with the specified file name.
  417 +
  418 + /// @param outname is the name of the output BIP file to be saved to disk.
378 bool bip(std::string outname) 419 bool bip(std::string outname)
379 { 420 {
380 unsigned int S = R[0] * R[2] * sizeof(T); //calculate the number of bytes in a ZX slice 421 unsigned int S = R[0] * R[2] * sizeof(T); //calculate the number of bytes in a ZX slice
@@ -408,7 +449,14 @@ public: @@ -408,7 +449,14 @@ public:
408 } 449 }
409 450
410 451
411 - //providing the left and the right bound data, return baseline-corrected band height 452 + /// Return a baseline corrected band given two adjacent baseline points and their bands. The result is stored in a pre-allocated array.
  453 +
  454 + /// @param lb is the label value for the left baseline point
  455 + /// @param rb is the label value for the right baseline point
  456 + /// @param lp is a pointer to an array holding the band image for the left baseline point
  457 + /// @param rp is a pointer to an array holding the band image for the right baseline point
  458 + /// @param wavelength is the label value for the requested baseline-corrected band
  459 + /// @param result is a pointer to a pre-allocated array at least X * Y * sizeof(T) in size.
412 bool baseline_band(double lb, double rb, T* lp, T* rp, double wavelength, T* result){ 460 bool baseline_band(double lb, double rb, T* lp, T* rp, double wavelength, T* result){
413 461
414 unsigned XY = R[0] * R[1]; 462 unsigned XY = R[0] * R[1];
@@ -421,6 +469,13 @@ public: @@ -421,6 +469,13 @@ public:
421 } 469 }
422 return true; 470 return true;
423 } 471 }
  472 +
  473 + /// Return a baseline corrected band given two adjacent baseline points. The result is stored in a pre-allocated array.
  474 +
  475 + /// @param lb is the label value for the left baseline point
  476 + /// @param rb is the label value for the right baseline point
  477 + /// @param bandwavelength is the label value for the desired baseline-corrected band
  478 + /// @param result is a pointer to a pre-allocated array at least X * Y * sizeof(T) in size.
424 bool height(double lb, double rb, double bandwavelength, T* result){ 479 bool height(double lb, double rb, double bandwavelength, T* result){
425 480
426 T* lp; 481 T* lp;
@@ -441,7 +496,14 @@ public: @@ -441,7 +496,14 @@ public:
441 } 496 }
442 497
443 498
444 - //calculate the area between two bound point(including baseline correction) 499 +
  500 + /// Calculate the area under the spectrum between two specified points and stores the result in a pre-allocated array.
  501 +
  502 + /// @param lb is the label value for the left baseline point
  503 + /// @param rb is the label value for the right baseline point
  504 + /// @param lab is the label value for the left bound (start of the integration)
  505 + /// @param rab is the label value for the right bound (end of the integration)
  506 + /// @param result is a pointer to a pre-allocated array at least X * Y * sizeof(T) in size
445 bool area(double lb, double rb, double lab, double rab, T* result){ 507 bool area(double lb, double rb, double lab, double rab, T* result){
446 508
447 T* lp; //left band pointer 509 T* lp; //left band pointer
@@ -519,7 +581,15 @@ public: @@ -519,7 +581,15 @@ public:
519 return true; 581 return true;
520 } 582 }
521 583
522 - //peak height ratio 584 + /// Compute the ratio of two baseline-corrected peaks. The result is stored in a pre-allocated array.
  585 +
  586 + /// @param lb1 is the label value for the left baseline point for the first peak (numerator)
  587 + /// @param rb1 is the label value for the right baseline point for the first peak (numerator)
  588 + /// @param pos1 is the label value for the first peak (numerator) position
  589 + /// @param lb2 is the label value for the left baseline point for the second peak (denominator)
  590 + /// @param rb2 is the label value for the right baseline point for the second peak (denominator)
  591 + /// @param pos2 is the label value for the second peak (denominator) position
  592 + /// @param result is a pointer to a pre-allocated array at least X * Y * sizeof(T) in size
523 bool ph_to_ph(double lb1, double rb1, double pos1, double lb2, double rb2, double pos2, T * result){ 593 bool ph_to_ph(double lb1, double rb1, double pos1, double lb2, double rb2, double pos2, T * result){
524 594
525 T* p1 = (T*)malloc(R[0] * R[1] * sizeof(T)); 595 T* p1 = (T*)malloc(R[0] * R[1] * sizeof(T));
@@ -541,7 +611,15 @@ public: @@ -541,7 +611,15 @@ public:
541 return true; 611 return true;
542 } 612 }
543 613
544 - //peak are to peak height ratio 614 + /// Compute the ratio between a peak area and peak height.
  615 +
  616 + /// @param lb1 is the label value for the left baseline point for the first peak (numerator)
  617 + /// @param rb1 is the label value for the right baseline point for the first peak (numerator)
  618 + /// @param pos1 is the label value for the first peak (numerator) position
  619 + /// @param lb2 is the label value for the left baseline point for the second peak (denominator)
  620 + /// @param rb2 is the label value for the right baseline point for the second peak (denominator)
  621 + /// @param pos2 is the label value for the second peak (denominator) position
  622 + /// @param result is a pointer to a pre-allocated array at least X * Y * sizeof(T) in size
545 bool pa_to_ph(double lb1, double rb1, double lab1, double rab1, 623 bool pa_to_ph(double lb1, double rb1, double lab1, double rab1,
546 double lb2, double rb2, double pos, T* result){ 624 double lb2, double rb2, double pos, T* result){
547 625
@@ -564,7 +642,17 @@ public: @@ -564,7 +642,17 @@ public:
564 return true; 642 return true;
565 } 643 }
566 644
567 - //peak area to peak area ratio 645 + /// Compute the ratio between two peak areas.
  646 +
  647 + /// @param lb1 is the label value for the left baseline point for the first peak (numerator)
  648 + /// @param rb1 is the label value for the right baseline point for the first peak (numerator)
  649 + /// @param lab1 is the label value for the left bound (start of the integration) of the first peak (numerator)
  650 + /// @param rab1 is the label value for the right bound (end of the integration) of the first peak (numerator)
  651 + /// @param lb2 is the label value for the left baseline point for the second peak (denominator)
  652 + /// @param rb2 is the label value for the right baseline point for the second peak (denominator)
  653 + /// @param lab2 is the label value for the left bound (start of the integration) of the second peak (denominator)
  654 + /// @param rab2 is the label value for the right bound (end of the integration) of the second peak (denominator)
  655 + /// @param result is a pointer to a pre-allocated array at least X * Y * sizeof(T) in size
568 bool pa_to_pa(double lb1, double rb1, double lab1, double rab1, 656 bool pa_to_pa(double lb1, double rb1, double lab1, double rab1,
569 double lb2, double rb2, double lab2, double rab2, T* result){ 657 double lb2, double rb2, double lab2, double rab2, T* result){
570 658
@@ -587,7 +675,13 @@ public: @@ -587,7 +675,13 @@ public:
587 return true; 675 return true;
588 } 676 }
589 677
590 - //x * f(x) 678 + /// Compute the definite integral of a baseline corrected peak.
  679 +
  680 + /// @param lb is the label value for the left baseline point
  681 + /// @param rb is the label value for the right baseline point
  682 + /// @param lab is the label for the start of the definite integral
  683 + /// @param rab is the label for the end of the definite integral
  684 + /// @param result is a pointer to a pre-allocated array at least X * Y * sizeof(T) in size
591 bool x_area(double lb, double rb, double lab, double rab, T* result){ 685 bool x_area(double lb, double rb, double lab, double rab, T* result){
592 T* lp; //left band pointer 686 T* lp; //left band pointer
593 T* rp; //right band pointer 687 T* rp; //right band pointer
@@ -662,7 +756,13 @@ public: @@ -662,7 +756,13 @@ public:
662 return true; 756 return true;
663 } 757 }
664 758
665 - //centroid point 759 + /// Compute the centroid of a baseline corrected peak.
  760 +
  761 + /// @param lb is the label value for the left baseline point
  762 + /// @param rb is the label value for the right baseline point
  763 + /// @param lab is the label for the start of the peak
  764 + /// @param rab is the label for the end of the peak
  765 + /// @param result is a pointer to a pre-allocated array at least X * Y * sizeof(T) in size
666 bool cpoint(double lb, double rb, double lab, double rab, T* result){ 766 bool cpoint(double lb, double rb, double lab, double rab, T* result){
667 T* p1 = (T*)malloc(R[0] * R[1] * sizeof(T)); 767 T* p1 = (T*)malloc(R[0] * R[1] * sizeof(T));
668 T* p2 = (T*)malloc(R[0] * R[1] * sizeof(T)); 768 T* p2 = (T*)malloc(R[0] * R[1] * sizeof(T));
@@ -683,7 +783,13 @@ public: @@ -683,7 +783,13 @@ public:
683 return true; 783 return true;
684 } 784 }
685 785
686 - //create mask file 786 + /// Create a mask based on a given band and threshold value.
  787 +
  788 + /// All pixels in the
  789 + /// specified band greater than the threshold are true and all pixels less than the threshold are false.
  790 + /// @param mask_band is the band used to specify the mask
  791 + /// @param threshold is the threshold used to determine if the mask value is true or false
  792 + /// @param p is a pointer to a pre-allocated array at least X * Y in size
687 bool build_mask(double mask_band, double threshold, unsigned char* p){ 793 bool build_mask(double mask_band, double threshold, unsigned char* p){
688 794
689 T* temp = (T*)malloc(R[0] * R[1] * sizeof(T)); //allocate memory for the certain band 795 T* temp = (T*)malloc(R[0] * R[1] * sizeof(T)); //allocate memory for the certain band
@@ -700,7 +806,10 @@ public: @@ -700,7 +806,10 @@ public:
700 return true; 806 return true;
701 } 807 }
702 808
703 - //apply mask 809 + /// Apply a mask file to the BSQ image, setting all values outside the mask to zero.
  810 +
  811 + /// @param outfile is the name of the masked output file
  812 + /// @param p is a pointer to memory of size X * Y, where p(i) = 0 for pixels that will be set to zero.
704 bool apply_mask(std::string outfile, unsigned char* p){ 813 bool apply_mask(std::string outfile, unsigned char* p){
705 814
706 std::ofstream target(outfile.c_str(), std::ios::binary); 815 std::ofstream target(outfile.c_str(), std::ios::binary);
@@ -730,7 +839,9 @@ public: @@ -730,7 +839,9 @@ public:
730 return true; 839 return true;
731 } 840 }
732 841
733 - //calculate the average band value 842 + /// Calculate the mean band value (average along B) at each pixel location.
  843 +
  844 + /// @param p is a pointer to memory of size X * Y * sizeof(T) that will store the band averages.
734 bool band_avg(T* p){ 845 bool band_avg(T* p){
735 unsigned long long XZ = R[0] * R[2]; 846 unsigned long long XZ = R[0] * R[2];
736 T* temp = (T*)malloc(sizeof(T) * XZ); 847 T* temp = (T*)malloc(sizeof(T) * XZ);
@@ -757,7 +868,10 @@ public: @@ -757,7 +868,10 @@ public:
757 return true; 868 return true;
758 } 869 }
759 870
760 - //calculate the average number of every band 871 + /// Calculate the mean value for all masked (or valid) pixels in a band and returns the average spectrum
  872 +
  873 + /// @param p is a pointer to pre-allocated memory of size [B * sizeof(T)] that stores the mean spectrum
  874 + /// @param mask is a pointer to memory of size [X * Y] that stores the mask value at each pixel location
761 bool avg_band(T*p, unsigned char* mask){ 875 bool avg_band(T*p, unsigned char* mask){
762 unsigned long long XZ = R[0] * R[2]; 876 unsigned long long XZ = R[0] * R[2];
763 unsigned long long XY = R[0] * R[1]; 877 unsigned long long XY = R[0] * R[1];
@@ -787,7 +901,11 @@ public: @@ -787,7 +901,11 @@ public:
787 return true; 901 return true;
788 } 902 }
789 903
790 - //calculate correlation coefficient matrix 904 + /// Calculate the covariance matrix for all masked pixels in the image.
  905 +
  906 + /// @param co is a pointer to pre-allocated memory of size [B * B] that stores the resulting covariance matrix
  907 + /// @param avg is a pointer to memory of size B that stores the average spectrum
  908 + /// @param mask is a pointer to memory of size [X * Y] that stores the mask value at each pixel location
791 bool co_matrix(T* co, T* avg, unsigned char *mask){ 909 bool co_matrix(T* co, T* avg, unsigned char *mask){
792 //memory allocation 910 //memory allocation
793 unsigned long long xy = R[0] * R[1]; 911 unsigned long long xy = R[0] * R[1];
@@ -829,7 +947,13 @@ public: @@ -829,7 +947,13 @@ public:
829 } 947 }
830 948
831 949
832 - //crop specified area the of the original file 950 + /// Crop a region of the image and save it to a new file.
  951 +
  952 + /// @param outfile is the file name for the new cropped image
  953 + /// @param x0 is the lower-left x pixel coordinate to be included in the cropped image
  954 + /// @param y0 is the lower-left y pixel coordinate to be included in the cropped image
  955 + /// @param x1 is the upper-right x pixel coordinate to be included in the cropped image
  956 + /// @param y1 is the upper-right y pixel coordinate to be included in the cropped image
833 bool crop(std::string outfile, unsigned x0, unsigned y0, unsigned x1, unsigned y1){ 957 bool crop(std::string outfile, unsigned x0, unsigned y0, unsigned x1, unsigned y1){
834 958
835 //calculate the new number of samples and lines 959 //calculate the new number of samples and lines
@@ -856,7 +980,7 @@ public: @@ -856,7 +980,7 @@ public:
856 } 980 }
857 981
858 982
859 - //close the file 983 + /// Close the file.
860 bool close(){ 984 bool close(){
861 file.close(); 985 file.close();
862 return true; 986 return true;
@@ -9,6 +9,14 @@ @@ -9,6 +9,14 @@
9 9
10 namespace stim{ 10 namespace stim{
11 11
  12 +/**
  13 + The BIP class represents a 3-dimensional binary file stored using band interleaved by pixel (BIP) image encoding. The binary file is stored
  14 + such that Z-X "frames" are stored sequentially to form an image stack along the y-axis. When accessing the data sequentially on disk,
  15 + the dimensions read, from fastest to slowest, are Z, X, Y.
  16 +
  17 + This class is optimized for data streaming, and therefore supports extremely large (terabyte-scale) files. Data is loaded from disk
  18 + on request. Functions used to access data are written to support efficient reading.
  19 +*/
12 template <typename T> 20 template <typename T>
13 21
14 class bip: public binary<T> { 22 class bip: public binary<T> {
@@ -25,7 +33,14 @@ public: @@ -25,7 +33,14 @@ public:
25 using binary<T>::file; 33 using binary<T>::file;
26 using binary<T>::R; 34 using binary<T>::R;
27 35
28 - //open a file, given the file and its header's names 36 + /// Open a data file for reading using the class interface.
  37 +
  38 + /// @param filename is the name of the binary file on disk
  39 + /// @param X is the number of samples along dimension 1
  40 + /// @param Y is the number of samples (lines) along dimension 2
  41 + /// @param B is the number of samples (bands) along dimension 3
  42 + /// @param header_offset is the number of bytes (if any) in the binary header
  43 + /// @param wavelengths is an optional STL vector of size B specifying a numerical label for each band
29 bool open(std::string filename, unsigned int X, unsigned int Y, unsigned int B, unsigned int header_offset, std::vector<double> wavelengths){ 44 bool open(std::string filename, unsigned int X, unsigned int Y, unsigned int B, unsigned int header_offset, std::vector<double> wavelengths){
30 45
31 //copy the wavelengths to the BSQ file structure 46 //copy the wavelengths to the BSQ file structure
@@ -37,7 +52,10 @@ public: @@ -37,7 +52,10 @@ public:
37 52
38 } 53 }
39 54
40 - //save one band of the file into the memory, and return the pointer 55 + /// Retrieve a single band (based on index) and stores it in pre-allocated memory.
  56 +
  57 + /// @param p is a pointer to an allocated region of memory at least X * Y * sizeof(T) in size.
  58 + /// @param page <= B is the integer number of the band to be copied.
41 bool band_index( T * p, unsigned int page){ 59 bool band_index( T * p, unsigned int page){
42 60
43 if (page >= R[2]){ //make sure the bank number is right 61 if (page >= R[2]){ //make sure the bank number is right
@@ -56,6 +74,10 @@ public: @@ -56,6 +74,10 @@ public:
56 return true; 74 return true;
57 } 75 }
58 76
  77 + /// Retrieve a single band (by numerical label) and stores it in pre-allocated memory.
  78 +
  79 + /// @param p is a pointer to an allocated region of memory at least X * Y * sizeof(T) in size.
  80 + /// @param wavelength is a floating point value (usually a wavelength in spectral data) used as a label for the band to be copied.
59 bool band( T * p, double wavelength){ 81 bool band( T * p, double wavelength){
60 82
61 //if there are no wavelengths in the BSQ file 83 //if there are no wavelengths in the BSQ file
@@ -247,7 +269,11 @@ public: @@ -247,7 +269,11 @@ public:
247 return true; 269 return true;
248 } 270 }
249 271
250 - //save one pixel of the BIP file into the memory, and return the pointer 272 + /// Retrieve a single spectrum (B-axis line) at a given (x, y) location and stores it in pre-allocated memory.
  273 +
  274 + /// @param p is a pointer to pre-allocated memory at least B * sizeof(T) in size.
  275 + /// @param x is the x-coordinate (dimension 1) of the spectrum.
  276 + /// @param y is the y-coordinate (dimension 2) of the spectrum.
251 bool spectrum(T * p, unsigned x, unsigned y){ 277 bool spectrum(T * p, unsigned x, unsigned y){
252 278
253 if ( x >= R[0] || y >= R[1]){ //make sure the sample and line number is right 279 if ( x >= R[0] || y >= R[1]){ //make sure the sample and line number is right
@@ -262,7 +288,10 @@ public: @@ -262,7 +288,10 @@ public:
262 return true; 288 return true;
263 } 289 }
264 290
265 - //save one pixel into memory 291 + /// Retrieve a single pixel and stores it in pre-allocated memory.
  292 +
  293 + /// @param p is a pointer to pre-allocated memory at least sizeof(T) in size.
  294 + /// @param n is an integer index to the pixel using linear array indexing.
266 bool pixel(T * p, unsigned n){ 295 bool pixel(T * p, unsigned n){
267 296
268 unsigned bandnum = R[0] * R[1]; //calculate numbers in one band 297 unsigned bandnum = R[0] * R[1]; //calculate numbers in one band
@@ -291,7 +320,10 @@ public: @@ -291,7 +320,10 @@ public:
291 320
292 } 321 }
293 322
294 - //(BIP) baseline correction 323 + /// Perform baseline correction given a list of baseline points and stores the result in a new BSQ file.
  324 +
  325 + /// @param outname is the name of the output file used to store the resulting baseline-corrected data.
  326 + /// @param wls is the list of baseline points based on band labels.
295 bool baseline(std::string outname, std::vector<double> wls){ 327 bool baseline(std::string outname, std::vector<double> wls){
296 328
297 unsigned N = wls.size(); //get the number of baseline points 329 unsigned N = wls.size(); //get the number of baseline points
@@ -400,7 +432,11 @@ public: @@ -400,7 +432,11 @@ public:
400 432
401 } 433 }
402 434
403 - // normalize the BIP file 435 + /// Normalize all spectra based on the value of a single band, storing the result in a new BSQ file.
  436 +
  437 + /// @param outname is the name of the output file used to store the resulting baseline-corrected data.
  438 + /// @param w is the label specifying the band that the hyperspectral image will be normalized to.
  439 + /// @param t is a threshold specified such that a spectrum with a value at w less than t is set to zero. Setting this threshold allows the user to limit division by extremely small numbers.
404 bool normalize(std::string outname, double w, double t = 0.0) 440 bool normalize(std::string outname, double w, double t = 0.0)
405 { 441 {
406 unsigned int B = R[2]; //calculate the number of bands 442 unsigned int B = R[2]; //calculate the number of bands
@@ -447,7 +483,9 @@ public: @@ -447,7 +483,9 @@ public:
447 return true; 483 return true;
448 } 484 }
449 485
450 - //convert BIP file to BSQ file and save it 486 + /// Convert the current BIP file to a BSQ file with the specified file name.
  487 +
  488 + /// @param outname is the name of the output BSQ file to be saved to disk.
451 bool bsq(std::string outname) 489 bool bsq(std::string outname)
452 { 490 {
453 std::string temp = outname + "_temp"; 491 std::string temp = outname + "_temp";
@@ -468,7 +506,9 @@ public: @@ -468,7 +506,9 @@ public:
468 return true; 506 return true;
469 } 507 }
470 508
471 - //convert bip file to bil file and save it 509 + /// Convert the current BIP file to a BIL file with the specified file name.
  510 +
  511 + /// @param outname is the name of the output BIL file to be saved to disk.
472 bool bil(std::string outname) 512 bool bil(std::string outname)
473 { 513 {
474 unsigned int S = R[0] * R[2] * sizeof(T); //calculate the number of bytes in a ZX slice 514 unsigned int S = R[0] * R[2] * sizeof(T); //calculate the number of bytes in a ZX slice
@@ -500,7 +540,14 @@ public: @@ -500,7 +540,14 @@ public:
500 return true; 540 return true;
501 } 541 }
502 542
503 - //providing the left and the right bound data, return baseline-corrected band height 543 + /// Return a baseline corrected band given two adjacent baseline points and their bands. The result is stored in a pre-allocated array.
  544 +
  545 + /// @param lb is the label value for the left baseline point
  546 + /// @param rb is the label value for the right baseline point
  547 + /// @param lp is a pointer to an array holding the band image for the left baseline point
  548 + /// @param rp is a pointer to an array holding the band image for the right baseline point
  549 + /// @param wavelength is the label value for the requested baseline-corrected band
  550 + /// @param result is a pointer to a pre-allocated array at least X * Y * sizeof(T) in size.
504 bool baseline_band(double lb, double rb, T* lp, T* rp, double wavelength, T* result){ 551 bool baseline_band(double lb, double rb, T* lp, T* rp, double wavelength, T* result){
505 552
506 unsigned XY = R[0] * R[1]; 553 unsigned XY = R[0] * R[1];
@@ -514,6 +561,12 @@ public: @@ -514,6 +561,12 @@ public:
514 return true; 561 return true;
515 } 562 }
516 563
  564 + /// Return a baseline corrected band given two adjacent baseline points. The result is stored in a pre-allocated array.
  565 +
  566 + /// @param lb is the label value for the left baseline point
  567 + /// @param rb is the label value for the right baseline point
  568 + /// @param bandwavelength is the label value for the desired baseline-corrected band
  569 + /// @param result is a pointer to a pre-allocated array at least X * Y * sizeof(T) in size.
517 bool height(double lb, double rb, double bandwavelength, T* result){ 570 bool height(double lb, double rb, double bandwavelength, T* result){
518 571
519 T* lp; 572 T* lp;
@@ -534,7 +587,13 @@ public: @@ -534,7 +587,13 @@ public:
534 } 587 }
535 588
536 589
537 - //calculate the area between two bound point(including baseline correction) 590 + /// Calculate the area under the spectrum between two specified points and stores the result in a pre-allocated array.
  591 +
  592 + /// @param lb is the label value for the left baseline point
  593 + /// @param rb is the label value for the right baseline point
  594 + /// @param lab is the label value for the left bound (start of the integration)
  595 + /// @param rab is the label value for the right bound (end of the integration)
  596 + /// @param result is a pointer to a pre-allocated array at least X * Y * sizeof(T) in size
538 bool area(double lb, double rb, double lab, double rab, T* result){ 597 bool area(double lb, double rb, double lab, double rab, T* result){
539 598
540 T* lp; //left band pointer 599 T* lp; //left band pointer
@@ -612,7 +671,15 @@ public: @@ -612,7 +671,15 @@ public:
612 return true; 671 return true;
613 } 672 }
614 673
615 - //peak height ratio 674 + /// Compute the ratio of two baseline-corrected peaks. The result is stored in a pre-allocated array.
  675 +
  676 + /// @param lb1 is the label value for the left baseline point for the first peak (numerator)
  677 + /// @param rb1 is the label value for the right baseline point for the first peak (numerator)
  678 + /// @param pos1 is the label value for the first peak (numerator) position
  679 + /// @param lb2 is the label value for the left baseline point for the second peak (denominator)
  680 + /// @param rb2 is the label value for the right baseline point for the second peak (denominator)
  681 + /// @param pos2 is the label value for the second peak (denominator) position
  682 + /// @param result is a pointer to a pre-allocated array at least X * Y * sizeof(T) in size
616 bool ph_to_ph(double lb1, double rb1, double pos1, double lb2, double rb2, double pos2, T * result){ 683 bool ph_to_ph(double lb1, double rb1, double pos1, double lb2, double rb2, double pos2, T * result){
617 684
618 T* p1 = (T*)malloc(R[0] * R[1] * sizeof(T)); 685 T* p1 = (T*)malloc(R[0] * R[1] * sizeof(T));
@@ -634,7 +701,15 @@ public: @@ -634,7 +701,15 @@ public:
634 return true; 701 return true;
635 } 702 }
636 703
637 - //peak are to peak height ratio 704 + /// Compute the ratio between a peak area and peak height.
  705 +
  706 + /// @param lb1 is the label value for the left baseline point for the first peak (numerator)
  707 + /// @param rb1 is the label value for the right baseline point for the first peak (numerator)
  708 + /// @param pos1 is the label value for the first peak (numerator) position
  709 + /// @param lb2 is the label value for the left baseline point for the second peak (denominator)
  710 + /// @param rb2 is the label value for the right baseline point for the second peak (denominator)
  711 + /// @param pos2 is the label value for the second peak (denominator) position
  712 + /// @param result is a pointer to a pre-allocated array at least X * Y * sizeof(T) in size
638 bool pa_to_ph(double lb1, double rb1, double lab1, double rab1, 713 bool pa_to_ph(double lb1, double rb1, double lab1, double rab1,
639 double lb2, double rb2, double pos, T* result){ 714 double lb2, double rb2, double pos, T* result){
640 715
@@ -657,7 +732,17 @@ public: @@ -657,7 +732,17 @@ public:
657 return true; 732 return true;
658 } 733 }
659 734
660 - //peak area to peak area ratio 735 + /// Compute the ratio between two peak areas.
  736 +
  737 + /// @param lb1 is the label value for the left baseline point for the first peak (numerator)
  738 + /// @param rb1 is the label value for the right baseline point for the first peak (numerator)
  739 + /// @param lab1 is the label value for the left bound (start of the integration) of the first peak (numerator)
  740 + /// @param rab1 is the label value for the right bound (end of the integration) of the first peak (numerator)
  741 + /// @param lb2 is the label value for the left baseline point for the second peak (denominator)
  742 + /// @param rb2 is the label value for the right baseline point for the second peak (denominator)
  743 + /// @param lab2 is the label value for the left bound (start of the integration) of the second peak (denominator)
  744 + /// @param rab2 is the label value for the right bound (end of the integration) of the second peak (denominator)
  745 + /// @param result is a pointer to a pre-allocated array at least X * Y * sizeof(T) in size
661 bool pa_to_pa(double lb1, double rb1, double lab1, double rab1, 746 bool pa_to_pa(double lb1, double rb1, double lab1, double rab1,
662 double lb2, double rb2, double lab2, double rab2, T* result){ 747 double lb2, double rb2, double lab2, double rab2, T* result){
663 748
@@ -680,7 +765,13 @@ public: @@ -680,7 +765,13 @@ public:
680 return true; 765 return true;
681 } 766 }
682 767
683 - //x * f(x) 768 + /// Compute the definite integral of a baseline corrected peak.
  769 +
  770 + /// @param lb is the label value for the left baseline point
  771 + /// @param rb is the label value for the right baseline point
  772 + /// @param lab is the label for the start of the definite integral
  773 + /// @param rab is the label for the end of the definite integral
  774 + /// @param result is a pointer to a pre-allocated array at least X * Y * sizeof(T) in size
684 bool x_area(double lb, double rb, double lab, double rab, T* result){ 775 bool x_area(double lb, double rb, double lab, double rab, T* result){
685 T* lp; //left band pointer 776 T* lp; //left band pointer
686 T* rp; //right band pointer 777 T* rp; //right band pointer
@@ -755,7 +846,13 @@ public: @@ -755,7 +846,13 @@ public:
755 return true; 846 return true;
756 } 847 }
757 848
758 - //centroid point 849 + /// Compute the centroid of a baseline corrected peak.
  850 +
  851 + /// @param lb is the label value for the left baseline point
  852 + /// @param rb is the label value for the right baseline point
  853 + /// @param lab is the label for the start of the peak
  854 + /// @param rab is the label for the end of the peak
  855 + /// @param result is a pointer to a pre-allocated array at least X * Y * sizeof(T) in size
759 bool cpoint(double lb, double rb, double lab, double rab, T* result){ 856 bool cpoint(double lb, double rb, double lab, double rab, T* result){
760 T* p1 = (T*)malloc(R[0] * R[1] * sizeof(T)); 857 T* p1 = (T*)malloc(R[0] * R[1] * sizeof(T));
761 T* p2 = (T*)malloc(R[0] * R[1] * sizeof(T)); 858 T* p2 = (T*)malloc(R[0] * R[1] * sizeof(T));
@@ -776,7 +873,13 @@ public: @@ -776,7 +873,13 @@ public:
776 return true; 873 return true;
777 } 874 }
778 875
779 - //create mask file 876 + /// Create a mask based on a given band and threshold value.
  877 +
  878 + /// All pixels in the
  879 + /// specified band greater than the threshold are true and all pixels less than the threshold are false.
  880 + /// @param mask_band is the band used to specify the mask
  881 + /// @param threshold is the threshold used to determine if the mask value is true or false
  882 + /// @param p is a pointer to a pre-allocated array at least X * Y in size
780 bool build_mask(double mask_band, double threshold, unsigned char* p){ 883 bool build_mask(double mask_band, double threshold, unsigned char* p){
781 884
782 T* temp = (T*)malloc(R[0] * R[1] * sizeof(T)); //allocate memory for the certain band 885 T* temp = (T*)malloc(R[0] * R[1] * sizeof(T)); //allocate memory for the certain band
@@ -794,7 +897,10 @@ public: @@ -794,7 +897,10 @@ public:
794 897
795 } 898 }
796 899
797 - //apply mask 900 + /// Apply a mask file to the BSQ image, setting all values outside the mask to zero.
  901 +
  902 + /// @param outfile is the name of the masked output file
  903 + /// @param p is a pointer to memory of size X * Y, where p(i) = 0 for pixels that will be set to zero.
798 bool apply_mask(std::string outfile, unsigned char* p){ 904 bool apply_mask(std::string outfile, unsigned char* p){
799 905
800 std::ofstream target(outfile.c_str(), std::ios::binary); 906 std::ofstream target(outfile.c_str(), std::ios::binary);
@@ -824,7 +930,9 @@ public: @@ -824,7 +930,9 @@ public:
824 return true; 930 return true;
825 } 931 }
826 932
827 - //calculate the average band of the file 933 + /// Calculate the mean band value (average along B) at each pixel location.
  934 +
  935 + /// @param p is a pointer to memory of size X * Y * sizeof(T) that will store the band averages.
828 bool band_avg(T* p){ 936 bool band_avg(T* p){
829 unsigned long long XY = R[0] * R[1]; 937 unsigned long long XY = R[0] * R[1];
830 //get every pixel and calculate average value 938 //get every pixel and calculate average value
@@ -843,7 +951,10 @@ public: @@ -843,7 +951,10 @@ public:
843 return true; 951 return true;
844 } 952 }
845 953
846 - //calculate the average number of every band 954 + /// Calculate the mean value for all masked (or valid) pixels in a band and returns the average spectrum
  955 +
  956 + /// @param p is a pointer to pre-allocated memory of size [B * sizeof(T)] that stores the mean spectrum
  957 + /// @param mask is a pointer to memory of size [X * Y] that stores the mask value at each pixel location
847 bool avg_band(T*p, unsigned char* mask){ 958 bool avg_band(T*p, unsigned char* mask){
848 unsigned long long XY = R[0] * R[1]; 959 unsigned long long XY = R[0] * R[1];
849 T* temp = (T*)malloc(sizeof(T) * R[2]); 960 T* temp = (T*)malloc(sizeof(T) * R[2]);
@@ -870,7 +981,12 @@ public: @@ -870,7 +981,12 @@ public:
870 free(temp); 981 free(temp);
871 return true; 982 return true;
872 } 983 }
873 - //calculate correlation coefficient matrix 984 +
  985 + /// Calculate the covariance matrix for all masked pixels in the image.
  986 +
  987 + /// @param co is a pointer to pre-allocated memory of size [B * B] that stores the resulting covariance matrix
  988 + /// @param avg is a pointer to memory of size B that stores the average spectrum
  989 + /// @param mask is a pointer to memory of size [X * Y] that stores the mask value at each pixel location
874 bool co_matrix(T* co, T* avg, unsigned char *mask){ 990 bool co_matrix(T* co, T* avg, unsigned char *mask){
875 //memory allocation 991 //memory allocation
876 unsigned long long xy = R[0] * R[1]; 992 unsigned long long xy = R[0] * R[1];
@@ -912,7 +1028,13 @@ public: @@ -912,7 +1028,13 @@ public:
912 } 1028 }
913 1029
914 1030
915 - //crop specified area the of the original file 1031 + /// Crop a region of the image and save it to a new file.
  1032 +
  1033 + /// @param outfile is the file name for the new cropped image
  1034 + /// @param x0 is the lower-left x pixel coordinate to be included in the cropped image
  1035 + /// @param y0 is the lower-left y pixel coordinate to be included in the cropped image
  1036 + /// @param x1 is the upper-right x pixel coordinate to be included in the cropped image
  1037 + /// @param y1 is the upper-right y pixel coordinate to be included in the cropped image
916 bool crop(std::string outfile, unsigned x0, unsigned y0, unsigned x1, unsigned y1){ 1038 bool crop(std::string outfile, unsigned x0, unsigned y0, unsigned x1, unsigned y1){
917 1039
918 //calculate the new number of samples and lines 1040 //calculate the new number of samples and lines
@@ -937,7 +1059,7 @@ public: @@ -937,7 +1059,7 @@ public:
937 } 1059 }
938 1060
939 1061
940 - //close the file 1062 + /// Close the file.
941 bool close(){ 1063 bool close(){
942 file.close(); 1064 file.close();
943 return true; 1065 return true;
@@ -66,9 +66,9 @@ public: @@ -66,9 +66,9 @@ public:
66 std::cout<<"ERROR: page out of range"<<std::endl; 66 std::cout<<"ERROR: page out of range"<<std::endl;
67 return false; 67 return false;
68 } 68 }
69 - 69 + //move the file pointer to the start of the page on disk
70 file.seekg(R[0] * R[1] * page * sizeof(T)); 70 file.seekg(R[0] * R[1] * page * sizeof(T));
71 - 71 + //read the page from disk
72 file.read((char *)p, sizeof(T) * R[0] * R[1]); 72 file.read((char *)p, sizeof(T) * R[0] * R[1]);
73 73
74 return true; 74 return true;
@@ -551,8 +551,6 @@ public: @@ -551,8 +551,6 @@ public:
551 /// @param rb2 is the label value for the right baseline point for the second peak (denominator) 551 /// @param rb2 is the label value for the right baseline point for the second peak (denominator)
552 /// @param pos2 is the label value for the second peak (denominator) position 552 /// @param pos2 is the label value for the second peak (denominator) position
553 /// @param result is a pointer to a pre-allocated array at least X * Y * sizeof(T) in size 553 /// @param result is a pointer to a pre-allocated array at least X * Y * sizeof(T) in size
554 -  
555 -  
556 bool pa_to_ph(double lb1, double rb1, double lab1, double rab1, 554 bool pa_to_ph(double lb1, double rb1, double lab1, double rab1,
557 double lb2, double rb2, double pos, T* result){ 555 double lb2, double rb2, double pos, T* result){
558 556
1 #ifndef STIM_IMAGE_H 1 #ifndef STIM_IMAGE_H
2 #define STIM_IMAGE_H 2 #define STIM_IMAGE_H
3 -#define cimg_use_jpeg //necessary for JPG files 3 +//#define cimg_use_jpeg //necessary for JPG files
4 #include "CImg.h" 4 #include "CImg.h"
5 5
6 #include <iostream> 6 #include <iostream>