Commit a08c98c3577cf3e6a50ce47e4eb8bbf4df57fbfd
1 parent
5853ce9b
finished documentation of bsq.h
Showing
1 changed file
with
43 additions
and
29 deletions
Show diff stats
envi/bsq.h
@@ -37,7 +37,7 @@ public: | @@ -37,7 +37,7 @@ public: | ||
37 | //using binary<T>::getSlice; | 37 | //using binary<T>::getSlice; |
38 | using binary<T>::R; | 38 | using binary<T>::R; |
39 | 39 | ||
40 | - ///This function opens a data file for reading using the class interface. | 40 | + /// Open a data file for reading using the class interface. |
41 | 41 | ||
42 | /// @param filename is the name of the binary file on disk | 42 | /// @param filename is the name of the binary file on disk |
43 | /// @param X is the number of samples along dimension 1 | 43 | /// @param X is the number of samples along dimension 1 |
@@ -56,7 +56,7 @@ public: | @@ -56,7 +56,7 @@ public: | ||
56 | 56 | ||
57 | } | 57 | } |
58 | 58 | ||
59 | - ///This function retrieves a single band (based on index) and stores it in pre-allocated memory. | 59 | + /// Retrieve a single band (based on index) and stores it in pre-allocated memory. |
60 | 60 | ||
61 | /// @param p is a pointer to an allocated region of memory at least X * Y * sizeof(T) in size. | 61 | /// @param p is a pointer to an allocated region of memory at least X * Y * sizeof(T) in size. |
62 | /// @param page <= B is the integer number of the band to be copied. | 62 | /// @param page <= B is the integer number of the band to be copied. |
@@ -74,7 +74,7 @@ public: | @@ -74,7 +74,7 @@ public: | ||
74 | return true; | 74 | return true; |
75 | } | 75 | } |
76 | 76 | ||
77 | - ///This function retrieves a single band (by numerical label) and stores it in pre-allocated memory. | 77 | + /// Retrieve a single band (by numerical label) and stores it in pre-allocated memory. |
78 | 78 | ||
79 | /// @param p is a pointer to an allocated region of memory at least X * Y * sizeof(T) in size. | 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. | 80 | /// @param wavelength is a floating point value (usually a wavelength in spectral data) used as a label for the band to be copied. |
@@ -131,7 +131,7 @@ public: | @@ -131,7 +131,7 @@ public: | ||
131 | return true; | 131 | return true; |
132 | } | 132 | } |
133 | 133 | ||
134 | - ///This function retrieves a single spectrum (B-axis line) at a given (x, y) location and stores it in pre-allocated memory. | 134 | + /// Retrieve a single spectrum (B-axis line) at a given (x, y) location and stores it in pre-allocated memory. |
135 | 135 | ||
136 | /// @param p is a pointer to pre-allocated memory at least B * sizeof(T) in size. | 136 | /// @param p is a pointer to pre-allocated memory at least B * sizeof(T) in size. |
137 | /// @param x is the x-coordinate (dimension 1) of the spectrum. | 137 | /// @param x is the x-coordinate (dimension 1) of the spectrum. |
@@ -155,7 +155,7 @@ public: | @@ -155,7 +155,7 @@ public: | ||
155 | return true; | 155 | return true; |
156 | } | 156 | } |
157 | 157 | ||
158 | - ///This function retrieves a single pixel and stores it in pre-allocated memory. | 158 | + /// Retrieve a single pixel and stores it in pre-allocated memory. |
159 | 159 | ||
160 | /// @param p is a pointer to pre-allocated memory at least sizeof(T) in size. | 160 | /// @param p is a pointer to pre-allocated memory at least sizeof(T) in size. |
161 | /// @param n is an integer index to the pixel using linear array indexing. | 161 | /// @param n is an integer index to the pixel using linear array indexing. |
@@ -177,7 +177,7 @@ public: | @@ -177,7 +177,7 @@ public: | ||
177 | return true; | 177 | return true; |
178 | } | 178 | } |
179 | 179 | ||
180 | - ///This function performs baseline correction given a list of baseline points and stores the result in a new BSQ file. | 180 | + /// Perform baseline correction given a list of baseline points and stores the result in a new BSQ file. |
181 | 181 | ||
182 | /// @param outname is the name of the output file used to store the resulting baseline-corrected data. | 182 | /// @param outname is the name of the output file used to store the resulting baseline-corrected data. |
183 | /// @param wls is the list of baseline points based on band labels. | 183 | /// @param wls is the list of baseline points based on band labels. |
@@ -282,7 +282,7 @@ public: | @@ -282,7 +282,7 @@ public: | ||
282 | return true; | 282 | return true; |
283 | } | 283 | } |
284 | 284 | ||
285 | - ///This function normalizes all spectra based on the value of a single band, storing the result in a new BSQ file. | 285 | + /// Normalize all spectra based on the value of a single band, storing the result in a new BSQ file. |
286 | 286 | ||
287 | /// @param outname is the name of the output file used to store the resulting baseline-corrected data. | 287 | /// @param outname is the name of the output file used to store the resulting baseline-corrected data. |
288 | /// @param w is the label specifying the band that the hyperspectral image will be normalized to. | 288 | /// @param w is the label specifying the band that the hyperspectral image will be normalized to. |
@@ -325,7 +325,7 @@ public: | @@ -325,7 +325,7 @@ public: | ||
325 | return true; | 325 | return true; |
326 | } | 326 | } |
327 | 327 | ||
328 | - ///This function converts the current BSQ file to a BIP file with the specified file name. | 328 | + /// Convert the current BSQ file to a BIP file with the specified file name. |
329 | 329 | ||
330 | /// @param outname is the name of the output BIP file to be saved to disk. | 330 | /// @param outname is the name of the output BIP file to be saved to disk. |
331 | bool bip(std::string outname) | 331 | bool bip(std::string outname) |
@@ -348,7 +348,7 @@ public: | @@ -348,7 +348,7 @@ public: | ||
348 | return true; | 348 | return true; |
349 | } | 349 | } |
350 | 350 | ||
351 | - ///This function converts the current BSQ file to a BIL file with the specified file name. | 351 | + /// Convert the current BSQ file to a BIL file with the specified file name. |
352 | 352 | ||
353 | /// @param outname is the name of the output BIL file to be saved to disk. | 353 | /// @param outname is the name of the output BIL file to be saved to disk. |
354 | bool bil(std::string outname) | 354 | bool bil(std::string outname) |
@@ -381,7 +381,7 @@ public: | @@ -381,7 +381,7 @@ public: | ||
381 | return true; | 381 | return true; |
382 | } | 382 | } |
383 | 383 | ||
384 | - /// This function returns a baseline corrected band given two adjacent baseline points and their bands. The result is stored in a pre-allocated array. | 384 | + /// Return a baseline corrected band given two adjacent baseline points and their bands. The result is stored in a pre-allocated array. |
385 | 385 | ||
386 | /// @param lb is the label value for the left baseline point | 386 | /// @param lb is the label value for the left baseline point |
387 | /// @param rb is the label value for the right baseline point | 387 | /// @param rb is the label value for the right baseline point |
@@ -402,7 +402,7 @@ public: | @@ -402,7 +402,7 @@ public: | ||
402 | return true; | 402 | return true; |
403 | } | 403 | } |
404 | 404 | ||
405 | - ///This function returns a baseline corrected band given two adjacent baseline points. The result is stored in a pre-allocated array. | 405 | + /// Return a baseline corrected band given two adjacent baseline points. The result is stored in a pre-allocated array. |
406 | 406 | ||
407 | /// @param lb is the label value for the left baseline point | 407 | /// @param lb is the label value for the left baseline point |
408 | /// @param rb is the label value for the right baseline point | 408 | /// @param rb is the label value for the right baseline point |
@@ -428,7 +428,7 @@ public: | @@ -428,7 +428,7 @@ public: | ||
428 | } | 428 | } |
429 | 429 | ||
430 | 430 | ||
431 | - ///This function calculates the area under the spectrum between two specified points and stores the result in a pre-allocated array. | 431 | + /// Calculate the area under the spectrum between two specified points and stores the result in a pre-allocated array. |
432 | 432 | ||
433 | /// @param lb is the label value for the left baseline point | 433 | /// @param lb is the label value for the left baseline point |
434 | /// @param rb is the label value for the right baseline point | 434 | /// @param rb is the label value for the right baseline point |
@@ -512,7 +512,7 @@ public: | @@ -512,7 +512,7 @@ public: | ||
512 | return true; | 512 | return true; |
513 | } | 513 | } |
514 | 514 | ||
515 | - /// This function computes the ratio of two baseline-corrected peaks. The result is stored in a pre-allocated array. | 515 | + /// Compute the ratio of two baseline-corrected peaks. The result is stored in a pre-allocated array. |
516 | 516 | ||
517 | /// @param lb1 is the label value for the left baseline point for the first peak (numerator) | 517 | /// @param lb1 is the label value for the left baseline point for the first peak (numerator) |
518 | /// @param rb1 is the label value for the right baseline point for the first peak (numerator) | 518 | /// @param rb1 is the label value for the right baseline point for the first peak (numerator) |
@@ -542,7 +542,7 @@ public: | @@ -542,7 +542,7 @@ public: | ||
542 | return true; | 542 | return true; |
543 | } | 543 | } |
544 | 544 | ||
545 | - /// This function computes the ratio between a peak area and peak height. | 545 | + /// Compute the ratio between a peak area and peak height. |
546 | 546 | ||
547 | /// @param lb1 is the label value for the left baseline point for the first peak (numerator) | 547 | /// @param lb1 is the label value for the left baseline point for the first peak (numerator) |
548 | /// @param rb1 is the label value for the right baseline point for the first peak (numerator) | 548 | /// @param rb1 is the label value for the right baseline point for the first peak (numerator) |
@@ -575,7 +575,7 @@ public: | @@ -575,7 +575,7 @@ public: | ||
575 | return true; | 575 | return true; |
576 | } | 576 | } |
577 | 577 | ||
578 | - /// This function computes the ratio between two peak areas. | 578 | + /// Compute the ratio between two peak areas. |
579 | 579 | ||
580 | /// @param lb1 is the label value for the left baseline point for the first peak (numerator) | 580 | /// @param lb1 is the label value for the left baseline point for the first peak (numerator) |
581 | /// @param rb1 is the label value for the right baseline point for the first peak (numerator) | 581 | /// @param rb1 is the label value for the right baseline point for the first peak (numerator) |
@@ -608,7 +608,7 @@ public: | @@ -608,7 +608,7 @@ public: | ||
608 | return true; | 608 | return true; |
609 | } | 609 | } |
610 | 610 | ||
611 | - /// This function computes the definite integral of a baseline corrected peak. | 611 | + /// Compute the definite integral of a baseline corrected peak. |
612 | 612 | ||
613 | /// @param lb is the label value for the left baseline point | 613 | /// @param lb is the label value for the left baseline point |
614 | /// @param rb is the label value for the right baseline point | 614 | /// @param rb is the label value for the right baseline point |
@@ -689,7 +689,7 @@ public: | @@ -689,7 +689,7 @@ public: | ||
689 | return true; | 689 | return true; |
690 | } | 690 | } |
691 | 691 | ||
692 | - /// This function computes the centroid of a baseline corrected peak. | 692 | + /// Compute the centroid of a baseline corrected peak. |
693 | 693 | ||
694 | /// @param lb is the label value for the left baseline point | 694 | /// @param lb is the label value for the left baseline point |
695 | /// @param rb is the label value for the right baseline point | 695 | /// @param rb is the label value for the right baseline point |
@@ -716,7 +716,7 @@ public: | @@ -716,7 +716,7 @@ public: | ||
716 | return true; | 716 | return true; |
717 | } | 717 | } |
718 | 718 | ||
719 | - /// This function creates a mask based on a given band and threshold value. | 719 | + /// Create a mask based on a given band and threshold value. |
720 | 720 | ||
721 | /// All pixels in the | 721 | /// All pixels in the |
722 | /// specified band greater than the threshold are true and all pixels less than the threshold are false. | 722 | /// specified band greater than the threshold are true and all pixels less than the threshold are false. |
@@ -740,7 +740,7 @@ public: | @@ -740,7 +740,7 @@ public: | ||
740 | 740 | ||
741 | } | 741 | } |
742 | 742 | ||
743 | - /// This function applies a mask file to the BSQ image, setting all values outside the mask to zero. | 743 | + /// Apply a mask file to the BSQ image, setting all values outside the mask to zero. |
744 | 744 | ||
745 | /// @param outfile is the name of the masked output file | 745 | /// @param outfile is the name of the masked output file |
746 | /// @param p is a pointer to memory of size X * Y, where p(i) = 0 for pixels that will be set to zero. | 746 | /// @param p is a pointer to memory of size X * Y, where p(i) = 0 for pixels that will be set to zero. |
@@ -772,7 +772,7 @@ public: | @@ -772,7 +772,7 @@ public: | ||
772 | return true; | 772 | return true; |
773 | } | 773 | } |
774 | 774 | ||
775 | - /// This function calculates the mean band value (average along B) at each pixel location. | 775 | + /// Calculate the mean band value (average along B) at each pixel location. |
776 | 776 | ||
777 | /// @param p is a pointer to memory of size X * Y * sizeof(T) that will store the band averages. | 777 | /// @param p is a pointer to memory of size X * Y * sizeof(T) that will store the band averages. |
778 | bool band_avg(T* p){ | 778 | bool band_avg(T* p){ |
@@ -794,22 +794,26 @@ public: | @@ -794,22 +794,26 @@ public: | ||
794 | return true; | 794 | return true; |
795 | } | 795 | } |
796 | 796 | ||
797 | - //calculate the average number of every band | 797 | + /// Calculate the mean value for all masked (or valid) pixels in a band and returns the average spectrum |
798 | + | ||
799 | + /// @param p is a pointer to pre-allocated memory of size [B * sizeof(T)] that stores the mean spectrum | ||
800 | + /// @param mask is a pointer to memory of size [X * Y] that stores the mask value at each pixel location | ||
798 | bool avg_band(T*p, unsigned char* mask){ | 801 | bool avg_band(T*p, unsigned char* mask){ |
799 | unsigned long long XY = R[0] * R[1]; | 802 | unsigned long long XY = R[0] * R[1]; |
800 | - unsigned count = 0; //number of vaild pixel in a band | 803 | + unsigned count = 0; //count will store the number of masked pixels |
801 | T* temp = (T*)malloc(sizeof(T) * XY); | 804 | T* temp = (T*)malloc(sizeof(T) * XY); |
802 | - //calculate valid pixel number | 805 | + //calculate this loop counts the number of true pixels in the mask |
803 | for (unsigned j = 0; j < XY; j++){ | 806 | for (unsigned j = 0; j < XY; j++){ |
804 | if (mask[j] != 0){ | 807 | if (mask[j] != 0){ |
805 | count++; | 808 | count++; |
806 | } | 809 | } |
807 | } | 810 | } |
808 | - //calculate average of a band | 811 | + //this loops goes through each band in B (R[2]) |
812 | + // masked (or valid) pixels from that band are averaged and the average is stored in p | ||
809 | for (unsigned i = 0; i < R[2]; i++){ | 813 | for (unsigned i = 0; i < R[2]; i++){ |
810 | p[i] = 0; | 814 | p[i] = 0; |
811 | - band_index(temp, i); | ||
812 | - for (unsigned j = 0; j < XY; j++){ | 815 | + band_index(temp, i); //get the band image and store it in temp |
816 | + for (unsigned j = 0; j < XY; j++){ //loop through temp, averaging valid pixels | ||
813 | if (mask[j] != 0){ | 817 | if (mask[j] != 0){ |
814 | p[i] += temp[j] / (T)count; | 818 | p[i] += temp[j] / (T)count; |
815 | } | 819 | } |
@@ -819,7 +823,11 @@ public: | @@ -819,7 +823,11 @@ public: | ||
819 | return true; | 823 | return true; |
820 | } | 824 | } |
821 | 825 | ||
822 | - //calculate correlated matrix | 826 | + /// Calculate the covariance matrix for all masked pixels in the image. |
827 | + | ||
828 | + /// @param co is a pointer to pre-allocated memory of size [B * B] that stores the resulting covariance matrix | ||
829 | + /// @param avg is a pointer to memory of size B that stores the average spectrum | ||
830 | + /// @param mask is a pointer to memory of size [X * Y] that stores the mask value at each pixel location | ||
823 | bool co_matrix(T* co, T* avg, unsigned char *mask){ | 831 | bool co_matrix(T* co, T* avg, unsigned char *mask){ |
824 | //memory allocation | 832 | //memory allocation |
825 | unsigned long long xy = R[0] * R[1]; | 833 | unsigned long long xy = R[0] * R[1]; |
@@ -857,7 +865,13 @@ public: | @@ -857,7 +865,13 @@ public: | ||
857 | } | 865 | } |
858 | 866 | ||
859 | 867 | ||
860 | - //crop specified area the of the original file | 868 | + /// Crop a region of the image and save it to a new file. |
869 | + | ||
870 | + /// @param outfile is the file name for the new cropped image | ||
871 | + /// @param x0 is the lower-left x pixel coordinate to be included in the cropped image | ||
872 | + /// @param y0 is the lower-left y pixel coordinate to be included in the cropped image | ||
873 | + /// @param x1 is the upper-right x pixel coordinate to be included in the cropped image | ||
874 | + /// @param y1 is the upper-right y pixel coordinate to be included in the cropped image | ||
861 | bool crop(std::string outfile, unsigned x0, unsigned y0, unsigned x1, unsigned y1){ | 875 | bool crop(std::string outfile, unsigned x0, unsigned y0, unsigned x1, unsigned y1){ |
862 | 876 | ||
863 | //calculate the new number of samples and lines | 877 | //calculate the new number of samples and lines |
@@ -886,7 +900,7 @@ public: | @@ -886,7 +900,7 @@ public: | ||
886 | } | 900 | } |
887 | 901 | ||
888 | 902 | ||
889 | - //close the file | 903 | + /// Close the file. |
890 | bool close(){ | 904 | bool close(){ |
891 | file.close(); | 905 | file.close(); |
892 | return true; | 906 | return true; |