1Affine region detectors 2----------------------- 3 4What is being detected? 5~~~~~~~~~~~~~~~~~~~~~~~ 6 7Affine region is basically any region of the image 8that is stable under affine transformations. It can be 9edges under affinity conditions, corners (small patch of an image) 10or any other stable features. 11 12-------------- 13 14Available detectors 15~~~~~~~~~~~~~~~~~~~ 16 17At the moment, the following detectors are implemented 18 19- Harris detector 20 21- Hessian detector 22 23-------------- 24 25Algorithm steps 26~~~~~~~~~~~~~~~ 27 28Harris and Hessian 29^^^^^^^^^^^^^^^^^^ 30 31Both are derived from a concept called Moravec window. Lets have a look 32at the image below: 33 34.. figure:: ./Moravec-window-corner.png 35 :alt: Moravec window corner case 36 37 Moravec window corner case 38 39As can be noticed, moving the yellow window in any direction will cause 40very big change in intensity. Now, lets have a look at the edge case: 41 42.. figure:: ./Moravec-window-edge.png 43 :alt: Moravec window edge case 44 45 Moravec window edge case 46 47In this case, intensity change will happen only when moving in 48particular direction. 49 50This is the key concept in understanding how the two corner detectors 51work. 52 53The algorithms have the same structure: 54 551. Compute image derivatives 56 572. Compute Weighted sum 58 593. Compute response 60 614. Threshold (optional) 62 63Harris and Hessian differ in what **derivatives they compute**. Harris 64computes the following derivatives: 65 66``HarrisMatrix = [(dx)^2, dxdy], [dxdy, (dy)^2]`` 67 68(note that ``d(x^2)`` and ``(dy^2)`` are **numerical** powers, not gradient again). 69 70The three distinct terms of a matrix can be separated into three images, 71to simplify implementation. Hessian, on the other hand, computes second 72order derivatives: 73 74``HessianMatrix = [dxdx, dxdy][dxdy, dydy]`` 75 76**Weighted sum** is the same for both. Usually Gaussian blur 77matrix is used as weights, because corners should have hill like 78curvature in gradients, and other weights might be noisy. 79Basically overlay weights matrix over a corner, compute sum of 80``s[i,j]=image[x + i, y + j] * weights[i, j]`` for ``i, j`` 81from zero to weight matrix dimensions, then move the window 82and compute again until all of the image is covered. 83 84**Response computation** is a matter of choice. Given the general form 85of both matrices above 86 87``[a, b][c, d]`` 88 89One of the response functions is 90 91``response = det - k * trace^2 = a * c - b * d - k * (a + d)^2`` 92 93``k`` is called discrimination constant. Usual values are ``0.04`` - 94``0.06``. 95 96The other is simply determinant 97 98``response = det = a * c - b * d`` 99 100**Thresholding** is optional, but without it the result will be 101extremely noisy. For complex images, like the ones of outdoors, for 102Harris it will be in order of 100000000 and for Hessian will be in order 103of 10000. For simpler images values in order of 100s and 1000s should be 104enough. The numbers assume ``uint8_t`` gray image. 105 106To get deeper explanation please refer to following **paper**: 107 108`Harris, Christopher G., and Mike Stephens. "A combined corner and edge 109detector." In Alvey vision conference, vol. 15, no. 50, pp. 10-5244. 1101988. <http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.434.4816&rep=rep1&type=pdf>`__ 111 112`Mikolajczyk, Krystian, and Cordelia Schmid. "An affine invariant interest point detector." In European conference on computer vision, pp. 128-142. Springer, Berlin, Heidelberg, 2002. <https://hal.inria.fr/inria-00548252/document>`__ 113 114`Mikolajczyk, Krystian, Tinne Tuytelaars, Cordelia Schmid, Andrew Zisserman, Jiri Matas, Frederik Schaffalitzky, Timor Kadir, and Luc Van Gool. "A comparison of affine region detectors." International journal of computer vision 65, no. 1-2 (2005): 43-72. <https://hal.inria.fr/inria-00548528/document>`__ 115 116