zadanie-6 (niblack)

This commit is contained in:
Patrycjusz Mania 2021-05-22 19:55:50 +02:00
parent 41f0bcd76c
commit 6d4bf3c213
2 changed files with 32 additions and 4 deletions

View File

@ -17,9 +17,18 @@ PNM* BinarizationManual::transform()
int width = image->width(); int width = image->width();
int height = image->height(); 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; x<width; x++)
for (int y=0; y<height; y++)
{
QRgb pixel = image->pixel(x,y);
int gray = qGray(pixel);
int v = gray >= threshold ? 255 : 0;
newImage->setPixel(x,y, QColor(v,v,v).rgb());
}
return newImage; return newImage;
} }

View File

@ -18,9 +18,28 @@ PNM* BinarizationNiblack::transform()
int r = getParameter("r").toInt(); int r = getParameter("r").toInt();
double a = getParameter("a").toDouble(); 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<width; x++)
for (int y=0; y<height; y++)
{
math::matrix<float> mask = getWindow(x,y,r, LChannel, RepeatEdge);
float avg = mask.sum() / (float)mask.size();
float std = 0.0;
for (unsigned int i=0;i<mask.rowno();++i) {
for (unsigned int j=0;j<mask.colno();++j) {
std += pow(mask[i][j] - avg, 2.0);
}
}
std = sqrt(std / (float)mask.size());
int threshold = avg + (a * std);
int v = qGray(image->pixel(x,y)) >= threshold ? 255 : 0;
newImage->setPixel(x,y, QColor(v,v,v).rgb());
}
qDebug() << Q_FUNC_INFO << "Not implemented yet!";
return newImage; return newImage;
} }