// ###################################################################### int BitObject::reset(const Image<byte>& img, const Point2D<int> location, const Rectangle boundingBox, const byte threshold) { ASSERT(img.initialized()); // first, reset everything to defaults freeMem(); itsBoundingBox = boundingBox; Image<byte> dest; // threshold to get binary object dest = highThresh(img, threshold, byte(1)); // count all foreground pixels as area int area = countParticles(dest, byte(1)); LINFO("area %d", area); // no object found? return -1 if (area == 0) { itsCentroidXY.reset(location); return area; } // set the dimensions of the original image itsImageDims = img.getDims(); // crop the object mask from the flooding destination itsObjectMask = crop(dest, itsBoundingBox); // get the area, the centroid, and the bounding box std::vector<float> sumx, sumy; itsArea = (int)sumXY(itsObjectMask, sumx, sumy); //itsStdDev = stdev(luminance(img)); int firstX, lastX, firstY, lastY; float cX, cY; bool success = (getCentroidFirstLast(sumx, cX, firstX, lastX) | getCentroidFirstLast(sumy, cY, firstY, lastY)); itsCentroidXY.reset(cX,cY); if (!success) LFATAL("determining the centroid failed"); if ((firstX != 0) || (lastX != itsObjectMask.getWidth()-1) || (firstY != 0) || (lastY != itsObjectMask.getHeight()-1)) LFATAL("boundary box doesn't match the one from flooding"); itsCentroidXY += Vector2D(itsBoundingBox.left(),itsBoundingBox.top()); return itsArea; }
//! read particles matching a specific PDG name and run id from supplied // file. Must supply particle mass ourselves... EventArray* readParticles(const std::string& file, const std::string& particle, const double mass, const std::string& runId) { int resultCode(0); size_t numberOf(0); resultCode = countParticles(file, particle, runId, numberOf); if (resultCode) { std::cerr << "[pp6day3_muonanalysis:error] Failed to count particles in file " << file << std::endl; return 0; } // With number of particles known, create the appropriately sized // EventArray and fill it return createParticles(file, numberOf, particle, mass, runId); }