#include "edge_sobel.h" #include EdgeSobel::EdgeSobel(PNM* img, ImageViewer* iv) : EdgeGradient(img, iv) { prepareMatrices(); } EdgeSobel::EdgeSobel(PNM* img) : EdgeGradient(img) { prepareMatrices(); } void EdgeSobel::prepareMatrices() { g_x = math::matrix(3, 3, {-1, 0, 1, -2, 0, 2, -1, 0, 1}); g_y = math::matrix(3, 3, {-1, -2, -1, 0, 0, 0, 1, 2, 1}); } math::matrix* EdgeSobel::rawHorizontalDetection() { int width = image->width(); int height = image->height(); math::matrix* x_gradient = new math::matrix(width, height); for (int i = 0; i < width; i++) { for (int j = 0; j < height; j++) { (*x_gradient)(i, j) = sum(join(g_x, getWindow(i, j, 3, LChannel, RepeatEdge))); } } return x_gradient; } math::matrix* EdgeSobel::rawVerticalDetection() { int width = image->width(); int height = image->height(); math::matrix* y_gradient = new math::matrix(width, height); math::matrix window; for (int i = 0; i < width; i++) { for (int j = 0; j < height; j++) { (*y_gradient)(i, j) = sum(join(g_y, getWindow(i, j, 3, LChannel, RepeatEdge))); } } return y_gradient; }