lc-cuttest / app.py
Hui
v1.0.0
e6ca32d
raw
history blame contribute delete
No virus
1.59 kB
import gradio as gr
import numpy as np
# from matplotlib import pyplot as plt
from skimage import color
# def lab_preview(img_lab):
# # scale
# img_lab_scaled = (img_lab + [0, 128, 128]) / [100, 255, 255]
# # plot
# fig = plt.figure()
# plt.subplots_adjust(hspace=0.25)
# plt.subplot(221)
# plt.imshow(img_lab_scaled)
# plt.title('Lab scaled')
# plt.subplot(222)
# plt.imshow(img_lab_scaled[:, :, 0], cmap="gray")
# plt.axis('off')
# plt.title('L channel')
# plt.subplot(223)
# plt.imshow(img_lab_scaled[:, :, 1], cmap='RdYlGn_r')
# plt.axis('off')
# plt.title('a')
# plt.subplot(224)
# plt.imshow(img_lab_scaled[:, :, 2], cmap='YlGnBu_r')
# plt.axis('off')
# plt.title('b')
# # convert plot to image using buffer
# fig.canvas.draw()
#
# # Now we can save it to a numpy array.
# data = np.frombuffer(fig.canvas.tostring_rgb(), dtype=np.uint8)
# data = data.reshape(fig.canvas.get_width_height()[::-1] + (3,))
# return data
def lab_mean(img_lab):
return (
np.mean(img_lab[:, :, 0]),
np.mean(img_lab[:, :, 1]),
np.mean(img_lab[:, :, 2])
)
def process_lab(img):
img_lab = color.rgb2lab(img)
# img_pre = lab_preview(img_lab)
l, a, b = lab_mean(img_lab)
return l, a, b
demo = gr.Interface(
fn=process_lab,
inputs=gr.Image(),
outputs=[
gr.Number(label="L-mean"),
gr.Number(label="a-mean"),
gr.Number(label="b-mean"),
# gr.Image(type="pil"),
]
)
if __name__ == "__main__":
demo.launch()