compute method
double
compute(
- Image image
)
override
Implementation
@override
double compute(img.Image image) {
final width = image.width;
final height = image.height;
final data = Float64List(width * height);
for (int y = 0; y < height; y++) {
for (int x = 0; x < width; x++) {
data[y * width + x] = pixelToGray(image, x, y);
}
}
List<double> haarTransform(List<double> data, int size) {
if (size == 1) return data;
final halfSize = size ~/ 2;
final result = List<double>.generate(size, (i) => 0.0);
for (int i = 0; i < halfSize; i++) {
result[i] = (data[2 * i] + data[2 * i + 1]) / sqrt(2);
result[halfSize + i] = (data[2 * i] - data[2 * i + 1]) / sqrt(2);
}
final transformed = haarTransform(result.sublist(0, halfSize), halfSize);
transformed.addAll(result.sublist(halfSize, size));
return transformed;
}
final result = haarTransform(data.toList(), width * height);
double sum = 0;
for (double value in result) {
sum += value * value;
}
return sqrt(sum) / (width * height);
}