diff --git a/src/core/transformations/blur_gaussian.cpp b/src/core/transformations/blur_gaussian.cpp index af4903e..5d55cf9 100644 --- a/src/core/transformations/blur_gaussian.cpp +++ b/src/core/transformations/blur_gaussian.cpp @@ -41,9 +41,8 @@ math::matrix BlurGaussian::getMask(int size, Mode) } float BlurGaussian::getGauss(int x, int y, float sigma) -{ +{ float gauss= exp(-(x*x+y*y)/(2*sigma*sigma))/(2*M_PI*sigma*sigma); return gauss; } - diff --git a/src/core/transformations/conversion_grayscale.cpp b/src/core/transformations/conversion_grayscale.cpp index bd15118..b45623a 100644 --- a/src/core/transformations/conversion_grayscale.cpp +++ b/src/core/transformations/conversion_grayscale.cpp @@ -65,4 +65,3 @@ PNM* ConversionGrayscale::transform() } return newImage; -} diff --git a/src/core/transformations/convolution.cpp b/src/core/transformations/convolution.cpp index 497aa64..cea9607 100644 --- a/src/core/transformations/convolution.cpp +++ b/src/core/transformations/convolution.cpp @@ -137,7 +137,7 @@ const math::matrix Convolution::join(math::matrix A, math::matrix< for (int x=0; x Convolution::reflection(const math::matrix A) } return C; -} diff --git a/src/core/transformations/edge_laplacian.cpp b/src/core/transformations/edge_laplacian.cpp index 9d7714c..a95a2e9 100644 --- a/src/core/transformations/edge_laplacian.cpp +++ b/src/core/transformations/edge_laplacian.cpp @@ -10,9 +10,12 @@ EdgeLaplacian::EdgeLaplacian(PNM* img, ImageViewer* iv) : { } -math::matrix EdgeLaplacian::getMask(int, Mode) +math::matrix EdgeLaplacian::getMask(int size , Mode) { - int size = getParameter("size").toInt(); + + if( getParameter("size").toInt() > size ) + size =getParameter("size").toInt(); + math::matrix mask(size, size); int r=size/2; diff --git a/src/core/transformations/edge_laplacian_of_gauss.cpp b/src/core/transformations/edge_laplacian_of_gauss.cpp index 0ac338d..eb07449 100644 --- a/src/core/transformations/edge_laplacian_of_gauss.cpp +++ b/src/core/transformations/edge_laplacian_of_gauss.cpp @@ -12,11 +12,14 @@ EdgeLaplaceOfGauss::EdgeLaplaceOfGauss(PNM* img, ImageViewer* iv) : { } -math::matrix EdgeLaplaceOfGauss::getMask(int, Mode) +math::matrix EdgeLaplaceOfGauss::getMask(int size, Mode) { - size = getParameter("size").toInt(); + if( getParameter("size").toInt() > size ) + size =getParameter("size").toInt(); + double sigma = getParameter("sigma").toDouble(); + math::matrix mask(size, size); int r=size/2; diff --git a/src/core/transformations/edge_sobel.cpp b/src/core/transformations/edge_sobel.cpp index bf6bb6e..f38eb35 100644 --- a/src/core/transformations/edge_sobel.cpp +++ b/src/core/transformations/edge_sobel.cpp @@ -51,7 +51,7 @@ math::matrix* EdgeSobel::rawHorizontalDetection() for (int y = 0; y < height; y++) { math::matrix temp = getWindow(x, y, 3, LChannel, NullEdge); - x_gradient[x][y] = Convolution::sum(Convolution::join(g_x, temp)); + (*x_gradient)(x, y) = Convolution::sum(Convolution::join(g_x, temp)); } } @@ -71,7 +71,7 @@ math::matrix* EdgeSobel::rawVerticalDetection() for (int y = 0; y < height; y++) { math::matrix temp = getWindow(x, y, 3, LChannel, NullEdge); - y_gradient[x][y] = Convolution::sum(Convolution::join(g_x, temp)); + (*y_gradient)(x, y) = Convolution::sum(Convolution::join(g_x, temp)); } } diff --git a/src/core/transformations/hough.cpp b/src/core/transformations/hough.cpp index 7ab2c97..d9f07dc 100644 --- a/src/core/transformations/hough.cpp +++ b/src/core/transformations/hough.cpp @@ -17,7 +17,50 @@ PNM* Hough::transform() { int thetaDensity = getParameter("theta_density").toInt(); - qDebug() << Q_FUNC_INFO << "Not implemented yet!"; + int width = image->width(); + int height = image->height(); + PNM* tempImage = new PNM(width, height, QImage::Format_Indexed8); + tempImage = ConversionGrayscale(image).transform(); - return 0; + if (!getParameter("skip_edge_detection").toBool()) { + tempImage = EdgeLaplacian(tempImage).transform(); + } + + int pmax =int(sqrt(height*height + width*width)); + int thetaSize= 180 * thetaDensity; + int lenght = pmax * 2 + 1; + double theta, p; + int max = 0; + + math::matrix hough(thetaSize,lenght); + + for (int i = 0; i < thetaSize; i++) { + for (int j = 0 ; j < lenght ; j++) { + hough[i][j] = 0; + } + } + + for (int i = 0; i < width; i++) { + for (int j = 0; j < height; j++) { + if (qGray(tempImage->pixel(i, j)) > 0) { + for (int k = 0; k < thetaSize; k++) { + theta = (k * 3.14) / (180 * thetaDensity); + p = i*cos(theta) + j*sin(theta); + hough[k][p+pmax]++; + if (hough[k][p+pmax] > max) { + max = hough[k][p+pmax]; + } + } + } + } + } + + PNM* newImage = new PNM(thetaSize,lenght, QImage::Format_Grayscale8); + for (int i = 0; i < thetaSize; i++) { + for (int j = 0; j < lenght; j++) { + int value = int(((hough[i][j] * 255)/ max)); + newImage->setPixel(i, j, QColor(value,value,value).rgb()); + } + } + return newImage; }