import math


def get_tile_pos(imshape, tilesize):
    """
    Given a image shape and a tilesize, returns a list of tuples with the (x,y) offset
    for the nth tile. Assumes square tiles.
    """
    offset = tilesize//2
    
    (rowpx, colpx) = imshape
    nrow = math.ceil((rowpx-tilesize) / offset) + 1
    ncol = math.ceil((rowpx-tilesize) / offset) + 1
        
    out = []
    for row in range(nrow):
        for col in range(ncol):
            if row<nrow-1:
                x = row*offset
            else:
                x = rowpx - tilesize
            if col<ncol-1:
                y = col*offset
            else:
                y = rowpx - tilesize
            out.append((x,y))
            
    return out