Sobel operator
Implementation
void cv_apply_sobel_filter(Image *img, int magnitude) {
cv_apply_grayscale(img);
/* ... */
for (int i = 0; i <= height; i++) {
for (int j = 0; j <= width; j++) {
for (int x = 0; x < SOBEL_K_SIZE; x++) {
for (int y = 0; y < SOBEL_K_SIZE; y++) {
/* ... */
sumX += img->bytes[currentPixel] * kernelX[y][x];
sumY += img->bytes[currentPixel] * kernelY[y][x];
}
}
int gradientMagnitude = sqrt((sumX * sumX) + (sumY * sumY));
/* ... */
img->bytes[i * width + j] = gradientMagnitude;
}
}
}Result


Last updated