[TASK] Migrate histogramm adaption over to YUV.

This commit is contained in:
Jan Philipp Timme 2015-12-11 14:02:05 +01:00
parent b762a3a076
commit 6ead23f875
1 changed files with 28 additions and 18 deletions

View File

@ -229,8 +229,8 @@ void ImageViewer::analyzeImage() {
* @brief ImageViewer::adjustBrightness
*/
void ImageViewer::adjustBrightness(int b) {
int h, s, old_l;
int new_l = 0;
//int h, s, old_l;
//int new_l = 0;
int delta = b - 255;
for(int x=0; x<working_copy->getImage()->width(); x++) {
for(int y=0; y<working_copy->getImage()->height(); y++) {
@ -249,8 +249,8 @@ void ImageViewer::adjustBrightness(int b) {
}
}
updateImageDisplay();
logFile << "Brightness adjusted to: " << old_l << " + " << delta << " -> (" << h << ", " << s << ", " << new_l << ")" << std::endl;
renewLogging();
//logFile << "Brightness adjusted to: " << old_l << " + " << delta << " -> (" << h << ", " << s << ", " << new_l << ")" << std::endl;
//renewLogging();
}
/**
@ -349,17 +349,19 @@ void ImageViewer::robustAutomaticContrastAdaption(int c_param) {
void ImageViewer::linearHistogrammAdaption(void) {
logFile << "Doing linear histogramm adaption ..." << std::endl;
renewLogging();
int h, s, l;
//int h, s, l;
int* ach = original->getAbsoluteCumulativeIntensityHistogramm();
int pixels = working_copy->getImage()->width()*working_copy->getImage()->height();
for(int x=0; x<working_copy->getImage()->width(); x++) {
for(int y=0; y<working_copy->getImage()->height(); y++) {
QColor color = QColor::fromRgb(original->getImage()->pixel(x, y));
color.getHsl(&h, &s, &l);
l = (int) qFloor(ach[l] * (255.0/pixels));
color.setHsl(h, s, l);
//color.getHsl(&h, &s, &l);
//l = (int) qFloor(ach[l] * (255.0/pixels));
//color.setHsl(h, s, l);
struct yuv yuv = LazyImage::RGBToYUV(color.rgb());
int l = qRound(yuv.y * 255.0);
yuv.y = qFloor(ach[l] * (255.0/pixels)) / 255.0;
color = LazyImage::YUVToRGB(yuv);
working_copy->getImage()->setPixel(x, y, color.rgb());
}
}
@ -426,13 +428,17 @@ void ImageViewer::partialLinearHistogrammAdaption() {
renewLogging();
// Apply the brightness map
int h, s, l;
//int h, s, l;
for(int x=0; x<working_copy->getImage()->width(); x++) {
for(int y=0; y<working_copy->getImage()->height(); y++) {
QColor color = QColor::fromRgb(original->getImage()->pixel(x, y));
color.getHsl(&h, &s, &l);
l = brightness_map[l];
color.setHsl(h, s, l);
//color.getHsl(&h, &s, &l);
//l = brightness_map[l];
//color.setHsl(h, s, l);
struct yuv yuv = LazyImage::RGBToYUV(color.rgb());
int l = qRound(yuv.y * 255.0);
yuv.y = qFloor(brightness_map[l]) / 255.0;
color = LazyImage::YUVToRGB(yuv);
working_copy->getImage()->setPixel(x, y, color.rgb());
}
}
@ -482,13 +488,17 @@ void ImageViewer::succeedingHistogrammAdaption() {
}
// Apply the map for each pixel.
int h, s, l;
//int h, s, l;
for(int x=0; x<working_copy->getImage()->width(); x++) {
for(int y=0; y<working_copy->getImage()->height(); y++) {
QColor color = QColor::fromRgb(original->getImage()->pixel(x, y));
color.getHsl(&h, &s, &l);
l = histogramm_map[l];
color.setHsl(h, s, l);
//color.getHsl(&h, &s, &l);
//l = histogramm_map[l];
//color.setHsl(h, s, l);
struct yuv yuv = LazyImage::RGBToYUV(color.rgb());
int l = qRound(yuv.y * 255.0);
yuv.y = qFloor(histogramm_map[l]) / 255.0;
color = LazyImage::YUVToRGB(yuv);
working_copy->getImage()->setPixel(x, y, color.rgb());
}
}