[TASK] Finish up gaussian blur filter implementation.
This commit is contained in:
parent
55b07d48cb
commit
57b4ab7b4d
@ -8,6 +8,7 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
#include "lazy_image.cpp"
|
||||||
|
|
||||||
class CannyEdgeMachine {
|
class CannyEdgeMachine {
|
||||||
|
|
||||||
@ -79,20 +80,20 @@ class CannyEdgeMachine {
|
|||||||
}
|
}
|
||||||
// apply gauss filter
|
// apply gauss filter
|
||||||
int filter_offset = (filter_width+1)/2;
|
int filter_offset = (filter_width+1)/2;
|
||||||
for(int x=0+filter_offset; x<this->width-filter_offset; x++) {
|
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 y=(0+filter_offset); y<(this->height-filter_offset); y++) {
|
||||||
int sum_intensity = 0;
|
int sum_intensity = 0;
|
||||||
int h, s, l;
|
int h, s, l;
|
||||||
for(int fx=0; fx<filter_width; fx++) {
|
for(int fx=0; fx<filter_width; fx++) {
|
||||||
int dx = fx - (filter_width / 2);
|
int dx = fx - (filter_width / 2);
|
||||||
for(int fy=0; fy<filter_width; fy++) {
|
for(int fy=0; fy<filter_width; fy++) {
|
||||||
int dy = fy - (filter_width / 2);
|
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);
|
color.getHsl(&h, &s, &l);
|
||||||
sum_intensity += (l * filter[fy*filter_width + fx]);
|
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);
|
color.getHsl(&h, &s, &l);
|
||||||
l = qRound((1.0*sum_intensity) / (1.0*sum_weights));
|
l = qRound((1.0*sum_intensity) / (1.0*sum_weights));
|
||||||
if(l > 255) l = 255;
|
if(l > 255) l = 255;
|
||||||
@ -106,13 +107,12 @@ class CannyEdgeMachine {
|
|||||||
|
|
||||||
void work() {
|
void work() {
|
||||||
this->reset();
|
this->reset();
|
||||||
|
this->doGaussBlur();
|
||||||
for(int x=0; x<this->width; x++) {
|
/*for(int x=0; x<this->width; x++) {
|
||||||
for(int y=0; y<this->height; y++) {
|
for(int y=0; y<this->height; y++) {
|
||||||
//this->gradient_magnitude = sqrt(...)
|
//this->gradient_magnitude = sqrt(...)
|
||||||
}
|
}
|
||||||
}
|
}*/
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -658,7 +658,7 @@ void ImageViewer::runCannyEdge(void) {
|
|||||||
CannyEdgeMachine cem = CannyEdgeMachine(original, working_copy);
|
CannyEdgeMachine cem = CannyEdgeMachine(original, working_copy);
|
||||||
cem.setThresholdValues(0, 0); //TODO
|
cem.setThresholdValues(0, 0); //TODO
|
||||||
cem.work();
|
cem.work();
|
||||||
|
updateImageDisplay();
|
||||||
}
|
}
|
||||||
/****************************************************************************************
|
/****************************************************************************************
|
||||||
*
|
*
|
||||||
|
@ -118,7 +118,7 @@ class LazyImage {
|
|||||||
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
enum overflowMode {ZERO_PADDING, CONSTANT, MIRRORED, CONTINUOUS};
|
enum overflowMode {DEFAULT, ZERO_PADDING, CONSTANT, MIRRORED, CONTINUOUS};
|
||||||
|
|
||||||
LazyImage(QImage* img) {
|
LazyImage(QImage* img) {
|
||||||
this->histogramm_normal_image = NULL;
|
this->histogramm_normal_image = NULL;
|
||||||
@ -219,6 +219,8 @@ class LazyImage {
|
|||||||
bool return_result = false;
|
bool return_result = false;
|
||||||
QRgb result;
|
QRgb result;
|
||||||
switch(mode) {
|
switch(mode) {
|
||||||
|
case DEFAULT:
|
||||||
|
break;
|
||||||
case ZERO_PADDING: // Return black for all out of bound requests
|
case ZERO_PADDING: // Return black for all out of bound requests
|
||||||
if(x < 0 || x >= width || y < 0 || y >= height) {
|
if(x < 0 || x >= width || y < 0 || y >= height) {
|
||||||
result = qRgb(0, 0, 0);
|
result = qRgb(0, 0, 0);
|
||||||
|
Loading…
Reference in New Issue
Block a user