compute method
double
compute(
- Image image
)
override
Implementation
@override
double compute(img.Image image) {
final sobelX = generateSobelKernel('x');
final sobelY = generateSobelKernel('y');
final width = image.width;
final height = image.height;
double edgeStrength = 0;
for (int y = 1; y < height - 1; y++) {
for (int x = 1; x < 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 = sqrt(gx * gx + gy * gy);
edgeStrength += magnitude;
}
}
// Normalize to range [0, 1]
return edgeStrength / ((width - 2) * (height - 2) * 255);
}