File size: 1,080 Bytes
93871a1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
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