[TASK] Finish basic dumb filter operation.

This commit is contained in:
Jan Philipp Timme 2015-11-27 14:57:37 +01:00
parent ae501ec6be
commit f875f1b8b6
2 changed files with 50 additions and 11 deletions

View File

@ -458,7 +458,7 @@ void ImageViewer::succeedingHistogrammAdaption() {
int h, s, l; int h, s, l;
for(int x=0; x<working_copy->getImage()->width(); x++) { for(int x=0; x<working_copy->getImage()->width(); x++) {
for(int y=0; y<working_copy->getImage()->height(); y++) { for(int y=0; y<working_copy->getImage()->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); color.getHsl(&h, &s, &l);
l = histogramm_map[l]; l = histogramm_map[l];
color.setHsl(h, s, l); color.setHsl(h, s, l);
@ -472,20 +472,59 @@ void ImageViewer::succeedingHistogrammAdaption() {
updateImageDisplay(); 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* data = filter_gui->getData();
int filter_size = filter_gui->getSize();
for(int i=0; i<filter_gui->getSize(); i++) { // sum up the filter weights
for(int j=0; j<filter_gui->getSize(); j++) { int filter_sum = 0;
logFile << "@" << i << "," << j << " -> " << data[i*filter_gui->getSize() + j] << std::endl; for(int i=0; i<filter_size; i++) {
for(int j=0; j<filter_size; j++) {
int current_data = data[i*filter_size + j];
filter_sum += current_data;
//logFile << "@" << i << "," << j << " -> " << current_data << std::endl;
}
}
int h, s, l;
// for each pixel
int filter_offset = ((filter_size+1)/2);
for(int x=0+filter_offset; x<working_copy->getImage()->width()-filter_offset; x++) {
for(int y=0+filter_offset; y<working_copy->getImage()->height()-filter_offset; y++) {
int intensity_sum = 0;
// sum up weighted intensity for each matrix entry
for(int fx=0; fx<filter_size; fx++) {
int dx = fx - (filter_size / 2);
for(int fy=0; fy<filter_size; fy++) {
int dy = fy - (filter_size / 2);
QColor color = QColor::fromRgb(original->getImage()->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; logFile << "done." << std::endl;
renewLogging(); renewLogging();
//updateImageDisplay(); updateImageDisplay();
} }
@ -716,7 +755,7 @@ void ImageViewer::generateControlPanels() {
filter_gui = new FilterGui(); filter_gui = new FilterGui();
apply_filter = new QPushButton("Apply filter"); 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_size_slider);
task_tab4_scrolllayout->addWidget(filter_gui->getWidget()); task_tab4_scrolllayout->addWidget(filter_gui->getWidget());

View File

@ -157,7 +157,7 @@ class ImageViewer : public QMainWindow {
void partialLinearHistogrammAdaption(); void partialLinearHistogrammAdaption();
void succeedingHistogrammAdaption(); void succeedingHistogrammAdaption();
void changeFilterSize(int s); void changeFilterSize(int s);
void applyFilter(); void applyBasicFilter();
void open(); void open();
void openReference(); void openReference();