zadanie-6 (gradient)

This commit is contained in:
Patrycjusz Mania 2021-05-24 19:43:56 +02:00
parent 6d4bf3c213
commit 7861be11ca

View File

@ -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<width; x++)
for (int y = 0; y<height; y++){
Gx = qGray(getPixel(x + 1, y, RepeatEdge)) - qGray(getPixel(x - 1, y, RepeatEdge));
Gy = qGray(getPixel(x, y + 1, RepeatEdge)) - qGray(getPixel(x, y - 1, RepeatEdge));
if (Gx > 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; x<width; x++)
for (int y = 0; y<height; y++) {
int pixelValue = qGray(image->pixel(x, y));
int v = pixelValue >= threshold ? 255 : 0;
newImage->setPixel(x,y, QColor(v,v,v).rgb());
}
return newImage;
}