【问题标题】:Matlab fourier descriptors what's wrong?Matlab傅里叶描述符有什么问题?
【发布时间】:2014-12-10 02:53:07
【问题描述】:

我正在使用 Gonzalez frdescp 函数来获取边界的傅立叶描述符。我使用这段代码,我得到了两组完全不同的数字,描述了两个相同但不同的比例形状。

那么有什么问题呢?

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);

为什么对于相同但规模不同的两个圆圈,我得到不同的描述符?

【问题讨论】:

  • 你从哪里得到 frdescp?这可能是问题的根源
  • 我从 Gonzaelz 的 Digital image processing using MATLAB book 中得到它,实际上我认为 bwboundaries 是问题!
  • 我编辑了my previous answer,希望对你和其他用户有用。

标签: matlab fft fourier-descriptors


【解决方案1】:

问题是frdescp 代码(我使用this code,应该和你提到的一样)也是为了使傅立叶描述符居中而编写的。

如果您想以正确的方式描述您的形状,则必须保留一些相对于表示 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

知道了,上面的函数可以使用如下:

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);

【讨论】:

    【解决方案2】:

    我刚刚和你遇到了同样的问题。

    根据此link,如果您希望缩放不变,请使比较比率类似,例如通过将每个傅立叶系数除以 DC 系数。 f*1 = f1/f[0]、f*[2]/f[0],以此类推。因此,您需要使用 DC 系数,其中代码中的 f(1) 不是您的步骤“f = f(2:20); % 获得前 20 并删除 dc 分量”之后的实际 DC 系数.我觉得问题可以通过先保持DC系数的值来解决,调整后的代码应该如下:

    % Normalization
    DC = f(1);
    f = f(2:20); % getting the first 20 & deleting the dc component
    f = abs(f) ; % use magnitudes to be invariant to translation & rotation
    f = f/DC; % divide the Fourier coefficients by the DC-coefficient to be invariant to scale
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-05-06
      • 1970-01-01
      • 2010-10-11
      • 2015-02-16
      • 1970-01-01
      • 1970-01-01
      • 2014-05-26
      • 2012-11-28
      相关资源
      最近更新 更多