Zadanie 5 - Binaryzacja
This commit is contained in:
parent
722fcbfed2
commit
c724f79b2f
@ -14,10 +14,43 @@ PNM* BinarizationGradient::transform()
|
||||
{
|
||||
int width = image->width();
|
||||
int height = image->height();
|
||||
int x = 0;
|
||||
int y = 0;
|
||||
double threshold = 0.0;
|
||||
|
||||
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;
|
||||
}
|
||||
|
@ -19,7 +19,17 @@ PNM* BinarizationManual::transform()
|
||||
|
||||
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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user