Ask Your Question
2

Digital Image Gradient

asked 2013-12-08 00:58:55 -0600

isaacenrique gravatar image

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 flag offensive close merge delete

2 answers

Sort by ยป oldest newest most voted
1

answered 2013-12-10 09:38:28 -0600

updated 2013-12-10 09:40:03 -0600

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;
        }
    }
}
edit flag offensive delete link more
0

answered 2013-12-08 04:40:46 -0600

SR gravatar image
edit flag offensive delete link more

Question Tools

Stats

Asked: 2013-12-08 00:58:55 -0600

Seen: 1,364 times

Last updated: Dec 10 '13