def expandRectangle(rect, xfactor=3, yfactor=3):
    """
    Takes a (x,y,w,h) rectangle tuple and returns a new bounding
    rectangle that is centered on the center of the origin rectangle,
    but has a width/height that is larger by a given factor.

    The returned coordinates are rounded to integers
    """
    x, y, w, h = rect
    # Horizontal expansion
    x -= ((xfactor - 1) / 2) * w
    w *= xfactor
    # Horizontal expansion
    y -= ((yfactor - 1) / 2) * h
    h *= yfactor
    return (int(round(x)), int(round(y)),
            int(round(w)), int(round(h)))