compute method
double
compute(
- Image image
)
override
Implementation
@override
double compute(img.Image image) {
final sobelX = generateSobelKernel('x');
final sobelY = generateSobelKernel('y');
double sum = 0;
for (int y = 1; y < image.height - 1; y++) {
for (int x = 1; x < image.width - 1; x++) {
double gx = 0;
double gy = 0;
for (int ky = -1; ky <= 1; ky++) {
for (int kx = -1; kx <= 1; kx++) {
final gray = pixelToGray(image, x + kx, y + ky);
gx += gray * sobelX[ky + 1][kx + 1];
gy += gray * sobelY[ky + 1][kx + 1];
}
}
final magnitude = gx * gx + gy * gy;
sum += magnitude;
}
}
return sum / ((image.width - 2) * (image.height - 2));
}