These two functions impliment the system of elliptical Fourier shape descriptors first described by Kuhl and Giardina in "Elliptic Fourier features of a closed contour" Computer Graphics and Image Processing 18:236-258 1982. fEfourier is the forward transform which creates a "shape spectrum" of a closed x,y outline, rEfourier takes a specified number of harmonics from the spectrum and reconstructs the x,y outline. The functions are not only useful for the creation of shape descriptors but also for smoothing outlines or reducing an arbitrary outline to a specified number of points.
My rating is based on the function using the correction by Sungeun Eom below. The function is used in this scientific paper whose approach can be reverse engineered to see how the input files should look etc.
Costa, C., et al. (2011). "Shape Analysis of Agricultural Products: A Review of Recent Research Advances and Potential Application to Computer Vision." Food and Bioprocess Technology 4(5): 673-692.
I have also struggled with the normalisation functions and had to disable these to get meaningful results and to get the rEfourier script to work.
I assume that the input outline to these functions is an array of (x,y) coordinates and not a chain code as is described in the Kuhl... paper originally. Is that correct. An other thing does the outline need to be continues link of pixels or can it be a link of vectors?
This is great work and nice of you to share it with us.
Excellent codes. I have also found the same problem that You didn't check whether it is a semimajor or semiminor axis.Meanwhile, the code can use the vectorization to speed up.For example, 'rDeltaX = diff(b(:,1)); rDeltaY = diff(b(:,2));' can replace the for loop.
Thanks for your work, but I have found two bugs in calculating rTheta1 and rPsi1. You didn't check whether it is a semimajor or semiminor axis. This is one fix for the problem for your information:
2) rPsi1 (line 148)
if (rStarFSDs(3,2)~=0)
if (rStarFSDs(1,2)>=0)
rPsi1 = atan(rStarFSDs(3,2) / rStarFSDs(1,2));
else
rPsi1 = atan(rStarFSDs(3,2) / rStarFSDs(1,2)) + pi;
end
else
if (rStarFSDs(1,2)>0)
rPsi1 = atan(rStarFSDs(3,2) / rStarFSDs(1,2));
else
rPsi1 = atan(rStarFSDs(3,2) / rStarFSDs(1,2)) + pi;
end
end
07 Dec 2007
Trevor Beugeling
The algorithm works great. However, I am having some difficulties using the normalization options. If I enable either the size or orientation normalization (or both), the data returned after using the rEfourier function is not correct. Is there some extra processing that is required when converting normalized descriptors back into a closed contour?
28 Sep 2007
Graeme Penney
Overall excellent, though I suspect there may be a bug. I get much more sensible results if I omit the -1 from line 39 of fEfourier.m
iNoOfPoints = size(rDeltaT,1) - 1.