diff --git a/canny_edge_machine.cpp b/canny_edge_machine.cpp index d58863a..181b527 100644 --- a/canny_edge_machine.cpp +++ b/canny_edge_machine.cpp @@ -60,11 +60,11 @@ class CannyEdgeMachine { void reset(void) { for(int i=0; ipixels; i++) { - this->gradient_magnitude = 0; - this->maximum_magnitude = 0; - this->binary_edge_pixels = 0; - this->gradient_x = 0; - this->gradient_y = 0; + this->gradient_magnitude[i] = 0; + this->maximum_magnitude[i] = 0; + this->binary_edge_pixels[i] = 0; + this->gradient_x[i] = 0; + this->gradient_y[i] = 0; } }; @@ -112,39 +112,61 @@ class CannyEdgeMachine { gradiant_vector[0] = -0.5; gradiant_vector[1] = 0; gradiant_vector[2] = 0.5; - int gradiant_offset = gradiant_size; + int gradiant_offset = gradiant_size/2; // calculate gradiants + double sum_intensity; for(int x=(0+gradiant_offset); x<(this->width-gradiant_offset); x++) { for(int y=(0+gradiant_offset); y<(this->height-gradiant_offset); y++) { int h, s, l; // x gradiant - double sum_intensity = 0; + sum_intensity = 0; for(int i=0; ioriginal->getPixel(x+dx, y, LazyImage::DEFAULT)); color.getHsl(&h, &s, &l); sum_intensity += l * gradiant_vector[i]; } - this->gradient_x[y*width + x] = sum_intensity; + this->gradient_x[y*this->width + x] = sum_intensity; // y gradiant - double sum_intensity = 0; + sum_intensity = 0; for(int i=0; ioriginal->getPixel(x, y+dy, LazyImage::DEFAULT)); color.getHsl(&h, &s, &l); sum_intensity += l * gradiant_vector[i]; } - this->gradient_y[y*width + x] = sum_intensity; + this->gradient_y[y*this->width + x] = sum_intensity; } } free(gradiant_vector); }; + void doGradiantMagnitude(void) { + for(int x=0; xwidth; x++) { + for(int y=0; yheight; y++) { + int gradiant_x = this->gradient_x[y*this->width + x]; + int gradiant_y = this->gradient_y[y*this->width + x]; + this->gradient_magnitude[y*this->width + x] = sqrt(pow(gradiant_x, 2) + pow(gradiant_y, 2)); + } + } + }; + + void filterLocalMaxima(void) { + for(int x=1; xwidth-2; x++) { + for(int y=1; yheight-2; y++) { + double dx = this->gradient_x[y*this->width + x]; + double dy = this->gradient_y[y*this->width + x]; + } + } + }; + void work() { this->reset(); this->doGaussBlur(); this->doGradiants(); - + this->doGradiantMagnitude(); + this->filterLocalMaxima(); + // TraceAndThreshold }; };