ImageCorners.jl
ImageCorners.jl provides image corner related algorithms in Julia.
Supported Algorithms
- Harris
- Shi-Tomasi
- Kitchen and Rosenfeld
- FAST Corners
These Algorithms can be accessed using the following methods:
julia> using ImageCorners, TestImages
julia> img = testimage("mandrill");
# corner detection using harris method
julia> corners = imcorner(img; method = harris);
# threshold can be specified for the thresolding the corner pixels
julia> corners = imcorner(img, 0.001; method = harris);
julia> corners = imcorner(img, Percentile(95); method = harris);
# for corner detection to subpixel precision imgcorner_subpixel can be used
julia> corners = imcorner_subpixel(img; method = harris);
ImageCorners.HomogeneousPoint
— TypeHomogeneousPoint(x::NTuple{N, T}) In projective geometry homogeneous coordinates are the natural coordinates for describing points and lines. For instance, the homogeneous coordinates for a planar point are a triplet of real numbers $(u, v ,w)$, with $w \neq 0$. This triple can be associated with a point $P = (x,y)$ in Cartesian coordinates, where $x = \frac{u}{w}$ and $y = \frac{v}{w}$ (more details). In particular, the HomogeneousPoint((10.0,5.0,1.0))
is the standardised projective representation of the Cartesian point (10.0,5.0)
.
ImageCorners.Percentile
— TypePercentile(x)
Indicate that x
should be interpreted as a percentile rather than an absolute value. For example,
canny(img, 1.4, (80, 20))
uses absolute thresholds on the edge magnitude imagecanny(img, 1.4, (Percentile(80), Percentile(20)))
uses percentiles of the edge magnitude image as threshold
ImageCorners.corner2subpixel
— Methodcorners = corner2subpixel(responses::AbstractMatrix,corner_indicator::AbstractMatrix{Bool})
-> Vector{HomogeneousPoint{Float64,3}}
Refines integer corner coordinates to sub-pixel precision. The function takes as input a matrix representing corner responses and a boolean indicator matrix denoting the integer coordinates of a corner in the image. The output is a vector of type HomogeneousPoint
storing the sub-pixel coordinates of the corners. The algorithm computes a correction factor which is added to the original integer coordinates. In particular, a univariate quadratic polynomial is fit separately to the $x$-coordinates and $y$-coordinates of a corner and its immediate east/west, and north/south neighbours. The fit is achieved using a local coordinate system for each corner, where the origin of the coordinate system is a given corner, and its immediate neighbours are assigned coordinates of minus one and plus one. The corner and its two neighbours form a system of three equations. For example, let $x_1 = -1$, $x_2 = 0$ and $x_3 = 1$ denote the local $x$ coordinates of the west, center and east pixels and let the vector $\mathbf{b} = [r_1, r_2, r_3]$ denote the corresponding corner response values. With
\[ \mathbf{A} = \begin{bmatrix} x_1^2 & x_1 & 1 \\ x_2^2 & x_2 & 1 \\ x_3^2 & x_3 & 1 \\ \end{bmatrix},\]
the coefficients of the quadratic polynomial can be found by solving the system of equations $\mathbf{b} = \mathbf{A}\mathbf{x}$. The result is given by $x = \mathbf{A}^{-1}\mathbf{b}$. The vertex of the quadratic polynomial yields a sub-pixel estimate of the true corner position. For example, for a univariate quadratic polynomial $px^2 + qx + r$, the $x$-coordinate of the vertex is $\frac{-q}{2p}$. Hence, the refined sub-pixel coordinate is equal to: $c + \frac{-q}{2p}$, where $c$ is the integer coordinate.
Corners on the boundary of the image are not refined to sub-pixel precision.
ImageCorners.fastcorners
— Methodfastcorners(img, n, threshold) -> corners
Performs FAST Corner Detection. n
is the number of contiguous pixels which need to be greater (lesser) than intensity + threshold (intensity - threshold) for a pixel to be marked as a corner. The default value for n is 12.
ImageCorners.harris
— Methodharris_response = harris(img; [k], [border], [weights])
Performs Harris corner detection. The covariances can be taken using either a mean weighted filter or a gamma kernel.
ImageCorners.imcorner
— Methodcorners = imcorner(img; [method])
corners = imcorner(img, threshold; [method])
Performs corner detection using one of the following methods - 1. harris 2. shitomasi 3. kitchenrosenfeld The parameters of the individual methods are described in their documentation. The maxima values of the resultant responses are taken as corners. If a threshold is specified, the values of the responses are thresholded to give the corner pixels. If threshold
is a Percentile
then its type will be preserved.
ImageCorners.imcorner_subpixel
— Methodcorners = imcorner_subpixel(img; [method])
-> Vector{HomogeneousPoint{Float64,3}}
corners = imcorner_subpixel(img, threshold, percentile; [method])
-> Vector{HomogeneousPoint{Float64,3}}
Same as imcorner
, but estimates corners to sub-pixel precision. Sub-pixel precision is achieved by interpolating the corner response values using the 4-connected neighbourhood of a maximum response value. See corner2subpixel
for more details of the interpolation scheme.
ImageCorners.kitchen_rosenfeld
— Methodkitchen_rosenfeld_response = kitchen_rosenfeld(img; [border])
Performs Kitchen Rosenfeld corner detection. The covariances can be taken using either a mean weighted filter or a gamma kernel.
ImageCorners.shi_tomasi
— Methodshi_tomasi_response = shi_tomasi(img; [border], [weights])
Performs Shi Tomasi corner detection. The covariances can be taken using either a mean weighted filter or a gamma kernel.
ImageCorners.unsafe_neighbourhood_4
— Methodunsafe_neighbourhood_4(matrix::AbstractMatrix,r::Int,c::Int)
Returns the value of a matrix at given coordinates together with the values of the north, south, east and west neighbours. This function does not perform bounds checking. It is up to the user to ensure that the function is not called with indices that are on the boundary of the matrix.