Content
- Chain codes
- Elliptical Fourier Descriptors
Computer Vision CMP-6035B
Dr. David Greenwood
Shapes compactly describe objects in images.
A shape in an image could be represented using the coordinates of edge pixels.
Pixel coordinates encode the shape and the location
We are not interested in where the shape is - just the representation of the shape itself.
Rather than represent edge pixels in terms of image coordinates, represent each pixel as a direction.
In which direction must we move to stay on the edge?
Assume:
\(6 6 7 0 1 1 2 3 5 3 5\)
For invariance to starting location:
Chain codes are translation invariant.
Chain codes are not scale or rotation invariant.
Chain codes specify a direction in absolute terms.
This idea can be extended to use a relative encoding.
Represent the next direction as the number of turns required to stay on the shape boundary.
In this case, 0 corresponds to straightforward.
This is a chain code derivative or differential chain code.
To compute the chain code derivative:
Need to be careful with the starting element.
NB: pay attention to modulus of negative numbers.
Chain code derivative provides rotational invariance for rotations of 90 degrees.
Chain codes describe a specific instance of a shape.
A parametric representation of a shape.
A Fourier series is an expansion of a periodic function \(f(x)\) in terms of an infinite sum of sines and cosines.
We can approximate non-periodic functions on a specific interval.
The Fourier series of a periodic function \(f(t)\) of period \(T\) is:
\[ f(t) = \frac{a_0}{2} + \sum_{n=1}^{\infty} \left[ a_n \cos \frac{2 \pi n t}{T} + b_n \sin \frac{2 \pi n t}{T} \right] \]
for some set of Fourier coefficients \(a_n\) and \(b_n\) defined by the integrals:
\[ a_n = \frac{2}{T} \int_{0}^{T} f(t) \cos \frac{2 \pi n t}{T} \mathrm{d}t,~ b_n = \frac{2}{T} \int_{0}^{T} f(t) \sin \frac{2 \pi n t}{T} \mathrm{d}t. \]
A function is even when:
\[f(x) = f(-x) \text{ for all } x\]
It has reflective symmetry about the y-axis, e.g. \(x^2\) or \(cos(x)\).
We can approximate even functions using only cosine coefficients.
A function is odd when:
\[ -f(x) = f(-x) \text{ for all } x\]
It rotational symmetry about the origin, e.g. \(x^3\) or \(sin(x)\).
We can approximate even functions using only sine coefficients.
It is useful to know about odd and even functions, but generally we will need to know both coefficients.
How do we go from Chain encodings to EFDs?
The projection of the first \(p\) links is the sum of differences between all previous links.
\[x_p = \sum_{i-1}^{p} \Delta x_i, ~ y_p = \sum_{i-1}^{p} \Delta y_i \]
For the x-projection:
Similarly, for the y-projection:
We will consider the “time” derivative of the chain.
Time here means the length of the chain.
\[t_p = \sum_{i-1}^{p} \Delta t_i \]
Calculate the Fourier expansion for the x-projection.
\[ x(t) = \frac{a_0}{2} + \sum_{n=1}^{\infty} \left[ a_n \cos \frac{2 \pi n t}{T} + b_n \sin \frac{2 \pi n t}{T} \right] \]
NB: not to infinity, but to some useful number of coefficients.
where:
\[\frac{a_0}{2} = \frac{1}{T} \int_{0}^{T} x(t) ~\mathrm{d}t\]
and \(T\) is the length of the chain.
again, from the definition:
\[ a_n = \frac{2}{T} \int_{0}^{T} x(t) \cos \frac{2 \pi n t}{T} ~\mathrm{d}t,~ b_n = \frac{2}{T} \int_{0}^{T} x(t) \sin \frac{2 \pi n t}{T} ~\mathrm{d}t. \]
How can we calculate these coefficients?
The time derivative of \(x\) is periodic with period \(T\) and can itself be represented by the Fourier series:
\[ x'(t) = \sum_{n=1}^{\infty} \alpha_n \cos \frac{2 \pi n t}{T} + \beta_n \sin \frac{2 \pi n t}{T} \]
where:
\[ \alpha_n = \frac{2}{T} \int_{0}^{T} x'(t) \cos \frac{2 \pi n t}{T} \mathrm{d}t~, \beta_n = \frac{2}{T} \int_{0}^{T} x'(t) \sin \frac{2 \pi n t}{T} \mathrm{d}t \]
then:
\[ \alpha_n = \frac{2}{T} \int_{0}^{T} x'(t) \cos \frac{2 \pi n t}{T} \mathrm{d}t \]
The difference here is our chain code is a piecewise linear function, so the time derivative is constant.
\[ \begin{aligned} \alpha_n &= \frac{2}{T} \int_{0}^{T} x'(t) \cos \frac{2 \pi n t}{T} \mathrm{d}t \\ &= \frac{2}{T} \sum_{p=1}^{K} \frac{\Delta x_p}{\Delta t_p} \int_{t_{p-1}}^{t_p} \cos \frac{2 \pi n t}{T} \mathrm{d}t \end{aligned} \]
The “trick” is to notice that the integral over the whole period is a summation of the \(K\) chain links, and the derivative is a constant: the change in direction over the change in length.
finally, we take the antiderivative of the cosine term:
\[ \begin{aligned} \alpha_n &= \frac{2}{T} \int_{0}^{T} x'(t) \cos \frac{2 \pi n t}{T} \mathrm{d}t \\ &= \frac{2}{T} \sum_{p=1}^{K} \frac{\Delta x_p}{\Delta t_p} \int_{t_{p-1}}^{t_p} \cos \frac{2 \pi n t}{T} \mathrm{d}t \\ &= \frac{1}{n\pi} \sum_{p=1}^{K} \frac{\Delta x_p}{\Delta t_p} \left( \sin \frac{2 \pi n t_p}{T} - \sin \frac{2 \pi n t_{p-1}}{T} \right) \end{aligned} \]
similarly, we can calculate:
\[ \beta_n = \frac{1}{n\pi} \sum_{p=1}^{K} \frac{\Delta x_p}{\Delta t_p} \left( \cos\frac{2 \pi n t_p}{T} - \cos \frac{2 \pi n t_{p-1}}{T} \right) \]
We can also obtain \(x'(t)\) directly from the \(x(t)\) definition:
\[ x(t) = \frac{a_0}{2} + \sum_{n=1}^{\infty} a_n \cos \frac{2 \pi n t}{T} + b_n \sin \frac{2 \pi n t}{T} \]
\[ x'(t) = \sum_{n=1}^{\infty} - \frac{2 \pi n t}{T} a_n \sin \frac{2 \pi n t}{T} + \frac{2 \pi n t}{T} b_n \cos \frac{2 \pi n t}{T} \]
If we compare both derivations of \(x'(t)\):
\[ x'(t) = \sum_{n=1}^{\infty} \alpha_n \cos \frac{2 \pi n t}{T} + \beta_n \sin \frac{2 \pi n t}{T} \]
\[ x'(t) = \sum_{n=1}^{\infty} - \frac{2 \pi n t}{T} a_n \sin \frac{2 \pi n t}{T} + \frac{2 \pi n t}{T} b_n \cos \frac{2 \pi n t}{T} \]
we can equate coefficients from both equations:
\[ - \frac{2 \pi n t}{T} a_n = \beta_n , ~ \frac{2 \pi n t}{T} b_n = \alpha_n \]
and solve for \(a_n\) and \(b_n\) yielding the x projection coefficients:
\[ a_n = \frac{T}{2n^2\pi^2} \sum_{p=1}^{K} \frac{\Delta x_p}{\Delta t_p} \left( \cos \frac{2 \pi n t_p}{T} - \cos \frac{2 \pi n t_{p-1}}{T} \right) \]
\[ b_n = \frac{T}{2n^2\pi^2} \sum_{p=1}^{K} \frac{\Delta x_p}{\Delta t_p} \left( \sin \frac{2 \pi n t_p}{T} - \sin \frac{2 \pi n t_{p-1}}{T} \right) \]
we can also solve for the \(y\) projection in the same way:
\[ c_n = \frac{T}{2n^2\pi^2} \sum_{p=1}^{K} \frac{\Delta y_p}{\Delta t_p} \left( \cos \frac{2 \pi n t_p}{T} - \cos \frac{2 \pi n t_{p-1}}{T} \right) \]
\[ d_n = \frac{T}{2n^2\pi^2} \sum_{p=1}^{K} \frac{\Delta y_p}{\Delta t_p} \left( \sin \frac{2 \pi n t_p}{T} - \sin \frac{2 \pi n t_{p-1}}{T} \right) \]
We now know everything we need to calculate the Fourier series coefficients for the \(x\) and \(y\) projections.
The DC component determines the centre position of the ellipse.
For those interested, the calculation can be found here:
“Kuhl, Giardina; Elliptic Fourier Features of a Closed Contour, Computer Graphics and Image Processing, 1982”
Chain Codes
Elliptical Fourier Descriptors (EFDs)