Commits

Miroslav Shubernetskiy committed 0ebc3c0

added problem 2

  • Participants
  • Parent commits 5b05f66

Comments (0)

Files changed (1)

+"""
+
+"""
+import sys, os, numpy, Image
+from prob1 import Resize1D
+
+sys.path.append(os.path.abspath('..'))
+from base.ip import *
+
+class Resize2D(IP_Image):
+    resizemethod = None
+
+    def __init__(self):
+        self.resizemethod = Resize1D()
+
+    def setResizeMethod(self, kernel, param):
+        self.resizemethod.setResizeMethod(kernel, param)
+
+    def resize(self, width, height):
+        size = self.img.size
+        data = numpy.asarray(self.img)
+        total = width * height
+        step1 = numpy.array([0] * width * size[1])
+        step2 = numpy.array([0] * total)
+        step1.shape = size[1], width
+        step2.shape = height, width
+        for h in range(size[1]):
+            step1[h, :] = self.resizemethod.resize(data[h, :], width)
+
+        for w in range(width):
+            step2[:, w] = self.resizemethod.resize(step1[:, w], height)
+        self.img = Image.fromarray(step2.astype(numpy.uint8))
+
+
+if __name__ == "__main__":
+    args = sys.argv
+    if len(args) != 7:
+        raise ValueError, "Usage: python %s input-image-path output-image-path new-w new-h kernel param" % __file__
+
+    input_path, output_path, new_w, new_h, kernel, param = args[1:]
+    new_w, new_h, kernel, param = int(new_w), int(new_h), int(kernel), float(param)
+
+    imgresize = Resize2D()
+
+    imgresize.openImage(input_path)
+    imgresize.setResizeMethod(kernel, param)
+    imgresize.resize(new_w, new_h)
+
+    if DEBUG:
+        imgresize.img.show()
+