Advertisement
Guest User

Untitled

a guest
Nov 20th, 2017
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.21 KB | None | 0 0
  1. import numpy as np
  2. import cv2
  3. import math
  4. from matplotlib import pyplot as plt
  5.  
  6. def resize(input, percentage):
  7. original_width, original_height, channels = input.shape
  8. print("Original dimensions: [%d ; %d ; %d]" % (original_width, original_height, channels))
  9. new_width = int(math.ceil(original_width * (percentage/100)))
  10. new_height = int(math.ceil(original_height * (percentage / 100)))
  11. print("New dimensions: [%d ; %d ; %d]" % (new_width, new_height, channels))
  12. output = np.zeros((new_width,new_height,channels))
  13. print("New matrix created, type: %s" % (type(output)))
  14. for i in range(new_width):
  15. for j in range(new_height):
  16. output[i, j, 0] = input[math.floor(i / (percentage / 100)), math.floor(j / (percentage / 100)), 0]
  17. output[i, j, 1] = input[math.floor(i / (percentage / 100)), math.floor(j / (percentage / 100)), 1]
  18. output[i, j, 2] = input[math.floor(i / (percentage / 100)), math.floor(j / (percentage / 100)), 2]
  19.  
  20. return output
  21.  
  22. ajtaci = cv2.imread('itcrowd.bmp', 1)
  23. invader = cv2.imread('invader.bmp', 1)
  24.  
  25. cv2.imshow("test", resize(ajtaci, 50))
  26.  
  27. cv2.imshow("Ajtaci", ajtaci)
  28.  
  29.  
  30. cv2.waitKey(0)
  31. cv2.destroyAllWindows()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement