Add algorithms/context-adaptive_interpolator.py
This commit is contained in:
parent
681aff3a38
commit
955582e0f8
26
algorithms/context-adaptive_interpolator.py
Normal file
26
algorithms/context-adaptive_interpolator.py
Normal file
@ -0,0 +1,26 @@
|
||||
from PIL import Image
|
||||
from statistics import mean
|
||||
|
||||
# What about other color channels?
|
||||
image = Image.open('9f04e2005fddb9d5512e2f42a3b826b019755717.jpg').convert('L')
|
||||
newI = image.load()
|
||||
I = image.copy().load()
|
||||
DEFAULT_COLOR = 255
|
||||
# This threshold is debatable.
|
||||
THRESHOLD = 20
|
||||
# How to manage the border of the image?
|
||||
for m in range(1, image.size[0] - 1):
|
||||
for n in range(1, image.size[1] - 1):
|
||||
e = I[m, n + 1]
|
||||
se = I[m + 1, n + 1]
|
||||
s = I[m + 1, n]
|
||||
sw = I[m + 1, n - 1]
|
||||
w = I[m, n - 1]
|
||||
nw = I[m - 1, n - 1]
|
||||
no = I[m - 1, n]
|
||||
ne = I[m - 1, n + 1]
|
||||
A = [e, se, s, sw, w, nw, no, ne]
|
||||
if max(A) - min(A) <= THRESHOLD:
|
||||
newI[m, n] = int(round(I[m, n] - mean(A), 0))
|
||||
|
||||
image.show()
|
Loading…
x
Reference in New Issue
Block a user