Spaces:
Running
Running
Commit
·
ebcb006
1
Parent(s):
7775d86
Update
Browse files
app.py
CHANGED
|
@@ -24,6 +24,7 @@ def binarize_image(image):
|
|
| 24 |
_, binarized = cv2.threshold(image, 0, 255, cv2.THRESH_BINARY + cv2.THRESH_OTSU)
|
| 25 |
return binarized
|
| 26 |
|
|
|
|
| 27 |
def process_XDoG(image_path):
|
| 28 |
kernel_size=0
|
| 29 |
sigma=1.4
|
|
@@ -38,10 +39,12 @@ def process_XDoG(image_path):
|
|
| 38 |
final_image = Image.fromarray(binarized_image)
|
| 39 |
return final_image
|
| 40 |
|
|
|
|
|
|
|
| 41 |
def replace_color(image, color_1, blur_radius=2):
|
| 42 |
data = np.array(image)
|
| 43 |
original_shape = data.shape
|
| 44 |
-
channels = original_shape[2] if len(original_shape) > 2 else 1
|
| 45 |
data = data.reshape(-1, channels)
|
| 46 |
color_1 = np.array(color_1)
|
| 47 |
matches = np.all(data[:, :3] == color_1, axis=1)
|
|
@@ -51,7 +54,7 @@ def replace_color(image, color_1, blur_radius=2):
|
|
| 51 |
while np.any(matches):
|
| 52 |
new_matches = np.zeros_like(matches)
|
| 53 |
match_num = np.sum(matches)
|
| 54 |
-
for i in range(len(data)):
|
| 55 |
if matches[i]:
|
| 56 |
x, y = divmod(i, original_shape[1])
|
| 57 |
neighbors = [
|
|
@@ -135,6 +138,7 @@ def line_color(image, mask, new_color):
|
|
| 135 |
def process_image(image, lineart):
|
| 136 |
if image.mode != 'RGBA':
|
| 137 |
image = image.convert('RGBA')
|
|
|
|
| 138 |
lineart = lineart.point(lambda x: 0 if x < 200 else 255)
|
| 139 |
lineart = ImageOps.invert(lineart)
|
| 140 |
kernel = np.ones((3, 3), np.uint8)
|
|
@@ -167,10 +171,7 @@ class webui:
|
|
| 167 |
lineart = process_XDoG(image_path).convert('L')
|
| 168 |
replace_color_image = process_image(rgb_image, lineart).convert('RGBA')
|
| 169 |
if alpha:
|
| 170 |
-
|
| 171 |
-
inverted_alpha = 255 - alpha_channel
|
| 172 |
-
inverted_alpha_image = Image.fromarray(inverted_alpha)
|
| 173 |
-
replace_color_image.putalpha(inverted_alpha_image)
|
| 174 |
replace_color_image_path = f"{image_name}_noline.png"
|
| 175 |
replace_color_image.save(replace_color_image_path)
|
| 176 |
lineart_image = lineart.convert('RGBA')
|
|
|
|
| 24 |
_, binarized = cv2.threshold(image, 0, 255, cv2.THRESH_BINARY + cv2.THRESH_OTSU)
|
| 25 |
return binarized
|
| 26 |
|
| 27 |
+
|
| 28 |
def process_XDoG(image_path):
|
| 29 |
kernel_size=0
|
| 30 |
sigma=1.4
|
|
|
|
| 39 |
final_image = Image.fromarray(binarized_image)
|
| 40 |
return final_image
|
| 41 |
|
| 42 |
+
|
| 43 |
+
|
| 44 |
def replace_color(image, color_1, blur_radius=2):
|
| 45 |
data = np.array(image)
|
| 46 |
original_shape = data.shape
|
| 47 |
+
channels = original_shape[2] if len(original_shape) > 2 else 1 # チャンネル数を確認
|
| 48 |
data = data.reshape(-1, channels)
|
| 49 |
color_1 = np.array(color_1)
|
| 50 |
matches = np.all(data[:, :3] == color_1, axis=1)
|
|
|
|
| 54 |
while np.any(matches):
|
| 55 |
new_matches = np.zeros_like(matches)
|
| 56 |
match_num = np.sum(matches)
|
| 57 |
+
for i in range(len(data)): # Removed tqdm
|
| 58 |
if matches[i]:
|
| 59 |
x, y = divmod(i, original_shape[1])
|
| 60 |
neighbors = [
|
|
|
|
| 138 |
def process_image(image, lineart):
|
| 139 |
if image.mode != 'RGBA':
|
| 140 |
image = image.convert('RGBA')
|
| 141 |
+
|
| 142 |
lineart = lineart.point(lambda x: 0 if x < 200 else 255)
|
| 143 |
lineart = ImageOps.invert(lineart)
|
| 144 |
kernel = np.ones((3, 3), np.uint8)
|
|
|
|
| 171 |
lineart = process_XDoG(image_path).convert('L')
|
| 172 |
replace_color_image = process_image(rgb_image, lineart).convert('RGBA')
|
| 173 |
if alpha:
|
| 174 |
+
replace_color_image.putalpha(alpha)
|
|
|
|
|
|
|
|
|
|
| 175 |
replace_color_image_path = f"{image_name}_noline.png"
|
| 176 |
replace_color_image.save(replace_color_image_path)
|
| 177 |
lineart_image = lineart.convert('RGBA')
|