@@ -60,10 +60,11 @@ def elliptic_fourier_descriptors(
6060 orders = np .arange (1 , order + 1 )
6161 consts = T / (2 * orders * orders * np .pi * np .pi )
6262 phi = phi * orders .reshape ((order , - 1 ))
63+
6364 d_cos_phi = np .cos (phi [:, 1 :]) - np .cos (phi [:, :- 1 ])
6465 d_sin_phi = np .sin (phi [:, 1 :]) - np .sin (phi [:, :- 1 ])
65- cos_phi = ( dxy [:, 0 ] / dt ) * d_cos_phi
66- a = consts * np .sum (cos_phi , axis = 1 )
66+
67+ a = consts * np .sum (( dxy [:, 0 ] / dt ) * d_cos_phi , axis = 1 )
6768 b = consts * np .sum ((dxy [:, 0 ] / dt ) * d_sin_phi , axis = 1 )
6869 c = consts * np .sum ((dxy [:, 1 ] / dt ) * d_cos_phi , axis = 1 )
6970 d = consts * np .sum ((dxy [:, 1 ] / dt ) * d_sin_phi , axis = 1 )
@@ -247,10 +248,23 @@ def plot_efd(coeffs, locus=(0.0, 0.0), image=None, contour=None, n=300):
247248 )
248249 ax = plt .subplot2grid ((n_rows , N_half ), (n // N_half , n % N_half ))
249250 ax .set_title (str (n + 1 ))
250- if contour is not None :
251- ax .plot (contour [:, 1 ], contour [:, 0 ], "c--" , linewidth = 2 )
252- ax .plot (yt , xt , "r" , linewidth = 2 )
251+
253252 if image is not None :
253+ # A background image of shape [rows, cols] gets transposed
254+ # by imshow so that the first dimension is vertical
255+ # and the second dimension is horizontal.
256+ # This implies swapping the x and y axes when plotting a curve.
257+ if contour is not None :
258+ ax .plot (contour [:, 1 ], contour [:, 0 ], "c--" , linewidth = 2 )
259+ ax .plot (yt , xt , "r" , linewidth = 2 )
254260 ax .imshow (image , plt .cm .gray )
261+ else :
262+ # Without a background image, no transpose is implied.
263+ # This case is useful when (x,y) point clouds
264+ # without relation to an image are to be handled.
265+ if contour is not None :
266+ ax .plot (contour [:, 0 ], contour [:, 1 ], "c--" , linewidth = 2 )
267+ ax .plot (xt , yt , "r" , linewidth = 2 )
268+ ax .axis ("equal" )
255269
256270 plt .show ()
0 commit comments