I am working on my task in the field of computer vision. One of the subtasks is to calculate the direction of the gradient based on the brightness of the image. I made the matrix bright [width] [height] containing the brightness values for each pixel in the image. And I have two such functions:
double Image::grad_x(int x,int y){
if(x==width-1 || x==0) return bright[x][y];
return bright[x+1][y]-bright[x-1][y];
}
double Image::grad_y(int x,int y){
if(y==height-1 || y==0) return bright[x][y];
return bright[x][y+1]-bright[x][y-1];
}
EDIT: border check fixed
I work with a simple derivative, without using the Sobel operator, because for my needs a simple derivative is enough.
The question is, what am I doing this gradient calculation correctly and what exactly should I do with border pixels (right now the function returns the value of the pixel itself, im not sure if this is accurate)? And by the way, is there any utility for calculating image gradients? I want to be sure that my program works well.
Anton source
share