compute method

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

Implementation

@override
double compute(img.Image image) {
  double sum = 0;
  double sumSquared = 0;
  double contrastSum = 0;

  final width = image.width;
  final height = image.height;

  for (int y = 1; y < height - 1; y++) {
    for (int x = 1; x < width - 1; x++) {
      final pixel = pixelToGray(image, x, y);
      final contrast = _localContrast(image, x, y);

      sum += pixel;
      sumSquared += pixel * pixel;
      contrastSum += contrast;
    }
  }

  double mean = sum / ((width - 2) * (height - 2));
  double variance =
      (sumSquared / ((width - 2) * (height - 2))) - (mean * mean);
  double adjustedVariance =
      variance / (contrastSum / ((width - 2) * (height - 2)));

  return adjustedVariance;
}