<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def snow_partitioning(im, dt=None, r_max=4, sigma=0.4, return_all=False, mask=True, randomize=True):
 r""" Partitions the void space into pore regions using a marker-based watershed algorithm, with specially filtered peaks as markers. The SNOW network extraction algorithm (Sub-Network of an Over-segmented Watershed) was designed to handle to perculiarities of high porosity materials, but it applies well to other materials as well. Parameters im : array_like A boolean image of the domain, with ``True`` indicating the pore space and ``False`` elsewhere. dt : array_like, optional The distance transform of the pore space. This is done automatically if not provided, but if the distance transform has already been computed then supplying it can save some time. r_max : int The radius of the spherical structuring element to use in the Maximum filter stage that is used to find peaks. The default is 4 sigma : float The standard deviation of the Gaussian filter used in step 1. The default is 0.4. If 0 is given then the filter is not applied, which is useful if a distance transform is supplied as the ``im`` argument that has already been processed. return_all : boolean If set to ``True`` a named tuple is returned containing the original image, the distance transform, the filtered peaks, and the final pore regions. The default is ``False`` mask : boolean Apply a mask to the regions where the solid phase is. Default is ``True`` randomize : boolean If ``True`` (default), then the region colors will be randomized before returning. This is helpful for visualizing otherwise neighboring regions have simlar coloring are are hard to distinguish. Returns ------- image : ND-array An image the same shape as ``im`` with the void space partitioned into pores using a marker based watershed with the peaks found by the SNOW algorithm [1]. Notes ----- If ``return_all`` is ``True`` then a **named tuple** is returned containing all of the images used during the process. They can be access as attriutes with the following names: * ``im``: The binary image of the void space * ``dt``: The distance transform of the image * ``peaks``: The peaks of the distance transform after applying the steps of the SNOW algorithm * ``regions``: The void space partitioned into pores using a marker based watershed with the peaks found by the SNOW algorithm References [1] Gostick, J. "A versatile and efficient network extraction algorithm using marker-based watershed segmenation". Physical Review E. (2017) """

    tup = namedtuple('results', field_names=['im', 'dt', 'peaks', 'regions'])
    print('_'*60)
    print("Beginning SNOW Algorithm")
    im_shape = sp.array(im.shape)
    if im.dtype is not bool:
        print('Converting supplied image (im) to boolean')
        im = im > 0
    if dt is None:
        print('Peforming Distance Transform')
        if sp.any(im_shape == 1):
            ax = sp.where(im_shape == 1)[0][0]
            dt = spim.distance_transform_edt(input=im.squeeze())
            dt = sp.expand_dims(dt, ax)
        else:
            dt = spim.distance_transform_edt(input=im)

    tup.im = im
    tup.dt = dt

    if sigma > 0:
        print('Applying Gaussian blur with sigma =', str(sigma))
        dt = spim.gaussian_filter(input=dt, sigma=sigma)

    peaks = find_peaks(dt=dt, r_max=r_max)
    print('Initial number of peaks: ', spim.label(peaks)[1])
    peaks = trim_saddle_points(peaks=peaks, dt=dt, max_iters=500)
    print('Peaks after trimming saddle points: ', spim.label(peaks)[1])
    peaks = trim_nearby_peaks(peaks=peaks, dt=dt)
    peaks, N = spim.label(peaks)
    print('Peaks after trimming nearby peaks: ', N)
    tup.peaks = peaks
    if mask:
        mask_solid = im > 0
    else:
        mask_solid = None
    regions = watershed(image=-dt, markers=peaks, mask=mask_solid)
    if randomize:
        regions = randomize_colors(regions)
    if return_all:
        tup.regions = regions
        return tup
    else:
        return regions