1
0
lpo-image-processing/05/do_sprawdzenia/cpp/bin_manual.cpp

46 lines
947 B
C++
Raw Normal View History

2021-03-28 14:03:07 +02:00
#include "bin_manual.h"
BinarizationManual::BinarizationManual(PNM* img) :
Transformation(img)
{
}
BinarizationManual::BinarizationManual(PNM* img, ImageViewer* iv) :
Transformation(img, iv)
{
}
PNM* BinarizationManual::transform()
{
int threshold = getParameter("threshold").toInt();
int width = image->width();
int height = image->height();
PNM* newImage = new PNM(width, height, QImage::Format_Mono);
// Iterate over pixels
for (int x=0; x < width; x++)
{
for (int y=0; y < height; y++)
{
// Get current pixel
QRgb pixel = image->pixel(x, y);
if(qGray(pixel) > threshold)
{
newImage->setPixel(x, y, Qt::color1);
}
else
{
newImage->setPixel(x, y, Qt::color0);
}
}
}
return newImage;
}