[TASK] Finish up gaussian blur filter implementation.
This commit is contained in:
parent
55b07d48cb
commit
57b4ab7b4d
|
@ -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(...)
|
||||
}
|
||||
}
|
||||
|
||||
}*/
|
||||
|
||||
};
|
||||
|
||||
|
|
|
@ -658,7 +658,7 @@ void ImageViewer::runCannyEdge(void) {
|
|||
CannyEdgeMachine cem = CannyEdgeMachine(original, working_copy);
|
||||
cem.setThresholdValues(0, 0); //TODO
|
||||
cem.work();
|
||||
|
||||
updateImageDisplay();
|
||||
}
|
||||
/****************************************************************************************
|
||||
*
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue