3m *_*asr 5 matlab fft fourier-descriptors
我正在使用Gonzalez frdescp
函数来获取边界的Fourier描述符.我使用这个代码,我得到两组完全不同的数字描述两个相同但不同的比例形状.
那有什么不对?
im = imread('c:\classes\a1.png');
im = im2bw(im);
b = bwboundaries(im);
f = frdescp(b{1}); // fourier descriptors for the boundary of the first object ( my pic only contains one object anyway )
// Normalization
f = f(2:20); // getting the first 20 & deleting the dc component
f = abs(f) ;
f = f/f(1);
Run Code Online (Sandbox Code Playgroud)
为什么我会得到相同的不同描述符 - 但规模不同 - 两个圆圈?
问题是frdescp
代码(我使用此代码,应该与您引用的相同)也是为了使傅立叶描述符居中.
如果您想以正确的方式描述您的形状,则必须保留一些与表示DC组件的描述符对称的描述符.
下图总结了这个概念:
为了解决你的问题(和你的其他人一样),我写了以下两个函数:
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
Run Code Online (Sandbox Code Playgroud)
知道了,你可以使用以下功能如下:
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);
Run Code Online (Sandbox Code Playgroud)