From 87f95e8e34ba09c26d68549f6b362079ee8248d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jaros=C5=82aw=20Wieczorek?= Date: Thu, 15 Apr 2021 20:34:13 +0200 Subject: [PATCH] Zadanie 11 --- 11/do_sprawdzenia/cpp/bin_gradient.cpp | 83 ++++++++++++++++ 11/do_sprawdzenia/cpp/hough.cpp | 93 ++++++++++++++++++ 11/do_sprawdzenia/cpp/hough_lines.cpp | 91 +++++++++++++++++ 11/do_sprawdzenia/cpp/image1.png | Bin 0 -> 7476 bytes 11/do_sprawdzenia/cpp/image2.png | Bin 0 -> 10048 bytes .../src/core/transformations/hough.cpp | 78 ++++++++++++++- .../src/core/transformations/hough_lines.cpp | 67 ++++++++++++- 7 files changed, 405 insertions(+), 7 deletions(-) create mode 100644 11/do_sprawdzenia/cpp/bin_gradient.cpp create mode 100644 11/do_sprawdzenia/cpp/hough.cpp create mode 100644 11/do_sprawdzenia/cpp/hough_lines.cpp create mode 100644 11/do_sprawdzenia/cpp/image1.png create mode 100644 11/do_sprawdzenia/cpp/image2.png diff --git a/11/do_sprawdzenia/cpp/bin_gradient.cpp b/11/do_sprawdzenia/cpp/bin_gradient.cpp new file mode 100644 index 0000000..d07edb2 --- /dev/null +++ b/11/do_sprawdzenia/cpp/bin_gradient.cpp @@ -0,0 +1,83 @@ +#include "bin_gradient.h" +using namespace std; + +BinarizationGradient::BinarizationGradient(PNM* img) : + Transformation(img) +{ +} + +BinarizationGradient::BinarizationGradient(PNM* img, ImageViewer* iv) : + Transformation(img, iv) +{ +} + +PNM* BinarizationGradient::transform() +{ + int width = image->width(); + int height = image->height(); + + PNM* newImage = new PNM(width, height, QImage::Format_Mono); + int numerator = 0; + int denominator = 0; + + // Gx + int Gx = 0; + + // Gy + int Gy = 0; + + int G = 0; + int T = 0; + + //PNM* newImage = new PNM(width, height, QImage::Format_Mono); + + for (int x = 0; x < width; x++) + { + for (int y = 0; y < height; y++) + { + Mode mode = Transformation::RepeatEdge; + int I = qGray(getPixel(x, y, mode)); + + // Get Gx and Gy + Gx = qGray(getPixel(x + 1, y, mode)) - qGray(getPixel(x - 1, y, mode)); + Gy = qGray(getPixel(x, y + 1, mode)) - qGray(getPixel(x, y - 1, mode)); + + if (Gx > Gy) + { + G = Gx; + } + else + { + G = Gy; + } + numerator += I * G; + denominator += G; + } + } + + T = numerator / denominator; + + for (int x = 0; x < width; x++) + { + for (int y = 0; y < height; y++) + { + Mode mode = Transformation::RepeatEdge; + QRgb pixel = getPixel(x, y, mode); + + int val = qGray(pixel); + + if (val < T) + { + newImage->setPixel(x, y, 0); + } + else + { + newImage->setPixel(x, y, 1); + } + } + } + + return newImage; +} + + diff --git a/11/do_sprawdzenia/cpp/hough.cpp b/11/do_sprawdzenia/cpp/hough.cpp new file mode 100644 index 0000000..e70518d --- /dev/null +++ b/11/do_sprawdzenia/cpp/hough.cpp @@ -0,0 +1,93 @@ +#include "hough.h" +#include "iostream" +#include "conversion_grayscale.h" +#include "edge_laplacian.h" + +Hough::Hough(PNM* img) : + Transformation(img) +{ +} + +Hough::Hough(PNM* img, ImageViewer* super) : + Transformation(img, super) +{ +} + +PNM* Hough::transform() +{ + int width = image->width(); + int height = image->height(); + + int theta_density = getParameter("theta_density").toInt(); + bool skip_edge = getParameter("skip_edge_detection").toBool(); + + std::cout << "skip_edge: " << skip_edge << std::endl; + int theta_size = 180 * theta_density; + double max_ro = sqrt(pow(width, 2) + pow(height, 2)); + + ConversionGrayscale* gray_scale = new ConversionGrayscale(image); + image = gray_scale->transform(); + + PNM* newImage = new PNM(theta_size, max_ro * 2 + 1, QImage::Format_Grayscale8); + + int new_image_width = newImage->width(); + int new_image_height = newImage->height(); + + math::matrix hough(new_image_width, new_image_height); + + + + if (skip_edge == false) + { + EdgeLaplacian *el = new EdgeLaplacian(image); + el->setParameter("size", 7); + image = el->transform(); + } + + for (int x = 0; x < new_image_width; x++) + { + for (int y = 0; y < new_image_height; y++) + { + hough[x][y] = 0; + } + } + + + double theta = 0.0; + double ro = 0; + float max = 0; + double max_z = 0; + + for (int i = 0; i < width; i++) + { + for (int j = 0; j < height; j++) + { + if (qGray(image->pixel(i, j)) > 0) + { + for (int k = 0; k < theta_size; k++) + { + theta = (k * M_PI) / (theta_density * 180); + ro = i * cos(theta) + j * sin(theta); + hough[k][ro + max_ro]++; + } + } + } + } + + max = hough.max(); + + int z; + + for (int x = 0; x < new_image_width; x++) + { + for (int y = 0; y < new_image_height; y++) + { + z = hough[x][y] * (max / 255); + + newImage->setPixel(x, y, QColor(z, z, z).rgb()); + } + } + std::cout << "max_z: " << max_z << std::endl; + + return newImage; +} diff --git a/11/do_sprawdzenia/cpp/hough_lines.cpp b/11/do_sprawdzenia/cpp/hough_lines.cpp new file mode 100644 index 0000000..41c2db3 --- /dev/null +++ b/11/do_sprawdzenia/cpp/hough_lines.cpp @@ -0,0 +1,91 @@ +#include "hough_lines.h" +#include "bin_gradient.h" +#include "edge_laplacian.h" + +#include "hough.h" +#include +#include +#include + +HoughLines::HoughLines(PNM* img) : + Transformation(img) +{ +} + +HoughLines::HoughLines(PNM* img, ImageViewer* iv) : + Transformation(img, iv) +{ +} + + + + + + +PNM* HoughLines::transform() +{ + + // Cut of value from the image; + int threshold = getParameter("threshold").toInt(); + bool drawWholeLines = getParameter("draw_whole_lines").toBool(); + int theta_density = 3; + + PNM* newImage = new PNM(image->copy()); + + EdgeLaplacian el(image); + el.setParameter("size", 3); + PNM* image_edge = el.transform(); + + PNM* image_bin = BinarizationGradient(image_edge).transform(); + + Hough h(image_edge); + + h.setParameter("theta_density", theta_density); + h.setParameter("skip_edge_detection", true); + PNM* image_hough = h.transform(); + + int hough_width = image_hough->width(); + int hough_height = image_hough->height(); + + int width = image_bin->width(); + int height = image_bin->height(); + + QPainter qPainter (newImage); + qPainter.setPen(Qt::red); + + for (int theta = 0; theta < hough_width; theta++) + { + for (int rho = 0; rho < hough_height; rho++) + { + int val = (int) qGray(image_hough->pixel(theta, rho)); + if (val > threshold) + { + double rtheta = ((double)theta / 3.0) * M_PI / 180.0; + int rrho = rho - hough_height / 2; + qPainter.drawLine(0, round(rrho / sin(rtheta)), width - 1, round((rrho - (width - 1) * cos(rtheta)) / sin(rtheta))); + + } + } + } + + int counter_pixels = 0; + if (!drawWholeLines) + { + for (int x = 0; x < width; x++) + { + for (int y = 0; y < height; y++) + { + QRgb pixel = image_bin->pixel(x, y); + + if (qGray(pixel) == 0) + { + counter_pixels++; + newImage->setPixel(x, y, image->pixel(x, y)); + } + } + } + std::cout << "counter " << counter_pixels << std::endl; + } + + return newImage; +} diff --git a/11/do_sprawdzenia/cpp/image1.png b/11/do_sprawdzenia/cpp/image1.png new file mode 100644 index 0000000000000000000000000000000000000000..81e70f3395d132b9d4fc345a4a6e65a023b8acd1 GIT binary patch literal 7476 zcmXw8cRbX8{J-TK4tM6+cZZPCMd2%PR-KGQMv=}=_6ivt&Mc#hWN(p~5i%|^vN9v3 z$SjhPy?&p5zsK*7&mZs4<2|0Q@qE2suh%=;K>sQ;BQGNe1Y*`EX&Qn+VDP^W0SEs0 zt)h-WApS#bO|_eT8NV}qlg!66yW4n^c}$Tw)TBEJ@m7p)GQs(^HdocaGiP~Qje{ce z&OEIB)($`7%-eV5Zt|Rj3{k#XL+nDjD_>ZEfSylh%a@sNm$RN;$(J8F!ToGGTvJXS zCO!OpxZnM0bbR?&i*MWRVQ`zd1-pZrp8no`9hU3e!r7CW54MhN3R}CIPL~?9#y{4n!XjT_p?kfbLT%?}**NKsdZ1#F|VPN&%MY{})O{!j%|f zC;~4v6A~u5VknssXGlFyL*l~lWbWSI@XcF6j1;?E#AN14Lx_b;PQq@qC@_i+bj5Oa z!jCY>T4fIK+uR9kC;VGB+vi=wE!@|kaTX)jPh?)W}rlev#q2CxC;1hh;cru5692I zuGNiU!f62T4D~Gd>cQrpvp3P!^5PJdrAGhXAjh2%(iUzt$PKkLZ`g8DJ^IC=wpUOjiNNgQH z?+glnV%FvY! zL;#=Wufp%QTX`fW{%94rFh;}+J|CsCC6#4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rW>ub!_Zb%#=E zkUFY3vF!%lH9+3y_C`?V7-HXUJsqi-JZPbCqXO@T;Jw$*iuv@7>%z;PuaKU4lhy7& zc39}sK*M#pFdh=F$+u1PXLzK>MQz~x?bg%Me%kO%qsOC=`qBYr7kz^|mz^1^v)&+g zh>^u#|2%hkyU2p1<+=vc)ru<}4RRUXg<^JNe>Z7jmwL=kp;?kKSknT+O@ijt%qrmme)GbY6MN{p@wqN$Z6rw6Vc)O~5crDQK;1XbY!f zh5*#P?z;AGY#E{do$7(LD668>DN+^rCnvcY`G0Vs@V^djPPdm)0)?Qjg<@NkEdy@@ zW@^97|L9U4leY<6oxUJALKt7IYhkhV-+hE2%X?rXS6HF3^HGJacf#)Ngr+`oNooNq zNDENqgkCz%)T*_t&`9-(oO^X3!yZ~av=_|jL@C2)Vuz^@}jZ)6&`%6qTbjQ zbfnKaEYzK-g%HX8G_iXcHire+@3Ig|QOfAHGZvf-^WGONE=Cl-TC-uEKobk&(+7jG z|Nqt(1v3Q}esTTl|K_2C@Z?!>Fg+Mc{(Mfcwidth(); + int height = image->height(); - qDebug() << Q_FUNC_INFO << "Not implemented yet!"; + int theta_density = getParameter("theta_density").toInt(); + bool skip_edge = getParameter("skip_edge_detection").toBool(); - return 0; + std::cout << "skip_edge: " << skip_edge << std::endl; + int theta_size = 180 * theta_density; + double max_ro = sqrt(pow(width, 2) + pow(height, 2)); + + ConversionGrayscale* gray_scale = new ConversionGrayscale(image); + image = gray_scale->transform(); + + PNM* newImage = new PNM(theta_size, max_ro * 2 + 1, QImage::Format_Grayscale8); + + int new_image_width = newImage->width(); + int new_image_height = newImage->height(); + + math::matrix hough(new_image_width, new_image_height); + + + + if (skip_edge == false) + { + EdgeLaplacian *el = new EdgeLaplacian(image); + el->setParameter("size", 7); + image = el->transform(); + } + + for (int x = 0; x < new_image_width; x++) + { + for (int y = 0; y < new_image_height; y++) + { + hough[x][y] = 0; + } + } + + + double theta = 0.0; + double ro = 0; + float max = 0; + double max_z = 0; + + for (int i = 0; i < width; i++) + { + for (int j = 0; j < height; j++) + { + if (qGray(image->pixel(i, j)) > 0) + { + for (int k = 0; k < theta_size; k++) + { + theta = (k * M_PI) / (theta_density * 180); + ro = i * cos(theta) + j * sin(theta); + hough[k][ro + max_ro]++; + } + } + } + } + + max = hough.max(); + + int z; + + for (int x = 0; x < new_image_width; x++) + { + for (int y = 0; y < new_image_height; y++) + { + z = hough[x][y] * (max / 255); + + newImage->setPixel(x, y, QColor(z, z, z).rgb()); + } + } + std::cout << "max_z: " << max_z << std::endl; + + return newImage; } diff --git a/app/cpp/mysimplegimp/src/core/transformations/hough_lines.cpp b/app/cpp/mysimplegimp/src/core/transformations/hough_lines.cpp index 02ec3e4..41c2db3 100644 --- a/app/cpp/mysimplegimp/src/core/transformations/hough_lines.cpp +++ b/app/cpp/mysimplegimp/src/core/transformations/hough_lines.cpp @@ -1,9 +1,10 @@ #include "hough_lines.h" - #include "bin_gradient.h" #include "edge_laplacian.h" -#include "hough.h" +#include "hough.h" +#include +#include #include HoughLines::HoughLines(PNM* img) : @@ -16,15 +17,75 @@ HoughLines::HoughLines(PNM* img, ImageViewer* iv) : { } + + + + + PNM* HoughLines::transform() { + // Cut of value from the image; int threshold = getParameter("threshold").toInt(); bool drawWholeLines = getParameter("draw_whole_lines").toBool(); + int theta_density = 3; PNM* newImage = new PNM(image->copy()); - qDebug() << Q_FUNC_INFO << "Not implemented yet!"; + EdgeLaplacian el(image); + el.setParameter("size", 3); + PNM* image_edge = el.transform(); + + PNM* image_bin = BinarizationGradient(image_edge).transform(); + + Hough h(image_edge); + + h.setParameter("theta_density", theta_density); + h.setParameter("skip_edge_detection", true); + PNM* image_hough = h.transform(); + + int hough_width = image_hough->width(); + int hough_height = image_hough->height(); + + int width = image_bin->width(); + int height = image_bin->height(); + + QPainter qPainter (newImage); + qPainter.setPen(Qt::red); + + for (int theta = 0; theta < hough_width; theta++) + { + for (int rho = 0; rho < hough_height; rho++) + { + int val = (int) qGray(image_hough->pixel(theta, rho)); + if (val > threshold) + { + double rtheta = ((double)theta / 3.0) * M_PI / 180.0; + int rrho = rho - hough_height / 2; + qPainter.drawLine(0, round(rrho / sin(rtheta)), width - 1, round((rrho - (width - 1) * cos(rtheta)) / sin(rtheta))); + + } + } + } + + int counter_pixels = 0; + if (!drawWholeLines) + { + for (int x = 0; x < width; x++) + { + for (int y = 0; y < height; y++) + { + QRgb pixel = image_bin->pixel(x, y); + + if (qGray(pixel) == 0) + { + counter_pixels++; + newImage->setPixel(x, y, image->pixel(x, y)); + } + } + } + std::cout << "counter " << counter_pixels << std::endl; + } return newImage; }