Spaces:
Running
Running
tori29umai
commited on
Commit
•
3c53cb7
1
Parent(s):
cd6fb4e
Update application file
Browse files
app.py
CHANGED
@@ -29,38 +29,6 @@ def process_XDoG(image_path):
|
|
29 |
binarized_image = binarize_image(xdog_image)
|
30 |
return Image.fromarray(binarized_image)
|
31 |
|
32 |
-
# 主要な色を取得する関数
|
33 |
-
def get_major_colors(image, threshold_percentage=0.01):
|
34 |
-
if image.mode != 'RGB':
|
35 |
-
image = image.convert('RGB')
|
36 |
-
color_count = defaultdict(int)
|
37 |
-
for pixel in image.getdata():
|
38 |
-
color_count[pixel] += 1
|
39 |
-
total_pixels = image.width * image.height
|
40 |
-
major_colors = [(color, count) for color, count in color_count.items() if (count / total_pixels) >= threshold_percentage]
|
41 |
-
return major_colors
|
42 |
-
|
43 |
-
# 色を統合する関数
|
44 |
-
def consolidate_colors(major_colors, threshold):
|
45 |
-
colors_lab = [rgb2lab(np.array([[color]], dtype=np.float32)/255.0).reshape(3) for color, _ in major_colors]
|
46 |
-
i = 0
|
47 |
-
while i < len(colors_lab):
|
48 |
-
j = i + 1
|
49 |
-
while j < len(colors_lab):
|
50 |
-
if deltaE_ciede2000(colors_lab[i], colors_lab[j]) < threshold:
|
51 |
-
if major_colors[i][1] >= major_colors[j][1]:
|
52 |
-
major_colors[i] = (major_colors[i][0], major_colors[i][1] + major_colors[j][1])
|
53 |
-
major_colors.pop(j)
|
54 |
-
colors_lab.pop(j)
|
55 |
-
else:
|
56 |
-
major_colors[j] = (major_colors[j][0], major_colors[j][1] + major_colors[i][1])
|
57 |
-
major_colors.pop(i)
|
58 |
-
colors_lab.pop(i)
|
59 |
-
continue
|
60 |
-
j += 1
|
61 |
-
i += 1
|
62 |
-
return major_colors
|
63 |
-
|
64 |
# Gradioインターフェース用のメイン関数
|
65 |
def gradio_interface(image):
|
66 |
image_path = 'temp_input_image.jpg'
|
@@ -72,8 +40,8 @@ def gradio_interface(image):
|
|
72 |
# Gradioアプリを設定し、起動する
|
73 |
iface = gr.Interface(
|
74 |
fn=gradio_interface,
|
75 |
-
inputs=gr.
|
76 |
-
outputs=gr.
|
77 |
title="Line Art Removal",
|
78 |
description="画像をアップロードして線画を除去します。"
|
79 |
)
|
|
|
29 |
binarized_image = binarize_image(xdog_image)
|
30 |
return Image.fromarray(binarized_image)
|
31 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
32 |
# Gradioインターフェース用のメイン関数
|
33 |
def gradio_interface(image):
|
34 |
image_path = 'temp_input_image.jpg'
|
|
|
40 |
# Gradioアプリを設定し、起動する
|
41 |
iface = gr.Interface(
|
42 |
fn=gradio_interface,
|
43 |
+
inputs=gr.Image(type='pil', label="Original Image"),
|
44 |
+
outputs=gr.Image(type='pil', label="Processed Image"),
|
45 |
title="Line Art Removal",
|
46 |
description="画像をアップロードして線画を除去します。"
|
47 |
)
|