diff --git a/imageviewer-qt4.cpp b/imageviewer-qt4.cpp index b9307ca..5076d84 100644 --- a/imageviewer-qt4.cpp +++ b/imageviewer-qt4.cpp @@ -458,7 +458,7 @@ void ImageViewer::succeedingHistogrammAdaption() { int h, s, l; for(int x=0; xgetImage()->width(); x++) { for(int y=0; ygetImage()->height(); y++) { - QColor color = QColor::fromRgb(original->getImage()->pixel(x, y)); + QColor color = QColor::fromRgb(original->getImage()->pixel(x, y)); color.getHsl(&h, &s, &l); l = histogramm_map[l]; color.setHsl(h, s, l); @@ -472,20 +472,59 @@ void ImageViewer::succeedingHistogrammAdaption() { updateImageDisplay(); } -void ImageViewer::applyFilter() { - logFile << "Applying filter ..."; - +/** + * No special logic, avoid the borders and apply the filter. + * + * @brief ImageViewer::applyBasicFilter + */ +void ImageViewer::applyBasicFilter() { + logFile << "Applying basic filter ..."; int* data = filter_gui->getData(); + int filter_size = filter_gui->getSize(); - for(int i=0; igetSize(); i++) { - for(int j=0; jgetSize(); j++) { - logFile << "@" << i << "," << j << " -> " << data[i*filter_gui->getSize() + j] << std::endl; + // sum up the filter weights + int filter_sum = 0; + for(int i=0; i " << current_data << std::endl; } - } + } + + int h, s, l; + // for each pixel + int filter_offset = ((filter_size+1)/2); + for(int x=0+filter_offset; xgetImage()->width()-filter_offset; x++) { + for(int y=0+filter_offset; ygetImage()->height()-filter_offset; y++) { + int intensity_sum = 0; + // sum up weighted intensity for each matrix entry + for(int fx=0; fxgetImage()->pixel(x+dx, y+dy)); + color.getHsl(&h, &s, &l); + //std::cout << "[" << fx << "," << fy <<"] " << l << " * " << data[fx*filter_size + fy] << " = "; + intensity_sum += (l * data[fx*filter_size + fy]); + //std::cout << intensity_sum << std::endl; + } + } + QColor color = QColor::fromRgb(original->getImage()->pixel(x, y)); + color.getHsl(&h, &s, &l); + //std::cout << "old lightness: " << l << ", filter_sum: " << filter_sum << ", intensity_sum:" << intensity_sum; + // divide by sum of weights + l = qRound((intensity_sum*1.0) / filter_sum); + //std::cout << " --> new l: " << l << std::endl; + color.setHsl(h, s, l); + // and set it. + working_copy->getImage()->setPixel(x, y, color.rgb()); + } + } logFile << "done." << std::endl; renewLogging(); - //updateImageDisplay(); + updateImageDisplay(); } @@ -716,7 +755,7 @@ void ImageViewer::generateControlPanels() { filter_gui = new FilterGui(); apply_filter = new QPushButton("Apply filter"); - QObject::connect(apply_filter, SIGNAL(clicked()), this, SLOT(applyFilter())); + QObject::connect(apply_filter, SIGNAL(clicked()), this, SLOT(applyBasicFilter())); task_tab4_scrolllayout->addWidget(filter_size_slider); task_tab4_scrolllayout->addWidget(filter_gui->getWidget()); diff --git a/imageviewer-qt4.h b/imageviewer-qt4.h index a524d87..30d13a6 100644 --- a/imageviewer-qt4.h +++ b/imageviewer-qt4.h @@ -157,7 +157,7 @@ class ImageViewer : public QMainWindow { void partialLinearHistogrammAdaption(); void succeedingHistogrammAdaption(); void changeFilterSize(int s); - void applyFilter(); + void applyBasicFilter(); void open(); void openReference();