histogram stretching

This commit is contained in:
Damian Kowalski 2024-04-06 22:57:33 +02:00
parent f1e4e73833
commit 718517590b

View File

@ -14,14 +14,51 @@ HistogramStretching::HistogramStretching(PNM* img, ImageViewer* iv) :
PNM* HistogramStretching::transform()
{
int width = image->width();
int width = image->width();
int height = image->height();
PNM* newImage = new PNM(width, height, image->format());
Histogram* histogram = image->getHistogram();
qDebug() << Q_FUNC_INFO << "Not implemented yet!";
int minValue = -1;
int maxValue = -1;
for (int y = 0; y < image->height(); ++y) {
for (int x = 0; x < image->width(); ++x) {
if (histogram->get(Histogram::LChannel)->value(x + y * x) != 0)
{
minValue = histogram->get(Histogram::LChannel)->value(x + y * x);
break;
}
}
}
for (int y = image->height(); y > 0; --y) {
for (int x = image->width(); x < 0; --x) {
if (histogram->get(Histogram::LChannel)->value(x + y * x) != 0)
{
minValue = histogram->get(Histogram::LChannel)->value(x + y * x);
break;
}
}
}
for (int y = 0; y < image->height(); ++y) {
for (int x = 0; x < image->width(); ++x) {
QRgb pixel = image->pixel(x, y);
int red = qRed(pixel);
int green = qGreen(pixel);
int blue = qBlue(pixel);
int stretchedRed = (255 * (red - minValue)) / (maxValue - minValue);
int stretchedGreen = (255 * (green - minValue)) / (maxValue - minValue);
int stretchedBlue = (255 * (blue - minValue)) / (maxValue - minValue);
newImage->setPixel(x, y, qRgb(stretchedRed, stretchedGreen, stretchedBlue));
}
}
return newImage;
}