0

I've successfully divided my image into tiles, which I am aiming to process. However, afterwards, I'd like to join them and form the processed image, the same way the original image was in dimensions. I've the following code already working. Upon loading an image into the variable 'image' of resolution 1000x775;

# define the tile size
tilesize_r = 128
tilesize_c = 128

# divide the image into 128x128 tiles
for r in range(0,image.shape[0] - tilesize_r, tilesize_r):
    for c in range(0,image.shape[1] - tilesize_c, tilesize_c):
        tile = image[r:r+tilesize_r,c:c+tilesize_c]
        tile_name = 'image{}tile{}.jpg'.format(ind, tilecount) #naming of it, does not matter
        tile_path = os.path.join(abs_tile_images_dir, tile_name) #path of it, does not matter either
        cv2.imwrite(tile_path, tile)
        tilecount+=1

So, in the end, I have the list of images as:

image0tile0.jpg
image0tile1.jpg
.
.
.
image0tile41.jpg

and so on. I'd like to join these again, what shall I do? I assume I need to construct the same loop, but this time I shall gather all the tiles that have the same "imageN" part first, and then loop over them, and join them based on the "tileN". Am I getting close?

3
  • What have you tried? Where did it give you difficulty? Commented Jul 28, 2022 at 15:28
  • Yes, your assumption is correct. Only this time you'll be reading in the tile image and storing it to that slice of the image array. Then write the image array out as an image.
    – pho
    Commented Jul 28, 2022 at 15:41
  • I don't know the boundaries of the loop this time, because there are many tile images per image and also the dimensions as the loop boundaries so they don't really match. It's more complex than dividing the image. Commented Jul 29, 2022 at 7:34

0

Browse other questions tagged or ask your own question.