def subworld(W, subregion):
    """Return submatrix of W based on given subregion, and its offset.

    subregion should be a list of locations, preferably contiguous.
    The bounding rectangle of subregion is used to determine
    submatrix.
    """
    min_r = W.shape[0]
    max_r = -1
    min_c = W.shape[1]
    max_c = -1
    for k in subregion:
        if k[0] < min_r:
            min_r = k[0]
        if k[0] > max_r:
            max_r = k[0]
        if k[1] < min_c:
            min_c = k[1]
        if k[1] > max_c:
            max_c = k[1]
    return W[min_r:(max_r+1), min_c:(max_c+1)], (min_r, min_c)