import itertools


def img_to_slices(img, img_rows, img_cols):
    """
    Convert image into slices
        args:
            .img: input image
            .img_rows: img_rows of slice
            .img_cols: img_rows of slice
        return slices, shapes[nb_rows, nb_cols]
    """
    nb_rows = img.shape[0] // img_rows
    nb_cols = img.shape[1] // img_cols
    slices = []
    # generate img slices
    for i, j in itertools.product(range(nb_rows), range(nb_cols)):
        slice = img[i * img_rows: i * img_rows + img_rows,
                    j * img_cols:j * img_cols + img_cols]
        slices.append(slice)
    return slices, [nb_rows, nb_cols]