Zadanie 5 - Binaryzacja

This commit is contained in:
Kamila Malanowicz 2020-04-29 20:43:13 +02:00
parent 722fcbfed2
commit c724f79b2f
2 changed files with 45 additions and 2 deletions

View File

@ -14,10 +14,43 @@ PNM* BinarizationGradient::transform()
{ {
int width = image->width(); int width = image->width();
int height = image->height(); int height = image->height();
int x = 0;
int y = 0;
double threshold = 0.0;
PNM* newImage = new PNM(width, height, QImage::Format_Mono); PNM* newImage = new PNM(width, height, QImage::Format_Mono);
qDebug() << Q_FUNC_INFO << "Not implemented yet!"; for (int i=0; i<width; i++) {
for (int j=0; j<height; j++) {
int px = qGray(image->pixel(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; i<width; i++) {
for (int j=0; j<height; j++) {
int l = qGray(image->pixel(i,j));
if (l < threshold) {
newImage->setPixel(i, j, Qt::color0);
} else {
newImage->setPixel(i, j, Qt::color1);
}
}
}
return newImage; return newImage;
} }

View File

@ -19,7 +19,17 @@ PNM* BinarizationManual::transform()
PNM* newImage = new PNM(width, height, QImage::Format_Mono); PNM* newImage = new PNM(width, height, QImage::Format_Mono);
qDebug() << Q_FUNC_INFO << "Not implemented yet!"; for (int i=0; i<width; i++) {
for (int j=0; j<height; j++) {
int l = qGray(image->pixel(i,j));
if (l < threshold) {
newImage->setPixel(i, j, Qt::color0);
} else {
newImage->setPixel(i, j, Qt::color1);
}
}
}
return newImage; return newImage;
} }