def get_slice(img, ori, slc):
    """
    Extract one slice from a 3D numpy.ndarray image.
    :param img: np.array. input image to extract slice.
    :param ori: int. orientation to extract slice. 1. sagittal. 2. coronal. 3. axial.
    :param slc: int. slice number to extract.
    :return: extracted 2D slice: np.array.
    """
    if ori == 1 and 0 <= slc < img.shape[0]:
        return img[slc, :, :]
    elif ori == 2 and 0 <= slc < img.shape[1]:
        return img[:, slc, :]
    elif ori == 3 and 0 <= slc < img.shape[2]:
        return img[:, :, slc]
    else:
        raise Exception('Invalid orientation or slice number')