zadanie-6 (gradient)
This commit is contained in:
parent
6d4bf3c213
commit
7861be11ca
@ -15,9 +15,36 @@ PNM* BinarizationGradient::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!";
|
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;
|
return newImage;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user