From c724f79b2fefc2a22411b7895a9c87a024cc21b3 Mon Sep 17 00:00:00 2001 From: Kamila Malanowicz Date: Wed, 29 Apr 2020 20:43:13 +0200 Subject: [PATCH] Zadanie 5 - Binaryzacja --- .../src/core/transformations/bin_gradient.cpp | 35 ++++++++++++++++++- .../src/core/transformations/bin_manual.cpp | 12 ++++++- 2 files changed, 45 insertions(+), 2 deletions(-) diff --git a/lpo-projekt-v2/src/core/transformations/bin_gradient.cpp b/lpo-projekt-v2/src/core/transformations/bin_gradient.cpp index d502adb..50b49e6 100644 --- a/lpo-projekt-v2/src/core/transformations/bin_gradient.cpp +++ b/lpo-projekt-v2/src/core/transformations/bin_gradient.cpp @@ -14,10 +14,43 @@ PNM* BinarizationGradient::transform() { int width = image->width(); int height = image->height(); + int x = 0; + int y = 0; + double threshold = 0.0; PNM* newImage = new PNM(width, height, QImage::Format_Mono); - qDebug() << Q_FUNC_INFO << "Not implemented yet!"; + for (int i=0; ipixel(i,j)); + int pxl = qGray(image->pixel(i-1,j)); + int pxr = qGray(image->pixel(i+1,j)); + int pxt = qGray(image->pixel(i,j+1)); + int pxb = qGray(image->pixel(i,j-1)); + + int gx = pxr - pxl; + int gy = pxt - pxb; + + int max = std::max(gx, gy); + + x = x + max * px; + y = y + max; + } + } + + threshold = x / y; + + for (int i=0; ipixel(i,j)); + + if (l < threshold) { + newImage->setPixel(i, j, Qt::color0); + } else { + newImage->setPixel(i, j, Qt::color1); + } + } + } return newImage; } diff --git a/lpo-projekt-v2/src/core/transformations/bin_manual.cpp b/lpo-projekt-v2/src/core/transformations/bin_manual.cpp index a410dfa..f7c29c6 100644 --- a/lpo-projekt-v2/src/core/transformations/bin_manual.cpp +++ b/lpo-projekt-v2/src/core/transformations/bin_manual.cpp @@ -19,7 +19,17 @@ PNM* BinarizationManual::transform() PNM* newImage = new PNM(width, height, QImage::Format_Mono); - qDebug() << Q_FUNC_INFO << "Not implemented yet!"; + for (int i=0; ipixel(i,j)); + + if (l < threshold) { + newImage->setPixel(i, j, Qt::color0); + } else { + newImage->setPixel(i, j, Qt::color1); + } + } + } return newImage; }