File size: 2,097 Bytes
dc4014d
 
ccea513
 
 
 
dc4014d
 
 
 
 
 
 
ccea513
4f3074a
 
dc4014d
 
 
 
 
 
ccea513
dc4014d
ccea513
dc4014d
 
4f3074a
 
 
ccea513
dc4014d
 
4f3074a
dc4014d
ccea513
b04dd16
ccea513
2c032a1
ccea513
 
dc4014d
 
2c032a1
dc4014d
 
 
 
2c032a1
e4999b4
dc4014d
 
 
db5f9ea
ccea513
98ca465
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import gradio as gr
from utils import *
import cv2
import numpy as np
import matplotlib.pyplot as plt
import io


def inference(img, template, angel):
    color_image = cv2.imread(img.name, cv2.IMREAD_COLOR)

    HSV_image = cv2.cvtColor(color_image, cv2.COLOR_BGR2HSV)
    selected_harmomic_scheme = HarmonicScheme(str(template), int(angel))
    new_HSV_image = selected_harmomic_scheme.hue_shifted(HSV_image, num_superpixels=-1)
    # Convert HSV to BGR
    result_image = cv2.cvtColor(new_HSV_image, cv2.COLOR_HSV2BGR)

    # Compute shifted histogram
    histo_1 = count_hue_histogram(HSV_image)
    histo_2 = count_hue_histogram(new_HSV_image)

    # Create Hue Plots
    fig1 = plothis(histo_1, selected_harmomic_scheme, "Source Hue")
    fig_1_cv = get_img_from_fig(fig1)
    fig2 = plothis(histo_2, selected_harmomic_scheme, "Target Hue")
    fig_2_cv = get_img_from_fig(fig2)

    hue_plots = np.concatenate((fig_1_cv, fig_2_cv), axis=1)

    cv2.imwrite('hue.jpg', hue_plots)
    cv2.imwrite('result_image.jpg', result_image)


    return ['result_image.jpg', 'hue.jpg']

title = 'Color Harmonization'
description = 'Compute Color Harmonization with different templates based on Color Harmonization paper by Daniel Cohen-Or et al. More metrics for user interfaces on https://interfacemetrics.aalto.fi'
article = "<p style='text-align: center'></p>"
examples = [['./examples/aim_interface.png', "V", 25], ['./examples/esfahan_unsplash.jpeg', "I", 352]]
# css = ".output_image, .input_image {height: 40rem !important; width: 100% !important;}"

gr.Interface(
    inference,
    [gr.inputs.Image(type='file', label='Original Image'),
     gr.inputs.Dropdown(["X", "Y", "T", "I", "mirror_L", "L", "V", "i"],
                        default="X",
                        label="Template"),
     gr.inputs.Slider(0, 359, label="Angle")],
    [gr.outputs.Image(type='file', label='Harmonized Image'),
     gr.outputs.Image(type='file', label='Hue')],
    title=title,
    description=description,
    article=article,
    examples=examples,
    # css=css,
).launch(debug=True, enable_queue=True)