Dabs commited on
Commit
8975d21
1 Parent(s): cf750d6

innitial commit

Browse files
Files changed (2) hide show
  1. .gitignore +2 -0
  2. app.py +31 -0
.gitignore ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ venv/
2
+
app.py ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import numpy as np
2
+
3
+ import gradio as gr
4
+
5
+ def quantize(val, factor):
6
+ quantized = (np.round(factor * np.array(val / 255)) * (255 / factor)).astype(int)
7
+ # print(val / 255, factor, factor * np.array(val / 255))
8
+ return quantized
9
+
10
+
11
+ def sepia(factor, input_img):
12
+ img_arr = np.asarray(input_img)
13
+ new_img = np.copy(img_arr)
14
+
15
+ for y in range(img_arr.shape[1] - 1):
16
+ for x in range(img_arr.shape[0] - 1):
17
+ old_pixel = new_img[x, y].copy()
18
+ new_pixel = quantize(old_pixel, factor)
19
+ new_img[x, y] = new_pixel
20
+
21
+ quant_error = old_pixel - new_pixel
22
+ new_img[x + 1][y ] = new_img[x + 1][y ] + quant_error * 7 / 16
23
+ new_img[x - 1][y + 1] = new_img[x - 1][y + 1] + quant_error * 3 / 16
24
+ new_img[x ][y + 1] = new_img[x ][y + 1] + quant_error * 5 / 16
25
+ new_img[x + 1][y + 1] = new_img[x + 1][y + 1] + quant_error * 1 / 16
26
+ return new_img
27
+
28
+
29
+ iface = gr.Interface(sepia, [gr.inputs.Slider(1, 10, 1), "image"], "pil")
30
+
31
+ iface.launch()