diff --git a/src/core/transformations/bin_gradient.cpp b/src/core/transformations/bin_gradient.cpp index d502adb..2cb9d92 100644 --- a/src/core/transformations/bin_gradient.cpp +++ b/src/core/transformations/bin_gradient.cpp @@ -15,9 +15,36 @@ PNM* BinarizationGradient::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!"; + float numerator = 0; + float denominator = 0; + + int Gx, Gy; + + for (int x = 0; x Gy){ + numerator += Gx * qGray(getPixel(x, y, RepeatEdge)); + denominator += Gx; + } else { + numerator += Gy * qGray(getPixel(x, y, RepeatEdge)); + denominator += Gy; + } + } + + int threshold = numerator / denominator; + + for (int x = 0; xpixel(x, y)); + int v = pixelValue >= threshold ? 255 : 0; + + newImage->setPixel(x,y, QColor(v,v,v).rgb()); + } return newImage; }