histogram stretching
This commit is contained in:
parent
f1e4e73833
commit
718517590b
@ -18,10 +18,47 @@ PNM* HistogramStretching::transform()
|
|||||||
int height = image->height();
|
int height = image->height();
|
||||||
|
|
||||||
PNM* newImage = new PNM(width, height, image->format());
|
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;
|
return newImage;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user