/**
   * Computes the mean squared error (MSE) between the two images.
   *
   * @param imgA first image. Not modified.
   * @param imgB second image. Not modified.
   * @return error between the two images.
   */
  public static double computeMeanSquaredError(ImageSInt32 imgA, ImageSInt32 imgB) {
    final int h = imgA.getHeight();
    final int w = imgA.getWidth();

    double total = 0;

    for (int y = 0; y < h; y++) {
      for (int x = 0; x < w; x++) {
        double difference = imgA.get(x, y) - imgB.get(x, y);
        total += difference * difference;
      }
    }

    return total / (w * h);
  }
示例#2
0
 // convert a blob image into quadrilaterals bounding each of the blobs
 public static List<List<Point2D_F64>> quadsFromBlobs(ImageSInt32 blobImage, int numBlobs) {
   @SuppressWarnings("unchecked")
   List<List<Point2D_F64>> points = new ArrayList();
   for (int i = 1; i < numBlobs; i++) {
     // TODO: make fast
     ArrayList<Point2D_F64> inClass = new ArrayList<Point2D_F64>();
     for (int x = 0; x < blobImage.getWidth(); x++) {
       for (int y = 0; y < blobImage.getHeight(); y++) {
         if (blobImage.get(x, y) == i) {
           inClass.add(new Point2D_F64(x, y));
         }
       }
     }
     // Transform blobs into quadrilaterals, ignoring blobs of very small size
     if (inClass.size() > BLOB_SIZE_THRESHOLD) {
       points.add(
           boofcv.alg.feature.detect.quadblob.FindBoundingQuadrilateral.findCorners(inClass));
     }
   }
   return points;
 }