diff --git a/Linear.py b/Linear.py new file mode 100644 index 0000000..01396da --- /dev/null +++ b/Linear.py @@ -0,0 +1,23 @@ +import lib +import math + +class BiLinear(lib.Interpolator): + def get_pixel(self, pic, x, y, r, qx, qy): + leftx = math.floor(x) + rightx = math.ceil(x) + topy = math.floor(y) + bottomy = math.ceil(y) + + left = pic.at(leftx, topy) + right = pic.at(leftx, topy) + dist = x % 1 + top = (left * (1 - dist) + right * dist) + + left = pic.at(leftx, bottomy) + right = pic.at(leftx, bottomy) + bottom = (left * (1 - dist) + right * dist) + + dist = y % 1 + pix = (top * (1 - dist) + bottom * dist) + + return pix diff --git a/test.py b/test.py index d945cb2..669d10d 100644 --- a/test.py +++ b/test.py @@ -5,8 +5,8 @@ import lib pic = lib.Picture.load(orig_file) pic.show() -import nn -Interp = nn.Nearest() +import Linear +Interp = Linear.BiLinear() pix = Interp.interpolate(pic, 200, 200) pix.show() pix.save(new_file) diff --git a/test_images/sksp_lightstick.jpg b/test_images/sksp_lightstick.jpg new file mode 100644 index 0000000..ee18b4a Binary files /dev/null and b/test_images/sksp_lightstick.jpg differ