#include #include #include #include #include // // A helper function which reads, from a ParameterFile object, a // matrix of the form (name rows cols ....data in row major order...) // Returns an invalid matrix if it fails (prints something) // VISMatrix readMatrix(VPF::ParameterFile pf, const char* name) { int r, c, j; float float_tmp; int int_tmp; // declare the return object VISMatrix matrix; // get the number rows and cols boolean good=true; if (VPF::set(r, pf[name][0]) != VPF::VALID) good=false; if (VPF::set(c, pf[name][1]) != VPF::VALID) good=false; if (!good) { cout << "ImplicitModel::bad matrix " << name << endl; return VISMatrix(); } // create the return object matrix = VISMatrix(r,c); // read the data for (j = 0; j < r*c; j++) if (VPF::set(float_tmp, pf[name][j+2]) == VPF::VALID) matrix.poke(j/c, j%c) = float_tmp; else if (VPF::set(int_tmp, pf[name][j+2]) == VPF::VALID) matrix.poke(j/c, j%c) = (float)int_tmp; else good=false; if (!good) { cout << "ImplicitModel::bad matrix " << name << endl; return VISMatrix(); } return(matrix); } // // Program reads in a parameter file to specify a mosaicing operation // in accordance with Project 2. The format of the file is ... // //CORRESPONDENCE_MATRIX Matrix //(square) --- rows and cols are image numbers, and upper half of this //matrix gives correspondences available //IMAGE_FILE_ //Gives image file name for the Nth image // // CORRESPONDENCES__ 2 _ and it // must be the same size // // TARGET_IMAGE specify which target image coordinate system to // produce the final result main(int argc, char** argv) { VISImageFile im_file; if (argc < 2) { cout << "usage: readparams parameterfile" << endl; exit(-1); } // create parameter file from the given argument VPF::ParameterFile pf(argv[1]); // read in the matrix of correspondences for which we will look VISMatrix correspondence_matrix = readMatrix(pf, "CORRESPONDENCE_MATRIX"); // print it out just for debugging cout << "correspondence matrix " << endl << correspondence_matrix << endl; // the number of images is the size of this matrix (one row/col per // image) int num_images = correspondence_matrix.c(); int i; // read in the image and put them in an array VISArray< VISImage< float > > images; char filename[80], keyword[80]; for (i = 0; i < num_images; i++) { sprintf(keyword, "%s_%d", "IMAGE_FILE", i); if (VPF::set(filename, pf[keyword][0]) != VPF::VALID) { cout << "no image file " << keyword << " in param file: " << argv[1] << endl; exit(-1); } images.poke(i) = VISImage(im_file.read(filename)); if (!(images.peek(i)).isValid()) { cout << "bad image file " << filename << " in param file: " << argv[1] << endl; exit(-1); } } char atlas_filename[80], intensity_var_filename[80], shape_var_filename[80]; if (VPF::set(atlas_filename, pf["ATLAS_FILE_OUTPUT"][0]) != VPF::VALID) { cout << "no ATLAS_FILE_OUTPUT in param file: " << argv[1] << endl; exit(-1); } }