Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -10,25 +10,25 @@ from math import tau
|
|
10 |
from PIL import Image
|
11 |
|
12 |
|
13 |
-
def fourier_transform_drawing(input_image, frames, coefficients):
|
14 |
# Convert PIL to OpenCV image(array)
|
15 |
input_image = np.array(input_image)
|
16 |
img = cv2.cvtColor(input_image, cv2.COLOR_RGB2BGR)
|
17 |
|
18 |
# processing
|
19 |
-
#
|
20 |
-
|
21 |
-
|
22 |
-
dim = (width, height)
|
23 |
-
resized = cv2.resize(img, dim, interpolation=cv2.INTER_AREA)
|
24 |
|
25 |
-
imgray = cv2.cvtColor(
|
26 |
blurred = cv2.GaussianBlur(imgray, (5, 5), 0)
|
27 |
(_, thresh) = cv2.threshold(blurred, 0, 255, cv2.THRESH_BINARY_INV | cv2.THRESH_OTSU)
|
28 |
contours, _ = cv2.findContours(thresh, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
|
29 |
|
30 |
-
#
|
31 |
-
largest_contour_idx = np.argmax([
|
|
|
|
|
32 |
verts = [tuple(coord) for coord in contours[largest_contour_idx].squeeze()]
|
33 |
|
34 |
xs, ys = zip(*verts)
|
@@ -115,7 +115,8 @@ interface = gr.Interface(
|
|
115 |
inputs=[
|
116 |
gr.Image(label="Input Image", sources=['upload'], type="pil"),
|
117 |
gr.Slider(minimum=5, maximum=500, value=100, label="Number of Frames"),
|
118 |
-
gr.Slider(minimum=1, maximum=500, value=50, label="Number of Coefficients")
|
|
|
119 |
],
|
120 |
outputs=gr.Video(),
|
121 |
title="Fourier Transform Drawing",
|
|
|
10 |
from PIL import Image
|
11 |
|
12 |
|
13 |
+
def fourier_transform_drawing(input_image, frames, coefficients, img_size):
|
14 |
# Convert PIL to OpenCV image(array)
|
15 |
input_image = np.array(input_image)
|
16 |
img = cv2.cvtColor(input_image, cv2.COLOR_RGB2BGR)
|
17 |
|
18 |
# processing
|
19 |
+
# resize the image to a smaller size for faster processing
|
20 |
+
dim = (img_size, img_size)
|
21 |
+
img = cv2.resize(img, dim, interpolation=cv2.INTER_AREA)
|
|
|
|
|
22 |
|
23 |
+
imgray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
|
24 |
blurred = cv2.GaussianBlur(imgray, (5, 5), 0)
|
25 |
(_, thresh) = cv2.threshold(blurred, 0, 255, cv2.THRESH_BINARY_INV | cv2.THRESH_OTSU)
|
26 |
contours, _ = cv2.findContours(thresh, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
|
27 |
|
28 |
+
# find the contour with the largest area
|
29 |
+
largest_contour_idx = np.argmax([cv2.contourArea(c) for c in contours])
|
30 |
+
largest_contour = contours[largest_contour_idx]
|
31 |
+
#largest_contour_idx = np.argmax([len(c) for c in contours])
|
32 |
verts = [tuple(coord) for coord in contours[largest_contour_idx].squeeze()]
|
33 |
|
34 |
xs, ys = zip(*verts)
|
|
|
115 |
inputs=[
|
116 |
gr.Image(label="Input Image", sources=['upload'], type="pil"),
|
117 |
gr.Slider(minimum=5, maximum=500, value=100, label="Number of Frames"),
|
118 |
+
gr.Slider(minimum=1, maximum=500, value=50, label="Number of Coefficients"),
|
119 |
+
gr.Number(value=224, label="Image size", precision=0)
|
120 |
],
|
121 |
outputs=gr.Video(),
|
122 |
title="Fourier Transform Drawing",
|