Example #1
0
// ######################################################################
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;
}
Example #2
0
// ######################################################################
Image<byte> BitObject::reset(const Image<byte>& img, const Point2D<int> location,
                             const byte threshold)
{
  ASSERT(img.initialized());

  // first, reset everything to defaults
  freeMem();

  // now, flood img to get the object
  Image<byte> dest;
 
  int area = floodCleanBB(img, dest, location, threshold, 
                          byte(1), itsBoundingBox);

  // no object found? return -1
  if (area == -1)
    {
      LINFO("no object found");
      itsCentroidXY.reset(location);
      return Image<byte>();
    }

  // 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(itsObjectMask));

  if (area != itsArea)
    LFATAL("area %i doesn't match the one from flooding %i", itsArea, area);

  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 dest;
}
Example #3
0
// ######################################################################
int BitObject::reset(const Image<byte>& img)
{
  ASSERT(img.initialized());

  // first, reset everything to defaults
  freeMem();

  // set the dimensions of the original image
  itsImageDims = img.getDims();

  // get the area, stddev, centroid, and the bounding box
  std::vector<float> sumx, sumy;
  itsArea = (int)sumXY(img, sumx, sumy);

  if (itsArea == 0) 
    {
      freeMem();
      return -1;
    }

  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)
    {
      freeMem();
      return -1;
    }

  itsBoundingBox = Rectangle::tlbrI(firstY, firstX, lastY, lastX);

  // cut out the object mask
  itsObjectMask = crop(img, itsBoundingBox);

  LINFO("BB: size: %i; %s; dims: %s",itsBoundingBox.width()*itsBoundingBox.height(),
      toStr(itsBoundingBox).data(),toStr(itsObjectMask.getDims()).data());

  return itsArea;
}
Example #4
0
double LinearRegression::top()
{
    double t = sumXY()-((sumX()*sumY())/ (double)data.size());
    return(t);
}