From cb455f987f19e090f47b5d856b5863642807c97e Mon Sep 17 00:00:00 2001 From: David Mayerich Date: Wed, 20 May 2015 13:10:21 -0500 Subject: [PATCH] removed old ENVI files --- envi/EnviClose.h | 58 ---------------------------------------------------------- envi/EnviFid.h | 47 ----------------------------------------------- envi/EnviHeader.h | 126 ------------------------------------------------------------------------------------------------------------------------------ envi/EnviOpen.h | 87 --------------------------------------------------------------------------------------- envi/EnviRead.h | 65 ----------------------------------------------------------------- envi/EnviWrite.h | 71 ----------------------------------------------------------------------- envi/envi.h | 118 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--------------- 7 files changed, 103 insertions(+), 469 deletions(-) delete mode 100644 envi/EnviClose.h delete mode 100644 envi/EnviFid.h delete mode 100644 envi/EnviHeader.h delete mode 100644 envi/EnviOpen.h delete mode 100644 envi/EnviRead.h delete mode 100644 envi/EnviWrite.h diff --git a/envi/EnviClose.h b/envi/EnviClose.h deleted file mode 100644 index bb21076..0000000 --- a/envi/EnviClose.h +++ /dev/null @@ -1,58 +0,0 @@ -#ifndef ENVICLOSE_H -#define ENVICLOSE_H - - -#include -#include -#include "EnviHeader.h" -#include "EnviFid.h" -#include "EnviOpen.h" - -// this is to close all the opened files and to create a header file for the written files - -static void EnviClose(EnviFidClass &fid, int dimX=0) -{ - - float* zeroPtr = (float*) malloc(sizeof(float) * fid.header.nF); - memset(zeroPtr, 0, sizeof(float) * fid.header.nF); - - if(fid.mode=="r") - { - fclose(fid.file); - } - - else - { - int totalPixels = fid.header.sX; - int dimY = totalPixels/dimX; - - if(totalPixels % dimX > 0) - { - dimY++; - - int padding = dimY*dimX-totalPixels; - - for(int p=0; p < padding; p++) - fwrite(zeroPtr, sizeof(float), fid.header.nF, fid.file); - } - - //write the calculated values to the header object - fid.header.sX = dimX; - fid.header.sY = dimY; - - - //write the header file to disk - //TODO - - - //close the binary file - fclose(fid.file); - - } - - - - -} -#endif - diff --git a/envi/EnviFid.h b/envi/EnviFid.h deleted file mode 100644 index 57d9a4f..0000000 --- a/envi/EnviFid.h +++ /dev/null @@ -1,47 +0,0 @@ -#ifndef ENVIFID_H -#define ENVIFID_H - -#include -#include -#include -#include -#include -#include "EnviHeader.h" -using namespace std; - -class EnviFidClass -{ -public: - //binary file name - string fileName; - - //header structure - EnviHeaderClass header; - - //valid flag (is the current file valid) - int isValid; - - //file mask (NULL if the whole file is to be read) - char* mask; - - //current position (in pixels) in the file - int filePos; - - //read/write mode ("r" or "w") - string mode; - - //create a variable to store a pointer to the binary file - FILE * file; - - //constructor, set default values - EnviFidClass() - { - isValid = 0; - filePos = 0; - } - - -}; - - -#endif diff --git a/envi/EnviHeader.h b/envi/EnviHeader.h deleted file mode 100644 index b0c93e8..0000000 --- a/envi/EnviHeader.h +++ /dev/null @@ -1,126 +0,0 @@ -#ifndef ENVIHEADER_H -#define ENVIHEADER_H -#include -#include -#include -#include -#include -using namespace std; - -enum InterleaveType {bip, bil, bsq}; -class EnviHeaderClass //"EnviheaderClass" will be used to store data into variables sX, sY, etc. -{ -public: - unsigned int sX; //samples = "sX" - unsigned int sY; //lines = "sY" - unsigned int nF; //bands = "nF" - unsigned int headersize; //header offset = "headersize" - unsigned int datatype; //data type = "datatype" - InterleaveType type; - string units; //wavelength units = "units" (Usully in Wavenumber or Wavelength) - int LoadHeader(string filename) - { - ifstream inFile; - //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 - inFile.open (filename.c_str()); - - //If or not there is a file - if (!inFile) - { - cout<<"Error"<>result; //converts result from previous line - - return result; - } - //retrieves a string parameter from a line of text - string getString(string line) - { - int position; - position=line.find("="); //Finds the position of the equal sign - - string word; //Creates a string for storing word data called "word" - word=line.substr(position+2); //Moves from the position of "=" 2 spaces to the right - //Note: We do not need to convert word using "istringstream" - - return word; - } -}; -#endif diff --git a/envi/EnviOpen.h b/envi/EnviOpen.h deleted file mode 100644 index 7bfb1ee..0000000 --- a/envi/EnviOpen.h +++ /dev/null @@ -1,87 +0,0 @@ -#ifndef ENVIOPEN_H -#define ENVIOPEN_H -#include -#include -#include -#include -#include -#include -#include "EnviHeader.h" -#include "EnviFid.h" -using namespace std; - - - -//return value is incorrect -static EnviFidClass EnviOpen(string filename, char* mask = NULL, string mode = "r", int nBands = 0, int sX = 0) -{ - //create a file ID object - EnviFidClass fid; - - //set the file read/write mode - fid.mode = mode; - - //set the mask (if specified) - fid.mask = mask; - - // load the header file only while reading - if(mode=="r") - { - //load the header file - int error = fid.header.LoadHeader(filename); - - //if the LoadHeader function is not zero, the header is invalid - if (error != 0) - { - fid.isValid = 0; - return fid; - } - - } - - //default header to be used in case of writing a file - else - { - - fid.header.datatype= 4; - fid.header.nF= nBands; - fid.header.sX=0; - fid.header.sY=1; - fid.header.headersize=0; - } - //load the binary file associated with this header - //get the binary file name - - //find the binary file name - - //locate the position of the extension - int pos = filename.find(".hdr"); - string binaryname = filename.substr(0, pos); - //load the binary file using fopen() - //store the resulting FILE pointer in the EnviFidClass variable - mode += "b"; - fid.file = fopen (binaryname.c_str(), mode.c_str()); - if(fid.file == NULL) - { - cout<<"Error opening binary file."< -#include -#include -#include -#include -#include -#include "EnviHeader.h" -#include "EnviFid.h" -#include "EnviOpen.h" -using namespace std; - - -static int EnviRead(float* ptr, int nPixels, EnviFidClass &fid) -{ - //number of values to read from the file - int totalPixels = fid.header.sX * fid.header.sY; - - //ERROR TEST: make sure that fid.file is a valid file pointer - if (fid.file == NULL) - { - cout<<"Binary file isn't open."< -#include -#include "EnviHeader.h" -#include "EnviFid.h" -#include "EnviOpen.h" - -// Take a memory pointer, and copy all of that data to disk. -static int EnviWrite(float* ptr, int npixels, EnviFidClass &fid) -{ - if(fid.mode == "r") return 0; - - //open a binary file for writing - if (fid.file == NULL) - { - cout<<"Binary file isn't open."< threshold (preventing division by small numbers) bool normalize(std::string outfile, double band, double threshold = 0.0){ if(header.interleave == envi_header::BSQ){ //if the infile is bsq file @@ -132,7 +145,10 @@ public: return false; } - //perform baseline correction + /// 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) bool baseline(std::string outfile, std::vector w){ if(header.interleave == envi_header::BSQ){ //if the infile is bsq file @@ -174,7 +190,10 @@ public: } } - //perform conversion + /// 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 bool convert(std::string outfile, stim::envi_header::interleaveType interleave){ if(header.interleave == envi_header::BSQ){ //if the infile is bsq file @@ -275,7 +294,11 @@ public: } - //create a mask based on a band and threshold, save it to p (if p is not NULL) + /// 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 bool build_mask(double mask_band, double threshold, unsigned char* p = NULL) { if(header.interleave == envi_header::BSQ){ //if the infile is bsq file @@ -308,7 +331,10 @@ public: return false; } - //apply mask + /// 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) bool apply_mask(std::string outfile, unsigned char* p) { @@ -346,7 +372,15 @@ public: return false; } - //peak height to peak height ratio + /// 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 bool ph_to_ph(double lb1, double rb1, double pos1, double lb2, double rb2, double pos2, void * result){ if(header.interleave == envi_header::BSQ){ //if the infile is bsq file if(header.data_type ==envi_header::float32) @@ -382,7 +416,15 @@ public: return false; } - //peak area to peak height ratio + /// 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 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) @@ -418,7 +460,17 @@ public: return false; } - //peak area to peak area ratio + /// 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 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 @@ -455,7 +507,13 @@ public: return false; } - //center of gravity + /// 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 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) @@ -491,6 +549,7 @@ public: return false; } + /// Closes the ENVI file. bool close(){ if(header.interleave == envi_header::BSQ){ if(header.data_type ==envi_header::float32) @@ -526,7 +585,11 @@ public: } return false; } - //get one pixel from binary file + + /// 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. bool pixel(void * p, unsigned n){ if(header.interleave == envi_header::BSQ){ if(header.data_type ==envi_header::float32) @@ -561,6 +624,7 @@ public: return false; } + /// Saves a header file describing the current ENVI file parameters. bool save_header(std::string filename){ //save the header file here @@ -569,6 +633,10 @@ public: return true; } + /// 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. bool band(void* ptr, double wavelength){ if(header.interleave == envi_header::BSQ){ //if the infile is bsq file @@ -604,6 +672,10 @@ public: return false; } + /// 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. bool band_index(void* ptr, unsigned int b){ if (header.interleave == envi_header::BSQ){ //if the infile is bsq file if (header.data_type == envi_header::float32) @@ -638,7 +710,10 @@ public: return false; } - //load mask from maskfile and save it into memory + /// 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 bool load_mask(unsigned char * mask, std::string maskname){ //open the mask file stim::image mask_image(maskname); @@ -693,7 +768,10 @@ public: return true; } - //calculate band average + /// 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 bool avg_band(void * p, unsigned char* mask){ if (header.interleave == envi_header::BSQ){ if (header.data_type == envi_header::float32) @@ -728,7 +806,11 @@ public: return false; } - //calculate correlation coefficient matrix with mask + /// 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 bool co_matrix(void* co, void* avg, unsigned char* mask){ if (header.interleave == envi_header::BSQ){ if (header.data_type == envi_header::float32) @@ -764,7 +846,13 @@ public: } - //crop specified area the of the original file + /// 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 bool crop(std::string outfile,unsigned x0, unsigned y0, unsigned x1, unsigned y1){ if (header.interleave == envi_header::BSQ){ -- libgit2 0.21.4