Advertisement
yclee126

tile images

Mar 11th, 2022
2,100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.58 KB | None | 0 0
  1. # tile images
  2.  
  3. import cv2
  4. import numpy as np
  5.  
  6. tile_w, tile_h = int(1920/4), int(1080/3)
  7. tile_x, tile_y = 4, 3
  8.  
  9. canvas = np.zeros((tile_h*tile_y, tile_w*tile_x, 3), dtype='uint8')
  10. for ty in range(tile_y):
  11.     for tx in range(tile_x):
  12.         img = cv2.imread(f'{ty*tile_x+tx + 1}.png')
  13.         img = cv2.resize(img, (tile_w, tile_h), interpolation=cv2.INTER_AREA)
  14.        
  15.         x0, x1 = tile_w*tx, tile_w*(tx+1)
  16.         y0, y1 = tile_h*ty, tile_h*(ty+1)
  17.  
  18.         canvas[y0:y1, x0:x1] = img
  19.  
  20. # cv2.imshow('win', canvas)
  21. # cv2.waitKey(0)
  22. cv2.imwrite('out.png', canvas)
  23.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement