Greetings .

I want to implement the Fast Radial Symmetry Transform (described here http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.97.4064&rep=rep1&type=pdf) to identify nuclei of cells in histological images of breast cancer for this I need to first calculate the gradient of the image. Until now he had not reviewed very afond what the gradient of a digital image is itself. Now I have several questions I would like to clarify:

(1) According understand the gradient of each point of a function is a vector formed by the partial derivatives of each variable, so for a digital image (which is a discretization of a 2D function) the gradient at each point in the image? which is exactly?. I guess it should be a two-channel digital image or am I wrong?

(2) How I can calculate or approximate the gradient of an image?

(3) Is there a function in OpenCV to compute or approximate the gradient of an image?

Thanks in advance for any help and/or suggestions and I apologize if my questions seem silly or too elementary .

edit retag close merge delete

Sort by » oldest newest most voted

In opencv you can use sobel functions, or write your own functions: For horizontal gradient compare pixelwit coordinates (x-1,y) and (x+1,y) i.e. gard(x,y)=abs(image(x-1,y)-image.(x+1,y)); Analogously for the Y gradient.

p.p. Here, that are my functions for calculating gradient on gray scale image. They are working with a pointer to the data stored in the matrix. The output matrices are 64bit, but 16 will do the job too, just change the cast and the constructor.

void gradx (Mat input, Mat &output)
{
output=Mat::zeros(input.size(),CV_64FC1);
for(int y=0;y<input.rows;y++)
{
for(int x=1;x<input.cols-1;x++)
{
*((double*)output.data+y*output.cols+x)=(double)(*(input.data+y*input.cols+x+1)-*(input.data+y*input.cols+x-1))/2;
}
}
}

void grady (Mat input, Mat &output)
{
output=Mat::zeros(input.size(),CV_64FC1);
for(int y=1;y<input.rows-1;y++)
{
for(int x=0;x<input.cols;x++)
{
*((double*)output.data+y*output.cols+x)=(double)(*(input.data+(y+1)*input.cols+x)-*(input.data+(y-1)*input.cols+x))/2;
}
}
}

more
more

Official site

GitHub

Wiki

Documentation