How do I calculate gradient and hessian matrix by two operators?
4 ビュー (過去 30 日間)
古いコメントを表示
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)
0 件のコメント
回答 (1 件)
David Young
2014 年 3 月 3 日
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 件のコメント
David Young
2014 年 3 月 19 日
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.
参考
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!