import numpy as np import cv2 def img2tile(image,height,width): max_tile_size = 250 tiles = [] x_tiles = (width + max_tile_size - 1) // max_tile_size y_tiles = (height + max_tile_size - 1) // max_tile_size for y in range(y_tiles): temp = [] for x in range(x_tiles): left = x * max_tile_size upper = y * max_tile_size right = min((x + 1) * max_tile_size, width) lower = min((y + 1) * max_tile_size, height) tile = image[upper:lower, left:right] temp.append(tile) tiles.append(temp) return(tiles) def tile2img(tiles, height, width): reconstructed_image = np.zeros((height, width, 3), dtype=np.uint8) current_y = 0 for row in tiles: current_x = 0 for tile in row: tile_height, tile_width = tile.shape[:2] reconstructed_image[current_y:current_y + tile_height, current_x:current_x + tile_width] = tile current_x += tile_width current_y += row[0].shape[0] return reconstructed_image