#include #include #include #include #include //#include #define NOMINMAX //stim libraries #include #include #include #include #include //#include #include std::vector< stim::image > C; //2D array used to access each mask C[m][p], where m = mask# and p = pixel# //loads spectral features into a feature matrix based on a set of class images (or masks) float* load_features(size_t nC, size_t tP, size_t B, stim::envi E, std::vector< unsigned int > nP){ float progress = 0; //initialize the progress bar variable unsigned long long bytes_fmat = sizeof(float) * tP * B; //calculate the number of bytes in the feature matrix std::cout<<"totalnumber of samples "< nP){ unsigned int* T = (unsigned int*)malloc(tP*sizeof(unsigned int)); //generate an OpenCV vector of responses size_t R_idx = 0; //index into the response array for(size_t c = 0; c < nC; c++){ //for each class image for(unsigned long long l = 0; l < nP[c]; l++){ //assign a response for all pixels of class c loaded in the training matrix T[R_idx + l] = (unsigned int)c+1; } R_idx += nP[c]; //increment the response vector index } return T; } //loads the necessary data for training a random forest classifier std::vector< unsigned int > ga_load_class_images(int argc, stim::arglist args, size_t* nC, size_t* tP){ if(args["classes"].nargs() < 2){ //if fewer than two classes are specified, there's a problem std::cout<<"ERROR: training requires at least two class masks"< nP; size_t num_images = args["classes"].nargs(); //count the number of class images //size_t num_images = args["rf"].nargs(); //count the number of class images //std::vector filenames(num_images); //initialize an array of file names to store the names of the images std::string filename; //allocate space to store the filename for an image for(size_t c = 0; c < num_images; c++){ //for each image filename = args["classes"].as_string(c);; //get the class image file name stim::image image(filename); //load the image //push_training_image(image.channel(0), nC, tP, nP); //push channel zero (all class images are assumed to be single channel) C.push_back(image.channel(0)); unsigned int npixels = (unsigned int)image.channel(0).nnz(); nP.push_back(npixels); //push the number of pixels onto the pixel array *tP += npixels; //add to the running total of pixels *nC = *nC + 1; } return nP; } void display_PixelfeatureNclass(float* F, unsigned int* T, size_t B, size_t Idx){ //display code for debug, displaying Idx th pixel from feature matrix F with all features B std::cout<<"class of pixel["<