def extract_ROI(image_path, image, ROI):
    """Extract the region of interest out of an image

    :param image_path: path to the image file
    :type image_path: str
    :param image: the image matrix
    :type image: numpy.ndarray
    :returns: numpy.ndarray -- the region of interest
    """
    if ROI is None:
        return image

    if len(ROI) != 4:
        raise TypeError("ROI needs to be of length 4")

    x, y, w, h = ROI
    height, width, _ = image.shape

    if x < 0 or y < 0 or x + w > width or y + h > height:
        raise ValueError("Invalid dimensions for ROI for image: %s"
                         % image_path)

    return image[x:x + w, y:y + h]