Spaces:
Sleeping
Sleeping
Gerold Meisinger
commited on
Commit
·
e2e2760
1
Parent(s):
81002ee
init
Browse files- .gitignore +3 -0
- README.md +5 -4
- app.py +38 -0
- decompose.py +10 -0
- inference/bird_b.webp +0 -0
- inference/bird_g.webp +0 -0
- inference/bird_r.webp +0 -0
- inference/dog2_b.webp +0 -0
- inference/dog2_g.webp +0 -0
- inference/dog2_r.webp +0 -0
- inference/house2_b.webp +0 -0
- inference/house2_g.webp +0 -0
- inference/house2_r.webp +0 -0
- missing/bird_b.webp +0 -0
- missing/bird_g.webp +0 -0
- missing/bird_r.webp +0 -0
- missing/dog2_b.webp +0 -0
- missing/dog2_g.webp +0 -0
- missing/dog2_r.webp +0 -0
- missing/house2_b.webp +0 -0
- missing/house2_g.webp +0 -0
- missing/house2_r.webp +0 -0
- packages.txt +1 -0
- requirements.txt +2 -0
.gitignore
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
venv
|
2 |
+
flagged
|
3 |
+
|
README.md
CHANGED
@@ -1,13 +1,14 @@
|
|
1 |
---
|
2 |
-
title: Channels
|
3 |
emoji: 🐠
|
4 |
-
colorFrom:
|
5 |
-
colorTo:
|
6 |
sdk: gradio
|
7 |
-
sdk_version: 3.
|
8 |
app_file: app.py
|
9 |
pinned: false
|
10 |
license: agpl-3.0
|
11 |
---
|
12 |
|
13 |
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
|
|
|
1 |
---
|
2 |
+
title: Restore RGB Channels
|
3 |
emoji: 🐠
|
4 |
+
colorFrom: indigo
|
5 |
+
colorTo: yellow
|
6 |
sdk: gradio
|
7 |
+
sdk_version: 3.44.4
|
8 |
app_file: app.py
|
9 |
pinned: false
|
10 |
license: agpl-3.0
|
11 |
---
|
12 |
|
13 |
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
14 |
+
|
app.py
ADDED
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import cv2
|
3 |
+
import os
|
4 |
+
|
5 |
+
def restore(image_missing, image_inference, channel):
|
6 |
+
if len(image_missing.shape) != 3 or len(image_inference.shape) != 3:
|
7 |
+
return None #[None, "Error: Please provide RGB images!"]
|
8 |
+
c = { "R": 0, "G": 1, "B": 2 }[channel] # cv2 uses BGR order
|
9 |
+
image_missing[:,:,c] = image_inference[:,:,c]
|
10 |
+
return image_missing
|
11 |
+
|
12 |
+
examples=[
|
13 |
+
[os.path.join(os.path.dirname(__file__), "missing/bird_r.webp" ), os.path.join(os.path.dirname(__file__), "inference/bird_r.webp" ), "R"],
|
14 |
+
[os.path.join(os.path.dirname(__file__), "missing/bird_g.webp" ), os.path.join(os.path.dirname(__file__), "inference/bird_g.webp" ), "G"],
|
15 |
+
[os.path.join(os.path.dirname(__file__), "missing/bird_b.webp" ), os.path.join(os.path.dirname(__file__), "inference/bird_b.webp" ), "B"],
|
16 |
+
[os.path.join(os.path.dirname(__file__), "missing/dog2_r.webp" ), os.path.join(os.path.dirname(__file__), "inference/dog2_r.webp" ), "R"],
|
17 |
+
[os.path.join(os.path.dirname(__file__), "missing/dog2_g.webp" ), os.path.join(os.path.dirname(__file__), "inference/dog2_g.webp" ), "G"],
|
18 |
+
[os.path.join(os.path.dirname(__file__), "missing/dog2_b.webp" ), os.path.join(os.path.dirname(__file__), "inference/dog2_b.webp" ), "B"],
|
19 |
+
[os.path.join(os.path.dirname(__file__), "missing/house2_r.webp"), os.path.join(os.path.dirname(__file__), "inference/house2_r.webp"), "R"],
|
20 |
+
[os.path.join(os.path.dirname(__file__), "missing/house2_g.webp"), os.path.join(os.path.dirname(__file__), "inference/house2_g.webp"), "G"],
|
21 |
+
[os.path.join(os.path.dirname(__file__), "missing/house2_b.webp"), os.path.join(os.path.dirname(__file__), "inference/house2_b.webp"), "B"],
|
22 |
+
]
|
23 |
+
|
24 |
+
app = gr.Interface(
|
25 |
+
fn=restore,
|
26 |
+
inputs=[
|
27 |
+
gr.Image("missing/dog2_r.webp", type="numpy", label="Missing channel"),
|
28 |
+
gr.Image("inference/dog2_r.webp", type="numpy", label="Inference"),
|
29 |
+
gr.Radio(["R", "G", "B"], label="Restore channel"),
|
30 |
+
],
|
31 |
+
outputs="image",
|
32 |
+
examples=examples,
|
33 |
+
title="Restore missing RGB channel",
|
34 |
+
description="Restore missing channel of a RGB image by using a ControlNet to guide image generation of Stable Diffusion to infer missing channel from the other two channels https://huggingface.co/GeroldMeisinger/control-channels . Examples are missing one channel each (use `decompose.py`) and inference examples are cherry-picked from generation with ControlNet. The submit button replaces the missing channel from the inference. To generate your own inferences you have to set up Stable Diffusion with ControlNet 'channels-rgb'. Note: While the inference images look fine on their own and you might as well use them, we are only interested in one of their channels.")
|
35 |
+
|
36 |
+
if __name__ == "__main__":
|
37 |
+
app.launch()
|
38 |
+
|
decompose.py
ADDED
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import numpy as np
|
2 |
+
import cv2
|
3 |
+
|
4 |
+
for basename in ["bird", "dog2", "house2"]:
|
5 |
+
img = cv2.imread(f"{basename}.png")
|
6 |
+
for c, suffix in enumerate(["b", "g", "r"]):
|
7 |
+
img_c = img.copy()
|
8 |
+
img_c[:,:,c] = 0
|
9 |
+
cv2.imwrite(f"missing/{basename}_{suffix}.webp", img_c, [cv2.IMWRITE_WEBP_QUALITY, 100])
|
10 |
+
|
inference/bird_b.webp
ADDED
![]() |
inference/bird_g.webp
ADDED
![]() |
inference/bird_r.webp
ADDED
![]() |
inference/dog2_b.webp
ADDED
![]() |
inference/dog2_g.webp
ADDED
![]() |
inference/dog2_r.webp
ADDED
![]() |
inference/house2_b.webp
ADDED
![]() |
inference/house2_g.webp
ADDED
![]() |
inference/house2_r.webp
ADDED
![]() |
missing/bird_b.webp
ADDED
![]() |
missing/bird_g.webp
ADDED
![]() |
missing/bird_r.webp
ADDED
![]() |
missing/dog2_b.webp
ADDED
![]() |
missing/dog2_g.webp
ADDED
![]() |
missing/dog2_r.webp
ADDED
![]() |
missing/house2_b.webp
ADDED
![]() |
missing/house2_g.webp
ADDED
![]() |
missing/house2_r.webp
ADDED
![]() |
packages.txt
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
python3-opencv
|
requirements.txt
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
gradio==3.44.4
|
2 |
+
opencv-contrib-python==4.8.0.76
|