Update pictureDeal.py
Browse files- pictureDeal.py +4 -60
pictureDeal.py
CHANGED
@@ -1,63 +1,7 @@
|
|
1 |
-
import cv2
|
2 |
-
from PIL import Image, ImageEnhance
|
3 |
import gradio as gr
|
4 |
-
from sklearn.cluster import KMeans
|
5 |
-
import numpy as np
|
6 |
|
7 |
-
|
|
|
8 |
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
with gr.Row():
|
13 |
-
img_input = gr.Image()
|
14 |
-
img_output = gr.Image()
|
15 |
-
|
16 |
-
section_btn1 = gr.Button("合并色彩")
|
17 |
-
|
18 |
-
|
19 |
-
def img_fit_predict(img,n_colors):
|
20 |
-
data = img.reshape(-1,3)
|
21 |
-
kmeans = KMeans(n_clusters=n_colors)
|
22 |
-
y_ = kmeans.fit_predict(data)
|
23 |
-
colors = kmeans.cluster_centers_/255
|
24 |
-
output_temp = colors[y_].reshape(img.shape)
|
25 |
-
return output_temp
|
26 |
-
|
27 |
-
section_btn1.click(img_fit_predict, inputs=[img_input,n_colors], outputs=img_output)
|
28 |
-
|
29 |
-
with gr.Row():
|
30 |
-
gaussian_blur = gr.Slider(1, 13, 13, step=2, label="整体降噪参数调整")
|
31 |
-
structuring_element = gr.Slider(1, 13, 3, step=2, label="去除小噪声")
|
32 |
-
canny_start = gr.Slider(1, 200, 4, step=1, label="边缘检测-开始参数")
|
33 |
-
canny_end = gr.Slider(1, 200, 10, step=1, label="边缘检测-结束参数")
|
34 |
-
|
35 |
-
with gr.Row():
|
36 |
-
thresh_val = gr.Slider(50, 500, 205, step=1, label="二值图像-thresh")
|
37 |
-
maxval = gr.Slider(50, 500, 330, step=1, label="二值图像-maxval")
|
38 |
-
enhance = gr.Slider(0, 1, 0.8, step=0.1, label="增强颜色-enhance")
|
39 |
-
blend = gr.Slider(0, 1, 0.4, step=0.1, label="增强颜色-blend")
|
40 |
-
|
41 |
-
section_btn2 = gr.Button("调整图片")
|
42 |
-
with gr.Row():
|
43 |
-
closed_output = gr.Image()
|
44 |
-
img_param_output = gr.Image()
|
45 |
-
|
46 |
-
def turn_arguments(img,img_output,gaussian_blur,structuring_element,canny_start,canny_end,thresh_val,maxval,enhance,blend):
|
47 |
-
gray = cv2.cvtColor(img_output, cv2.COLOR_BGR2GRAY)
|
48 |
-
gray = cv2.GaussianBlur(gray, (gaussian_blur,gaussian_blur), 0)
|
49 |
-
edges = cv2.Canny(gray, canny_start, canny_end)
|
50 |
-
_, thresh = cv2.threshold(edges, thresh_val, maxval, cv2.THRESH_BINARY)
|
51 |
-
kernel = cv2.getStructuringElement(cv2.MORPH_ELLIPSE, (structuring_element, structuring_element))
|
52 |
-
closed = cv2.morphologyEx(thresh, cv2.MORPH_CLOSE, kernel)
|
53 |
-
image = Image.fromarray(img_output)
|
54 |
-
closed = closed.astype(img.dtype)
|
55 |
-
enhancer = ImageEnhance.Color(image=image)
|
56 |
-
img1 = enhancer.enhance(enhance).convert('RGB')
|
57 |
-
img2 = Image.fromarray(closed).convert('RGB')
|
58 |
-
union_img = np.asarray(Image.blend(img2, img1, blend))
|
59 |
-
return closed,union_img
|
60 |
-
|
61 |
-
section_btn2.click(turn_arguments,inputs=[img_input, img_output,gaussian_blur,structuring_element,canny_start,canny_end,thresh_val,maxval,enhance,blend ],outputs = [closed_output,img_param_output])
|
62 |
-
|
63 |
-
interface.launch()
|
|
|
|
|
|
|
1 |
import gradio as gr
|
|
|
|
|
2 |
|
3 |
+
def greet(name):
|
4 |
+
return "Hello " + name + "!!"
|
5 |
|
6 |
+
iface = gr.Interface(fn=greet, inputs="text", outputs="text")
|
7 |
+
iface.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|