How do I calculate gradient and hessian matrix by two operators?

4 visualizaciones (últimos 30 días)
Klara
Klara el 3 de Mzo. de 2014
Comentada: David Young el 19 de Mzo. de 2014
For each point (x,y), the gradients should be calculated by two operators like:
operator x:1/4*[1,0,-1;0,0,0;1,0,-1] operator y:1/4*[-1,0,-1;0,0,0;1,0,1]
now should I first measure the gradients by its function and then convolve them with these matrices as below? (I have no image processing toolbox)
Then hessian operators are [-1,1] for x , and [-1;1] for y. Well, I know how to generate hessian matrix but don't know how to do with these operators in a way that finally I can calculate the sum of all these measurements (their dimension would be different after convolution)

Respuestas (1)

David Young
David Young el 3 de Mzo. de 2014
On the first part of your question, I think you should not call gradient, because convolution with the operators is what calculates the gradients. This makes more sense:
opx = [1,0,-1;0,0,0;1,0,-1]/4;
opy = [-1,0,-1;0,0,0;1,0,1]/4;
Gx = conv2(im, opx);
Gy = conv2(im, opy);
However, the choice of operators puzzles me. [1 0 -1; 2 0 -1; 1 0 -1] would be a more conventional choice for an x-gradient operator.
To get the elements of the Hessian, you can convolve Gx and Gy with gradient operators, something like
Gxx = conv2(Gx, opx);
and so on. Again, the motivation for the choice of operator isn't clear - the operators [-1 1] and [-1; 1] introduce a half-pixel offset into the results, so can be an awkward choice.
An alternative approach is just to use the gradient function instead of convolution. However, convolution gives you more control, and permits the introduction of some smoothing and the use of symmetrical operators.
Depending on your data, you may well need some smoothing as well as differencing to form estimates of gradients or Hessian elements.
  8 comentarios
Klara
Klara el 18 de Mzo. de 2014
It was wrong to use conv2 instead of filter2. then there is no different dimension problem.
David Young
David Young el 19 de Mzo. de 2014
filter2 just calls conv2. Both have a 'same' option which avoids a change in size; the difference is that it is the default for filter2. In both cases the array is padded with zeros to compute values near the boundaries, which may or may not be what you want.

Iniciar sesión para comentar.

Productos

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by