From 6d4bf3c21345172632219febdd01892d1cdd342f Mon Sep 17 00:00:00 2001 From: Patrycjusz Mania Date: Sat, 22 May 2021 19:55:50 +0200 Subject: [PATCH] zadanie-6 (niblack) --- src/core/transformations/bin_manual.cpp | 13 +++++++++++-- src/core/transformations/bin_niblack.cpp | 23 +++++++++++++++++++++-- 2 files changed, 32 insertions(+), 4 deletions(-) diff --git a/src/core/transformations/bin_manual.cpp b/src/core/transformations/bin_manual.cpp index a410dfa..18d1e36 100644 --- a/src/core/transformations/bin_manual.cpp +++ b/src/core/transformations/bin_manual.cpp @@ -17,9 +17,18 @@ PNM* BinarizationManual::transform() int width = image->width(); int height = image->height(); - PNM* newImage = new PNM(width, height, QImage::Format_Mono); + PNM* newImage = new PNM(width, height, QImage::Format_RGB32); - qDebug() << Q_FUNC_INFO << "Not implemented yet!"; + for (int x=0; xpixel(x,y); + + int gray = qGray(pixel); + int v = gray >= threshold ? 255 : 0; + + newImage->setPixel(x,y, QColor(v,v,v).rgb()); + } return newImage; } diff --git a/src/core/transformations/bin_niblack.cpp b/src/core/transformations/bin_niblack.cpp index 418648b..691d5f9 100644 --- a/src/core/transformations/bin_niblack.cpp +++ b/src/core/transformations/bin_niblack.cpp @@ -18,9 +18,28 @@ PNM* BinarizationNiblack::transform() int r = getParameter("r").toInt(); double a = getParameter("a").toDouble(); - PNM* newImage = new PNM(width, height, QImage::Format_Mono); + PNM* newImage = new PNM(width, height, QImage::Format_RGB32); + + for (int x=0; x mask = getWindow(x,y,r, LChannel, RepeatEdge); + float avg = mask.sum() / (float)mask.size(); + + float std = 0.0; + for (unsigned int i=0;ipixel(x,y)) >= threshold ? 255 : 0; + + newImage->setPixel(x,y, QColor(v,v,v).rgb()); + } - qDebug() << Q_FUNC_INFO << "Not implemented yet!"; return newImage; }