|
|
import gradio as gr |
|
|
import numpy as np |
|
|
import flip_evaluator as flip |
|
|
|
|
|
def compute_simple_diff(a: np.array, b: np.array) -> (np.array, float): |
|
|
'''compute difference of two arrays''' |
|
|
return a - b, str(np.round(np.mean(a-b), 4)) |
|
|
|
|
|
|
|
|
def compute_flip_diff(a: np.array, b: np.array) -> (np.array, float): |
|
|
''' |
|
|
compute NVIDIA nvlab's FLIP difference between two image arrays |
|
|
''' |
|
|
error_map, mean_error, _ = flip.evaluate(a, b, "HDR") |
|
|
return error_map, str(np.round(mean_error,4)) |
|
|
|
|
|
|
|
|
examples = [ |
|
|
["examples/Office_ShadowAcne/reference.png", |
|
|
"examples/Office_ShadowAcne/test.png"] |
|
|
] |
|
|
|
|
|
with gr.Blocks() as demo: |
|
|
gr.Markdown("Compute difference using NVIDIA's [FLIP](https://github.com/NVlabs/flip/)") |
|
|
with gr.Row(equal_height=True): |
|
|
|
|
|
before = gr.Image(label="Before") |
|
|
after = gr.Image(label="After") |
|
|
diff = gr.Image(label="Difference") |
|
|
with gr.Row(equal_height=True): |
|
|
with gr.Column(scale=2): |
|
|
button = gr.Button("Compute difference") |
|
|
with gr.Column(scale=1, min_width=200): |
|
|
meanbox = gr.Textbox(label="Mean difference") |
|
|
|
|
|
button.click(fn=compute_flip_diff, |
|
|
inputs=[before, after], |
|
|
outputs=[diff, meanbox] |
|
|
) |
|
|
gr.Examples(examples, [before, after]) |
|
|
|
|
|
if __name__ == "__main__": |
|
|
demo.launch() |
|
|
|