<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def n4_bias_field_correction(image, mask=None, shrink_factor=4, convergence={'iters':[50,50,50,50], 'tol':1e-07}, spline_param=200, verbose=False, weight_mask=None):
 """ N4 Bias Field Correction ANTsR function: `n4BiasFieldCorrection` Arguments --------- image : ANTsImage image to bias correct mask : ANTsImage input mask, if one is not passed one will be made shrink_factor : scalar Shrink factor for multi-resolution correction, typically integer less than 4 convergence : dict w/ keys `iters` and `tol` iters : vector of maximum number of iterations for each shrinkage factor tol : the convergence tolerance. spline_param : integer Parameter controlling number of control points in spline. Either single value, indicating how many control points, or vector with one entry per dimension of image, indicating the spacing in each direction. verbose : boolean enables verbose output. weight_mask : ANTsImage (optional) antsImage of weight mask Returns ------- ANTsImage Example ------- """

    if image.pixeltype != 'float':
        image = image.clone('float')
    iters = convergence['iters']
    tol = convergence['tol']
    if mask is None:
        mask = get_mask(image)

    N4_CONVERGENCE_1 = '[%s, %.10f]' % ('x'.join([str(it) for it in iters]), tol)
    N4_SHRINK_FACTOR_1 = str(shrink_factor)
    if (not isinstance(spline_param, (list,tuple))) or (len(spline_param) == 1):
        N4_BSPLINE_PARAMS = '[%i]' % spline_param
    elif (isinstance(spline_param, (list,tuple))) and (len(spline_param) == image.dimension):
        N4_BSPLINE_PARAMS = '[%s]' % ('x'.join([str(sp) for sp in spline_param]))
    else:
        raise ValueError('Length of splineParam must either be 1 or dimensionality of image')

    if weight_mask is not None:
        if not isinstance(weight_mask, iio.ANTsImage):
            raise ValueError('Weight Image must be an antsImage')

    outimage = image.clone()
    kwargs = {
        'd': outimage.dimension,
        'i': image,
        'w': weight_mask,
        's': N4_SHRINK_FACTOR_1,
        'c': N4_CONVERGENCE_1,
        'b': N4_BSPLINE_PARAMS,
        'x': mask,
        'o': outimage,
        'v': int(verbose)
    }

    processed_args = pargs._int_antsProcessArguments(kwargs)
    libfn = utils.get_lib_fn('N4BiasFieldCorrection')
    libfn(processed_args)
    return outimage