int main(int argc, char **argv) { try { // Generate some names vector<string> names; for (int i = 0; i < NameN; ++i) names.push_back (to_string (rand())); // The name id per pixels vector<vector<int> > pixelToNames (Width*Height); // Generate a random image for (auto &pixel : pixelToNames) { const int samplesN = rand ()%(SamplesMax+1); for (int s = 0; s < samplesN; ++s) pixel.push_back (rand()%NameN); } cout << "Fill a mask id map" << endl; Builder builder (Width, Height, {"R","G","B"}); // Fill the builder for (int y = 0; y < Height; ++y) for (int x = 0; x < Width; ++x) { const vector<int> &pixel = pixelToNames[x+y*Width]; const float weight = 1.f/(float)pixel.size (); const float values[3] = {weight, weight*0.75f, weight*0.5f}; for (size_t s = 0; s < pixel.size (); ++s) builder.addCoverage (x, y, pixel[s], values); } { // Build and write a mask cout << "Build the mask id map" << endl; const Mask mask (builder, names); cout << "Write the mask" << endl; mask.write (filename); } // Read a mask cout << "Read the mask" << endl; Mask mask; mask.read (filename); const int R = mask.findSlice ("R"); const int G = mask.findSlice ("G"); const int B = mask.findSlice ("B"); // Check the mask cout << "Check the mask" << endl; // Build the mask of every name for (int i = 0; i < NameN; ++i) { // Create a query for this name Query query (&mask, [&names,i](const char *name){return names[i] == name;}); for (int y=0; y<Height; ++y) for (int x=0; x<Width; ++x) { // Recompute the coverage from the original image const vector<int> &pixel = pixelToNames[x+y*Width]; const float weight = 1.f/(float)pixel.size (); const float values[3] = {weight, weight*0.75f, weight*0.5f}; float weightSum[3] = {0, 0, 0}; for (size_t s = 0; s < pixel.size (); ++s) { weightSum[0] += names[pixel[s]] == names[i] ? (half)values[0] : (half)0; weightSum[1] += names[pixel[s]] == names[i] ? (half)values[1] : (half)0; weightSum[2] += names[pixel[s]] == names[i] ? (half)values[2] : (half)0; } // The coverage from the file std::vector<float> coverage; query.getSliceData (x, y, coverage); Errors += int((half)weightSum[0] != (half)coverage[R]); Errors += int((half)weightSum[1] != (half)coverage[G]); Errors += int((half)weightSum[2] != (half)coverage[B]); } } } catch (runtime_error &e) { cout << e.what () << endl; remove (filename); return -1; } remove (filename); cout << Errors << " error(s)" << endl; return Errors; }
void readParams() { // Get parameters ======================================================= fn1 = getParam("--i1"); fn2 = getParam("--i2"); rot0 = getDoubleParam("--rot",0); rotF = getDoubleParam("--rot",1); step_rot = getDoubleParam("--rot",2); tilt0 = getDoubleParam("--tilt",0); tiltF = getDoubleParam("--tilt",1); step_tilt = getDoubleParam("--tilt",2); psi0 = getDoubleParam("--psi",0); psiF = getDoubleParam("--psi",1); step_psi = getDoubleParam("--psi",2); scale0 = getDoubleParam("--scale",0); scaleF = getDoubleParam("--scale",1); step_scale = getDoubleParam("--scale",2); grey_scale0 = getDoubleParam("--grey_scale",0); grey_scaleF = getDoubleParam("--grey_scale",1); step_grey = getDoubleParam("--grey_scale",2); grey_shift0 = getDoubleParam("--grey_shift",0); grey_shiftF = getDoubleParam("--grey_shift",1); step_grey_shift = getDoubleParam("--grey_shift",2); z0 = getDoubleParam("-z",0); zF = getDoubleParam("-z",1); step_z = getDoubleParam("-z",2); y0 = getDoubleParam("-y",0); yF = getDoubleParam("-y",1); step_y = getDoubleParam("-y",2); x0 = getDoubleParam("-x",0); xF = getDoubleParam("-x",1); step_x = getDoubleParam("-x",2); mask_enabled = checkParam("--mask"); if (mask_enabled) mask.read(argc, argv); usePowell = checkParam("--local"); useFRM = checkParam("--frm"); if (useFRM) { maxFreq=getDoubleParam("--frm",0); maxShift=getIntParam("--frm",1); } onlyShift = checkParam("--onlyShift"); if (step_rot == 0) step_rot = 1; if (step_tilt == 0) step_tilt = 1; if (step_psi == 0) step_psi = 1; if (step_scale == 0) step_scale = 1; if (step_grey == 0) step_grey = 1; if (step_grey_shift == 0) step_grey_shift = 1; if (step_z == 0) step_z = 1; if (step_y == 0) step_y = 1; if (step_x == 0) step_x = 1; tell = checkParam("--show_fit"); apply = checkParam("--apply"); fnOut = getParam("--apply"); if (checkParam("--covariance")) { params.alignment_method = COVARIANCE; } else if (checkParam("--least_squares")) { params.alignment_method = LEAST_SQUARES; } else { params.alignment_method = COVARIANCE; } }