首先:我是一个完全的菜鸟,所以为糟糕的格式道歉。
我正在按照本教程获取图像的傅立叶级数。在本教程进行到一半时,我一直遇到这部分代码的错误:
(* Fourier coefficients of a single curve *)
fourierComponentData[pointList_, nMax_, op_] :=
Module[{\[CurlyEpsilon] = 10^-3, \[Mu] = 2^14, M = 10000, s,
scale, \[CapitalDelta], L , nds, sMax,
if, \[ScriptX]\[ScriptY]Function, X, Y, XFT, YFT, type},
(* prepare curve *)
scale =
1. Mean[Table[
Max[ fl /@ pointList] -
Min[fl /@ pointList], {fl, {First, Last}}]];
\[CapitalDelta] =
EuclideanDistance[First[pointList], Last[pointList]];
L = Which[op === "Closed", type = "Closed";
If[First[pointList] === Last[pointList],
pointList, Append[pointList, First[pointList]]],
op === "Open", type = "Open"; pointList,
\[CapitalDelta] == 0., type = "Closed";
pointList,
\[CapitalDelta]/scale < op, type = "Closed";
Append[pointList, First[pointList]],
True, type = "Open";
Join[pointList, Rest[Reverse[pointList]]]];
(* re-parametrize curve by arclength *)
\[ScriptX]\[ScriptY]Function = BSplineFunction[L, SplineDegree -> 4];
nds = NDSolve[{s'[t] ==
Sqrt[\[ScriptX]\[ScriptY]Function'[
t].\[ScriptX]\[ScriptY]Function'[t]], s[0] == 0}, s,
{t, 0, 1}, MaxSteps -> 10^5,
PrecisionGoal -> 4];
(* total curve length *)
sMax = s[1] /. nds[[1]];
if =
Interpolation[
Table[{s[\[Sigma]] /. nds[[1]], \[Sigma]}, {\[Sigma], 0, 1, 1/M}]];
X[t_Real] :=
BSplineFunction[L][Max[Min[1, if[(t + Pi)/(2 Pi) sMax]] , 0]][[1]];
Y[t_Real] :=
BSplineFunction[L][Max[Min[1, if[(t + Pi)/(2 Pi) sMax]] , 0]][[2]];
(* extract Fourier coefficients *)
{XFT, YFT} =
Fourier[Table[#[N @ t], {t, -Pi + \[CurlyEpsilon],
Pi - \[CurlyEpsilon], (2 Pi -
2 \[CurlyEpsilon])/\[Mu]}]] & /@ {X, Y};
{type, 2 Pi/Sqrt[\[Mu]] *
((Transpose[
Table[{Re[#], Im[#]} &[Exp[I k Pi] #[[k + 1]]], {k, 0,
nMax}]] & /@ {XFT, YFT}))} ]
Options[fourierComponents] = {"MaxOrder" -> 180, "OpenClose" -> 0.025};
fourierComponents[pointLists_, OptionsPattern[]] :=
Monitor[Table[
fourierComponentData[pointLists[[k]],
\
If[Head[#] === List, #[[k]], #] &[ OptionValue["MaxOrder"]],
\
If[Head[#] === List, #[[k]], #] &[ OptionValue["OpenClose"]]],
{k, Length[pointLists]}],
Grid[{{Text[
Style["progress calculating Fourier coefficients",
Darker[Green, 0.66]]],
ProgressIndicator[k/Length[pointLists]]} },
Alignment -> Left, Dividers -> Center]] /;
Depth[pointLists] === 4
fCs = fourierComponents[hLines,
"OpenClose" -> Table["Closed", {Length[hLines]}]];
堆栈跟踪是:
非常感谢任何帮助。