def gene_block(img, block_sz=4, gene_block_vec=True):
    """
    Generate block vector or block pixel.
    :param img: row image
    :param block_sz: block size
    :param gene_block_vec: generate block vector(True) or block pixel(False)
    :return: block vector or block pixel
    """
    vectors = []
    if gene_block_vec:
        # generate xd(y, x)
        n_y = np.int(img.shape[0] / block_sz)
        n_x = np.int(img.shape[1] / block_sz)

        for y in range(n_y):
            for x in range(n_x):
                vert_start = y * block_sz
                vert_end = y * block_sz + block_sz
                horiz_start = x * block_sz
                horiz_end = x * block_sz + block_sz
                vec = img[vert_start:vert_end, horiz_start:horiz_end].flatten()
                vectors.append(vec)
    else:
        # generate xd(i, j)

        left_pad = np.int(np.ceil(block_sz / 2)) - 1
        right_pad = block_sz - np.int(np.ceil(block_sz / 2))
        up_pad = np.int(np.ceil(block_sz / 2)) - 1
        down_pad = block_sz - np.int(np.ceil(block_sz / 2))
        pad = np.array([[up_pad, down_pad], [left_pad, right_pad]])
        pad_img = zero_pad(img, pad)  # pad image because the margin of image also need block vector

        n_y = img.shape[0]
        n_x = img.shape[1]

        for y in range(up_pad, up_pad + n_y):
            for x in range(left_pad, left_pad + n_x):
                vert_start = y - np.int(np.ceil(block_sz / 2)) + 1
                vert_end = y + block_sz - np.int(np.ceil(block_sz / 2)) + 1
                horiz_start = x - np.int(np.ceil(block_sz / 2)) + 1
                horiz_end = x + block_sz - np.int(np.ceil(block_sz / 2)) + 1
                vec = pad_img[vert_start:vert_end, horiz_start:horiz_end].flatten()
                vectors.append(vec)
    return np.array(vectors)

    Generate block vector or block pixel.
    :param img: row image
    :param block_sz: block size
    :param gene_block_vec: generate block vector(True) or block pixel(False)
    :return: block vector or block pixel
    
Methodology/Traditional/PCAKmeans/algorithm.py