[TASK] Begin implementing basic gradiant parts for canny edge.
This commit is contained in:
parent
57b4ab7b4d
commit
9c3cceef31
@ -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; i<gradiant_size; i++) {
|
||||
int dx = i - gradiant_size/2;
|
||||
QColor color = QColor::fromRgb(this->original->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; i<gradiant_size; i++) {
|
||||
int dy = i - gradiant_size/2;
|
||||
QColor color = QColor::fromRgb(this->original->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; x<this->width; x++) {
|
||||
for(int y=0; y<this->height; y++) {
|
||||
//this->gradient_magnitude = sqrt(...)
|
||||
}
|
||||
}*/
|
||||
this->doGradiants();
|
||||
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user