diff --git a/canny_edge_machine.cpp b/canny_edge_machine.cpp index 7192919..d58863a 100644 --- a/canny_edge_machine.cpp +++ b/canny_edge_machine.cpp @@ -77,7 +77,7 @@ class CannyEdgeMachine { filter[i*filter_width + j] = pow(2, i) * pow(2, j); sum_weights += filter[i*filter_width + j]; } - } + } // apply gauss filter int filter_offset = (filter_width+1)/2; for(int x=(0+filter_offset); x<(this->width-filter_offset); x++) { @@ -105,14 +105,45 @@ class CannyEdgeMachine { free(filter); }; + void doGradiants(void) { + // build the gradiant vector + int gradiant_size = 3; + double* gradiant_vector = (double*) malloc(sizeof(double) * gradiant_size); + gradiant_vector[0] = -0.5; + gradiant_vector[1] = 0; + gradiant_vector[2] = 0.5; + int gradiant_offset = gradiant_size; + // calculate gradiants + 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; + 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; + // y gradiant + double 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; + } + } + free(gradiant_vector); + }; + void work() { this->reset(); this->doGaussBlur(); - /*for(int x=0; xwidth; x++) { - for(int y=0; yheight; y++) { - //this->gradient_magnitude = sqrt(...) - } - }*/ + this->doGradiants(); };