def withinPicture(frame, i):
    """confirms that the sample position is within the frame to prevent errors"""
    ## Note that the frame dimenions are (y,x) while the i coordinates are (x,y)

    if (i[0] < 0 or i[1] < 0 ):
        # check that the sample position doesn't contain negative coordinates
        # print("ERROR: sample location below 0, i = {}".format(i))
        return False
    elif(i[0]<frame.shape[1] and i[1]<frame.shape[0]):
    # check that the sample position is within the frame
        return True