diff --git a/src/core/transformations/blur_gaussian.cpp b/src/core/transformations/blur_gaussian.cpp index 758f178..9fdae67 100644 --- a/src/core/transformations/blur_gaussian.cpp +++ b/src/core/transformations/blur_gaussian.cpp @@ -39,6 +39,6 @@ math::matrix BlurGaussian::getMask(int size, Mode) float BlurGaussian::getGauss(int x, int y, float sigma) { - return exp(-((pow(x, 2.0) + pow(y, 2.0)) / 2 * pow(sigma, 2.0))) / (2 * M_PI * pow(sigma, 2.0)); + return exp(-((pow(x, 2.0) + pow(y, 2.0)) / (2 * pow(sigma, 2.0)))) / (2 * M_PI * pow(sigma, 2.0)); } diff --git a/src/core/transformations/edge_gradient.cpp b/src/core/transformations/edge_gradient.cpp index a36a5b8..0557093 100644 --- a/src/core/transformations/edge_gradient.cpp +++ b/src/core/transformations/edge_gradient.cpp @@ -1,4 +1,5 @@ #include "edge_gradient.h" +#include EdgeGradient::EdgeGradient(PNM* img, ImageViewer* iv) : Convolution(img, iv) @@ -24,8 +25,27 @@ PNM* EdgeGradient::transform() { PNM* newImage = new PNM(image->width(), image->height(), image->format()); - qDebug() << Q_FUNC_INFO << "Not implemented yet!"; + PNM* horizontal = horizontalDetection(); + PNM* vertical = verticalDetection(); + + for (int x=0;xwidth();++x) { + for (int y=0;yheight();++y) { + int horizontalPixel = horizontal->pixel(x,y); + int verticalPixel = vertical->pixel(x,y); + + int r = sqrt(pow(qRed(horizontalPixel), 2.0) + pow(qRed(verticalPixel), 2.0)); + int g = sqrt(pow(qGreen(horizontalPixel), 2.0) + pow(qGreen(verticalPixel), 2.0)); + int b = sqrt(pow(qBlue(horizontalPixel), 2.0) + pow(qBlue(verticalPixel), 2.0)); + + newImage->setPixel(x, y, QColor(limit(r),limit(g),limit(b)).rgb()); + } + } return newImage; } +int EdgeGradient::limit(int value) { + if (value < 0) return 0; + if (value > 255) return 255; + return value; +} diff --git a/src/core/transformations/edge_gradient.h b/src/core/transformations/edge_gradient.h index 331ccc1..b030b2c 100644 --- a/src/core/transformations/edge_gradient.h +++ b/src/core/transformations/edge_gradient.h @@ -16,6 +16,7 @@ public: protected: virtual void prepareMatrices() = 0; + int limit(int value); math::matrix g_x, g_y; }; diff --git a/src/core/transformations/edge_laplacian.cpp b/src/core/transformations/edge_laplacian.cpp index 8c26718..851ff61 100644 --- a/src/core/transformations/edge_laplacian.cpp +++ b/src/core/transformations/edge_laplacian.cpp @@ -15,7 +15,14 @@ math::matrix EdgeLaplacian::getMask(int, Mode) int size = getParameter("size").toInt(); math::matrix mask(size, size); - qDebug() << Q_FUNC_INFO << "Not implemented yet!"; + for (int i=0;i #include "blur_gaussian.h" EdgeLaplaceOfGauss::EdgeLaplaceOfGauss(PNM* img) : @@ -12,23 +12,28 @@ EdgeLaplaceOfGauss::EdgeLaplaceOfGauss(PNM* img, ImageViewer* iv) : { } -math::matrix EdgeLaplaceOfGauss::getMask(int, Mode) +math::matrix EdgeLaplaceOfGauss::getMask(int size, float sigma, Mode) { - size = getParameter("size").toInt(); - double sigma = getParameter("sigma").toDouble(); + if (size == 0) + size = getParameter("size").toInt(); + if (sigma == 0) + sigma = getParameter("sigma").toDouble(); math::matrix mask(size, size); - qDebug() << Q_FUNC_INFO << "Not implemented yet!"; + for (int i=0;i getMask(int, Mode); + virtual math::matrix getMask(int, float, Mode); static float getLoG(int, int, float); int getSize(); diff --git a/src/core/transformations/edge_prewitt.cpp b/src/core/transformations/edge_prewitt.cpp index d6585eb..56faf05 100644 --- a/src/core/transformations/edge_prewitt.cpp +++ b/src/core/transformations/edge_prewitt.cpp @@ -14,6 +14,15 @@ EdgePrewitt::EdgePrewitt(PNM*img, ImageViewer* iv) : void EdgePrewitt::prepareMatrices() { - qDebug() << Q_FUNC_INFO << "Not implemented yet!"; + float array_x[9] = {-1,0,1, + -1,0,1, + -1,0,1}; + + float array_y[9] = {-1,-1,-1, + 0,0,0, + 1,1,1}; + + g_x = math::matrix(3,3, array_x); + g_y = math::matrix(3,3, array_y); } diff --git a/src/core/transformations/edge_roberts.cpp b/src/core/transformations/edge_roberts.cpp index 0428da9..a2d7817 100644 --- a/src/core/transformations/edge_roberts.cpp +++ b/src/core/transformations/edge_roberts.cpp @@ -1,4 +1,5 @@ #include "edge_roberts.h" +#include EdgeRoberts::EdgeRoberts(PNM* img) : EdgeGradient(img) @@ -14,5 +15,15 @@ EdgeRoberts::EdgeRoberts(PNM* img, ImageViewer* iv) : void EdgeRoberts::prepareMatrices() { - qDebug() << Q_FUNC_INFO << "Not implemented yet!"; + g_x = math::matrix(2,2); + g_x[0][0] = 1; + g_x[0][1] = 0; + g_x[1][0] = 0; + g_x[1][1] = -1; + + g_y = math::matrix(2,2); + g_y[0][0] = 0; + g_y[0][1] = 1; + g_y[1][0] = -1; + g_y[1][1] = 0; } diff --git a/src/core/transformations/edge_sobel.cpp b/src/core/transformations/edge_sobel.cpp index 6ef4bff..1af5820 100644 --- a/src/core/transformations/edge_sobel.cpp +++ b/src/core/transformations/edge_sobel.cpp @@ -14,7 +14,16 @@ EdgeSobel::EdgeSobel(PNM* img) : void EdgeSobel::prepareMatrices() { - qDebug() << Q_FUNC_INFO << "Not implemented yet!"; + float array_x[9] = {-1,0,1, + -2,0,2, + -1,0,1}; + + float array_y[9] = {-1,-2,-1, + 0,0,0, + 1,2,1}; + + g_x = math::matrix(3,3, array_x); + g_y = math::matrix(3,3, array_y); } math::matrix* EdgeSobel::rawHorizontalDetection() diff --git a/src/core/transformations/edge_zero.cpp b/src/core/transformations/edge_zero.cpp index 541943f..30ecd40 100644 --- a/src/core/transformations/edge_zero.cpp +++ b/src/core/transformations/edge_zero.cpp @@ -22,8 +22,24 @@ PNM* EdgeZeroCrossing::transform() int t = getParameter("threshold").toInt(); PNM* newImage = new PNM(width, height, QImage::Format_Grayscale8); + EdgeLaplaceOfGauss log(newImage); - qDebug() << Q_FUNC_INFO << "Not implemented yet!"; + int v0 = 128; + + for (int x=0;x mask = log.getMask(size, sigma, RepeatEdge); + + float max = mask.max(); + float min = mask.min(); + + if (min < v0 - t && max > v0 + t) + newImage->setPixel(x,y, QColor(lapsjan, lapsjan, lapsjan).rgb()); + else + newImage->setPixel(x,y, QColor(0, 0, 0).rgb()); + } + } return newImage; }