def view_as_blocks(arr, block_size, overlap):
    """
    Break up an image into blocks and return array.
    """
    m, n = arr.shape
    # assume square
    chip_size,_ = block_size
    stride = chip_size
    step = chip_size + 2 * overlap

    nrows, ncols = (m - 2*overlap) // chip_size, (n - 2*overlap) // chip_size
    splitted = []
    for i in range(nrows):
        for j in range(ncols):
            h_start = j*stride
            v_start = i*stride
            cropped = arr[v_start:v_start+step, h_start:h_start+step]
            splitted.append(cropped)
    return splitted,nrows,ncols