From 33a7f9b2af7d6b9194b8fdbe54dd4b5e3ccde5c1 Mon Sep 17 00:00:00 2001 From: Dawid_Kreft Date: Mon, 18 May 2020 00:12:00 +0200 Subject: [PATCH] Zadanie 11 - lines --- src/core/transformations/bin_gradient.cpp | 36 ++++++++++++++++++++++- src/core/transformations/hough_lines.cpp | 31 +++++++++++++++++-- 2 files changed, 64 insertions(+), 3 deletions(-) diff --git a/src/core/transformations/bin_gradient.cpp b/src/core/transformations/bin_gradient.cpp index d502adb..803b5b3 100644 --- a/src/core/transformations/bin_gradient.cpp +++ b/src/core/transformations/bin_gradient.cpp @@ -17,8 +17,42 @@ PNM* BinarizationGradient::transform() PNM* newImage = new PNM(width, height, QImage::Format_Mono); - qDebug() << Q_FUNC_INFO << "Not implemented yet!"; + int Gmax = 0; + int numerator = 0; + int denominator = 0; + for(int x=1; xpixel(x,y)) + qGreen(image->pixel(x,y)) + qBlue(image->pixel(x,y))) / 3; + int Gxa = (qRed(image->pixel(x-1,y)) + qGreen(image->pixel(x-1,y)) + qBlue(image->pixel(x-1,y))) / 3; + int Gxb = (qRed(image->pixel(x+1,y)) + qGreen(image->pixel(x+1,y)) + qBlue(image->pixel(x+1,y))) / 3; + int Gya = (qRed(image->pixel(x,y+1)) + qGreen(image->pixel(x,y+1)) + qBlue(image->pixel(x,y+1))) / 3; + int Gyb= (qRed(image->pixel(x,y-1)) + qGreen(image->pixel(x,y-1)) + qBlue(image->pixel(x,y-1))) / 3; + int Gx = Gxa - Gxb; + int Gy = Gya - Gyb; + + if (Gx > Gy) Gmax = Gx; + else Gmax = Gy; + + numerator += t * Gmax; + denominator += Gmax; + + } + } + int T = numerator/denominator; + // create new image + for(int i=0; ipixel(i,j); + int tempValue = (qRed(pixel) + qGreen(pixel) + qBlue(pixel)) / 3; + if ( tempValue > T ){ + newImage->setPixel(i, j, Qt::color1); + } + else { + newImage->setPixel(i, j, Qt::color0); + } + } + } return newImage; } diff --git a/src/core/transformations/hough_lines.cpp b/src/core/transformations/hough_lines.cpp index 02ec3e4..62902e9 100644 --- a/src/core/transformations/hough_lines.cpp +++ b/src/core/transformations/hough_lines.cpp @@ -24,7 +24,34 @@ PNM* HoughLines::transform() PNM* newImage = new PNM(image->copy()); - qDebug() << Q_FUNC_INFO << "Not implemented yet!"; - + // step 1 + EdgeLaplacian* edgeLA = new EdgeLaplacian(image); + edgeLA->setParameter("size", 3); + PNM* tempImage = edgeLA->transform(); + // step 2 + BinarizationGradient* binarizationGradient = new BinarizationGradient(tempImage); + PNM* binImage = binarizationGradient->transform(); + // step 3 + Hough* hough = new Hough(binImage); + hough->setParameter("theta_density", 3); + hough->setParameter("skip_edge_detection", true); + tempImage = hough->transform(); + // step 4 + QPainter p(newImage); + p.setPen(Qt::red); + for(int i=0; i < tempImage->width(); i++) { + for(int j=0; j < tempImage->height(); j++) { + if(qGray(tempImage->pixel(i, j)) > threshold) { + double rtheta = ((double)i/3.0)*M_PI/180.0; + int rrho = j - tempImage->height()/2; + p.drawLine(0, round(rrho/sin(rtheta)), newImage->width()-1, round((rrho - (newImage->width()-1)*cos(rtheta))/sin(rtheta))); + } + if (!drawWholeLines == true){ + if (qRed(binImage->pixel(i, j)) == 0){ + newImage->setPixel(i, j, image->pixel(i, j)); + } + } + } + } return newImage; }