diff --git a/algorithms/context-adaptive_interpolator.py b/algorithms/context-adaptive_interpolator.py index 399f275..da3252f 100644 --- a/algorithms/context-adaptive_interpolator.py +++ b/algorithms/context-adaptive_interpolator.py @@ -1,19 +1,24 @@ -# Based on https://web.archive.org/web/20231116015653/http://nrl.northumbria.ac.uk/id/eprint/29339/1/Paper_accepted.pdf +# Based on https://web.archive.org/web/20231116015653/http://nrl.northumbria.ac.uk/id/eprint/29339/1/Paper_accepted.pdf IV. B.. from PIL import Image from statistics import mean, median -# What about other color channels? -image = Image.open('9f04e2005fddb9d5512e2f42a3b826b019755717.jpg').convert('L') -r = image.load() -I = image.copy().load() -DEFAULT_COLOR = 255 -# This threshold is debatable. +# What about other color channels? See #11. +MODE = 'L' + +IImage = Image.open('9f04e2005fddb9d5512e2f42a3b826b019755717.jpg').convert(MODE) +I = IImage.load() + +rImage = Image.new(MODE, (IImage.size[0] - 2, IImage.size[1] - 2)) +r = rImage.load() + +# This threshold is debatable. See #13. THRESHOLD = 20 -# How to manage the border of the image? + # Equation (10) -for m in range(1, image.size[0] - 1): - for n in range(1, image.size[1] - 1): +# Accelerate computation. See #15. +for m in range(1, IImage.size[0] - 1): + for n in range(1, IImage.size[1] - 1): e = I[m, n + 1] se = I[m + 1, n + 1] s = I[m + 1, n] @@ -35,7 +40,7 @@ for m in range(1, image.size[0] - 1): newPixel = I[m, n] - (sw + ne) / 2 else: newPixel = I[m, n] - median(A) - r[m, n] = round(newPixel) + r[m - 1, n - 1] = round(newPixel) Q = 3 @@ -48,6 +53,9 @@ def sigma(i, j): return sigma_q(i, j, Q) def sigma_q(i, j, q): - # Equation + # Equation (8) + # TODO: + pass -image.rotate(-90).show() \ No newline at end of file +# Why need to rotate the image? See #14. +rImage.rotate(-90).show() \ No newline at end of file