[TASK] Finish up gaussian blur filter implementation.

This commit is contained in:
Jan Philipp Timme 2015-12-18 14:18:36 +01:00
parent 55b07d48cb
commit 57b4ab7b4d
3 changed files with 12 additions and 10 deletions

View File

@ -8,6 +8,7 @@
#include <iostream>
#include <math.h>
#include "lazy_image.cpp"
class CannyEdgeMachine {
@ -79,20 +80,20 @@ class CannyEdgeMachine {
}
// apply gauss filter
int filter_offset = (filter_width+1)/2;
for(int x=0+filter_offset; x<this->width-filter_offset; x++) {
for(int y=0+filter_offset; y<this->width-filter_offset; y++) {
for(int x=(0+filter_offset); x<(this->width-filter_offset); x++) {
for(int y=(0+filter_offset); y<(this->height-filter_offset); y++) {
int sum_intensity = 0;
int h, s, l;
for(int fx=0; fx<filter_width; fx++) {
int dx = fx - (filter_width / 2);
for(int fy=0; fy<filter_width; fy++) {
int dy = fy - (filter_width / 2);
QColor color = QColor::fromRgb(this->original->getImage()->pixel(x+dx, y+dy));
QColor color = QColor::fromRgb(this->original->getPixel(x+dx, y+dy, LazyImage::DEFAULT));
color.getHsl(&h, &s, &l);
sum_intensity += (l * filter[fy*filter_width + fx]);
}
}
QColor color = QColor::fromRgb(original->getImage()->pixel(x, y));
QColor color = QColor::fromRgb(this->original->getPixel(x, y, LazyImage::DEFAULT));
color.getHsl(&h, &s, &l);
l = qRound((1.0*sum_intensity) / (1.0*sum_weights));
if(l > 255) l = 255;
@ -106,13 +107,12 @@ class CannyEdgeMachine {
void work() {
this->reset();
for(int x=0; x<this->width; x++) {
this->doGaussBlur();
/*for(int x=0; x<this->width; x++) {
for(int y=0; y<this->height; y++) {
//this->gradient_magnitude = sqrt(...)
}
}
}*/
};

View File

@ -658,7 +658,7 @@ void ImageViewer::runCannyEdge(void) {
CannyEdgeMachine cem = CannyEdgeMachine(original, working_copy);
cem.setThresholdValues(0, 0); //TODO
cem.work();
updateImageDisplay();
}
/****************************************************************************************
*

View File

@ -118,7 +118,7 @@ class LazyImage {
public:
enum overflowMode {ZERO_PADDING, CONSTANT, MIRRORED, CONTINUOUS};
enum overflowMode {DEFAULT, ZERO_PADDING, CONSTANT, MIRRORED, CONTINUOUS};
LazyImage(QImage* img) {
this->histogramm_normal_image = NULL;
@ -219,6 +219,8 @@ class LazyImage {
bool return_result = false;
QRgb result;
switch(mode) {
case DEFAULT:
break;
case ZERO_PADDING: // Return black for all out of bound requests
if(x < 0 || x >= width || y < 0 || y >= height) {
result = qRgb(0, 0, 0);