File Exchange

## Elliptic fourier for shape analysis

version 1.3 (6.65 KB) by

Implementation of elliptic fourier for shape analysis.

Updated

1) plot_chain_code(ai, color, line_width)
This function will plot the given chain code. The chain code (ai) should be in
column vector.
Example:
>> ai = [5 4 1 2 3 4 3 0 0 1 0 1 0 0 0 7 7 1 1 0 7 5 4 5 4 5 0 6 5 4 1 3 4 4 4 4 6];
>> plot_chain_code(ai)

2) plot_fourier_approx(ai, n, m, normalized, color, line_width)

This function will plot the Fourier approximation, given a chain code (ai),
number of harmonic elements (n), and number of points for reconstruction (m).
Normalization can be applied by setting "normalized = 1".

3) output = calc_traversal_dist(ai, n, m, normalized)

This function will generate position coordinates of chain code (ai). Number of
harmonic elements (n), and number of points for reconstruction (m) must be
specified.
The output is a matrix of [x1, y1; x2, y2; ...; xm, ym].

3) output = fourier_approx(ai, n, m, normalized)

This function will generate position coordinates of Fourier approximation of
chain code (ai). Number of harmonic elements (n), and number of points for
reconstruction (m) must be specified.
The output is a matrix of [x1, y1; x2, y2; ...; xm, ym].

4) output = calc_harmonic_coefficients(ai, n)

This function will calculate the n-th set of four harmonic coefficients.
The output is [an bn cn dn]

5) [A0, C0] = calc_dc_components(ai)

This function will calculate the bias coefficients A0 and C0.

6) output = calc_traversal_dist(ai)

Traversal distance is defined as accumulated distance travelled by every
component of the chain code assuming [0 0] is the starting position.
Example:
>> x = calc_traversal_dist([1 2 3])
x =
1 1
1 2
0 3

7) output = calc_traversal_time(ai)

Traversal time is defined as accumulated time consumed by every
component of the chain code.
Example:
>> x = calc_traversal_time([1 2 3])
x =

1.4142
2.4142
3.8284

### Comments and Ratings (7)

Auralius Manurung

### Auralius Manurung (view profile)

Hi Richard,
Yes, though there is a limit to it.
Yo can play with the 'n' and the 'm' parameters.
It should becoming closer and closer to the original image.

Richard

### Richard (view profile)

Hi Auralius, Thanks for making this. I see a problem when I run example 1. If I change n increasing it from 10 the resulting approximation plot does not continue to get closer to the original image. For example n of 100 is pretty much the same as n = 1000. Worse yet there is quite a bit of visible error around the figure.

Shouldn't this approach the original image as n is greatly increased?

thanks

Auralius Manurung

### Auralius Manurung (view profile)

Auralius Manurung

### Auralius Manurung (view profile)

Hi Chrstopher Cramer,

Yes! You are absolutely right!
Thanks for your feedback!

Chrstopher Cramer

### Chrstopher Cramer (view profile)

Hi Auralius, nice work. I think I've found a couple of additional errors. In both calc_harmonic_coefficients.m and calc_dc_components.m, you have a conditional:

if (p > 2)

in all of these cases, this should either be:

if (p > 1)

or maybe

if (p >= 2)

Auralius Manurung

### Auralius Manurung (view profile)

Hi João Neves,

Sorry for the late reply and thank you for your valuable inputs.

You are definitely right. I will fix this in the next update.

Cheers,
Auralius

João Neves

### João Neves (view profile)

Fantastic work, however I would like to know if there is an error in the calc_dc_components function.
Is this line correct?

sum_c0 = sum_c0 + delta_x / (2 * delta_t) * (t(p))^2 + delta * t(p);

or it should be

sum_c0 = sum_c0 + delta_y / (2 * delta_t) * (t(p))^2 + delta * t(p);

Thanks again for this great work

 19 May 2016 1.3 Updated as per feedback from Chrstopher Cramer. 27 Nov 2012 1.3 Corrected mistake on the equation based on João Neves' suggestion. 8 Sep 2011 1.1 Added function descriptions for better understanding
##### MATLAB Release
MATLAB 7.8 (R2009a)
##### Acknowledgements

Inspired by: Elliptical Fourier shape descriptors

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.