compute method

  1. @override
double compute(
  1. Image image
)
override

Implementation

@override
double compute(img.Image image) {
  final width = image.width;
  final height = image.height;
  final data = List<double>.generate(
      width * height, (i) => pixelToGray(image, i % width, i ~/ width));

  double mean = data.reduce((a, b) => a + b) / data.length;
  double variance =
      data.map((x) => (x - mean) * (x - mean)).reduce((a, b) => a + b) /
          data.length;

  double autoCorrelation = 0.0;
  for (int offset = 1; offset < width; offset++) {
    double sum = 0.0;
    for (int y = 0; y < height; y++) {
      for (int x = 0; x < width - offset; x++) {
        sum += data[y * width + x] * data[y * width + (x + offset)];
      }
    }
    autoCorrelation += sum / (width * height);
  }

  return autoCorrelation / variance;
}