Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -49,19 +49,33 @@ def fourier_transform_drawing(input_image, frames, coefficients, img_size):
|
|
49 |
|
50 |
t_list = np.linspace(0, tau, len(xs))
|
51 |
|
52 |
-
# compute the Fourier coefficients
|
53 |
def f(t, t_list, xs, ys):
|
54 |
-
return np.interp(t, t_list, xs + 1j*ys)
|
55 |
-
|
56 |
-
def compute_cn(f, n):
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
|
|
63 |
return coef
|
64 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
65 |
N = coefficients
|
66 |
coefs = [(compute_cn(f, 0), 0)] + [(compute_cn(f, j), j) for i in range(1, N+1) for j in (i, -i)]
|
67 |
|
@@ -121,7 +135,7 @@ interface = gr.Interface(
|
|
121 |
outputs=gr.Video(),
|
122 |
title="Fourier Transform Drawing",
|
123 |
description="Upload an image and generate a Fourier Transform drawing animation. You can find out more about the project here : https://github.com/staghado/fourier-draw",
|
124 |
-
examples=[["Fourier2.jpg", 100, 100], ["Luffy.png",
|
125 |
)
|
126 |
|
127 |
if __name__ == "__main__":
|
|
|
49 |
|
50 |
t_list = np.linspace(0, tau, len(xs))
|
51 |
|
|
|
52 |
def f(t, t_list, xs, ys):
|
53 |
+
return np.interp(t, t_list, xs + 1j * ys)
|
54 |
+
|
55 |
+
def compute_cn(f, n, t_list, xs, ys):
|
56 |
+
num_points = 1000 # Adjust this based on required precision
|
57 |
+
t_values = np.linspace(0, tau, num_points)
|
58 |
+
|
59 |
+
# Vectorized operation
|
60 |
+
integrand = f(t_values, t_list, xs, ys) * np.exp(-n * t_values * 1j)
|
61 |
+
|
62 |
+
coef = np.trapz(integrand, t_values) / tau
|
63 |
return coef
|
64 |
|
65 |
+
|
66 |
+
# # compute the Fourier coefficients
|
67 |
+
# def f(t, t_list, xs, ys):
|
68 |
+
# return np.interp(t, t_list, xs + 1j*ys)
|
69 |
+
|
70 |
+
# def compute_cn(f, n):
|
71 |
+
# coef = 1/tau*quad_vec(
|
72 |
+
# lambda t: f(t, t_list, xs, ys)*np.exp(-n*t*1j),
|
73 |
+
# 0,
|
74 |
+
# tau,
|
75 |
+
# limit=100,
|
76 |
+
# full_output=False)[0]
|
77 |
+
# return coef
|
78 |
+
|
79 |
N = coefficients
|
80 |
coefs = [(compute_cn(f, 0), 0)] + [(compute_cn(f, j), j) for i in range(1, N+1) for j in (i, -i)]
|
81 |
|
|
|
135 |
outputs=gr.Video(),
|
136 |
title="Fourier Transform Drawing",
|
137 |
description="Upload an image and generate a Fourier Transform drawing animation. You can find out more about the project here : https://github.com/staghado/fourier-draw",
|
138 |
+
examples=[["Fourier2.jpg", 100, 100, 224], ["Luffy.png", 150, 200, 224]]
|
139 |
)
|
140 |
|
141 |
if __name__ == "__main__":
|