Il problema è che il codice frdescp
(ho usato this code, che dovrebbe essere lo stesso di cui si è fatto riferimento) viene scritto anche per centrare i descrittori di Fourier.
Se si desidera descrivere la forma in modo corretto, è obbligatorio mantenere alcuni descrittori simmetrici rispetto a quello che rappresenta il componente CC.
L'immagine seguente riassume il concetto:
Al fine di risolvere il problema (e altri come la vostra), ho scritto le seguenti due funzioni:
function descriptors = fourierdescriptor(boundary)
%I assume that the boundary is a N x 2 matrix
%Also, N must be an even number
np = size(boundary, 1);
s = boundary(:, 1) + i*boundary(:, 2);
descriptors = fft(s);
descriptors = [descriptors((1+(np/2)):end); descriptors(1:np/2)];
end
function significativedescriptors = getsignificativedescriptors(alldescriptors, num)
%num is the number of significative descriptors (in your example, is was 20)
%In the following, I assume that num and size(alldescriptors,1) are even numbers
dim = size(alldescriptors, 1);
if num >= dim
significativedescriptors = alldescriptors;
else
a = (dim/2 - num/2) + 1;
b = dim/2 + num/2;
significativedescriptors = alldescriptors(a : b);
end
end
so, può utilizzare le funzioni di cui sopra come segue:
im = imread('test.jpg');
im = im2bw(im);
b = bwboundaries(im);
b = b{1};
%force the number of boundary points to be even
if mod(size(b,1), 2) ~= 0
b = [b; b(end, :)];
end
%define the number of significative descriptors I want to extract (it must be even)
numdescr = 20;
%Now, you can extract all fourier descriptors...
f = fourierdescriptor(b);
%...and get only the most significative:
f_sign = getsignificativedescriptors(f, numdescr);
fonte
2014-05-19 15:01:40
da dove hai preso il frdescp? potrebbe essere la fonte del problema – Rasman
L'ho ottenuto dall'elaborazione delle immagini digitali di Gonzaelz usando il libro MATLAB, in realtà penso che il problema siano i bwboundary! –
Ho modificato [la mia risposta precedente] (http://stackoverflow.com/a/23741097/738017), spero che possa essere utile a voi e ad altri utenti. –