ifp.startlogger(filename='/media/julian/Daten/neuraldata/cremi_2016/develop/160927_determine_shortest_paths/160929_pthsovrdist_pow10/160929.log', type='a')

        # # Cropping
        # if crop:
        #     ifp.crop([10, 200, 200], [110, 712, 712])

            # ifp.write()

        # ifp.logging('ifp.get_image = {}', ifp.get_image('labels')[0, 0, 0])
        # ifp.logging('ifp.amax = {}\n', ifp.amax('labels'))

        ifp.logging('keys() = {}', ifp.get_data().keys())

        # For multiple labels
        ifp.logging('Starting label iterator for {} labels', len(ifp.anytask_rtrn(np.unique, ids='labels')))

        c = 0
        for lblo in ifp.label_bounds_iterator('labels', 'curlabel', ids='disttransf', targetids='curdisttransf',
                                              maskvalue=0, value=0):

            ifp.logging('------------\nCurrent label {} in iteration {}', lblo['label'], c)
            ifp.logging('Bounding box = {}', lblo['bounds'])

            local_maxima_found = find_local_maxima(ifp)

            ifp.logging('Local maxima found: {}', local_maxima_found)

            if local_maxima_found:

                if ifp.amax('locmax') != 0:
    # Seed the randomize function
    random.seed(1)

    # # Choose one label
    # lbl = random.choice(labels)
    # ifp.logging('Choice: {}', lbl)
    #
    # ifp.astype(np.uint32, ids='labels')
    # (grag, rag) = ifp.anytask_rtrn(graphs.gridRegionAdjacencyGraph, ignoreLabel=0, ids='labels')
    # ifp.logging('RAG: {}', rag)
    #
    # ifp.logging('Node ids: {}', rag.nodeIds())

    ifp.astype(np.uint32, ids='labels')
    (grag, rag) = ifp.anytask_rtrn(graphs.gridRegionAdjacencyGraph, ignoreLabel=0, ids='labels')
    edge_ids = rag.edgeIds()
    ifp.logging('Edge ids: {}', edge_ids)

    # Type 1:
    # Select edges by size (smallest edges)
    ifp.logging('Number of edgeLengths = {}', len(rag.edgeLengths()))
    edgelen_ids = dict(zip(edge_ids, rag.edgeLengths()))
    ifp.logging('edgelen_ids = {}', edgelen_ids)
    sorted_edgelens = np.sort(rag.edgeLengths())
    #
    smallest_merge_lens = sorted_edgelens[0:numberbysize]
    ifp.logging('Lengths selected for merging: {}', smallest_merge_lens)
    #
    smallest_merge_ids = []
    for x in smallest_merge_lens:
            type='a')

        # # Cropping
        # if crop:
        #     ifp.crop([10, 200, 200], [110, 712, 712])

        # ifp.write()

        # ifp.logging('ifp.get_image = {}', ifp.get_image('labels')[0, 0, 0])
        # ifp.logging('ifp.amax = {}\n', ifp.amax('labels'))

        ifp.logging('keys() = {}', ifp.get_data().keys())

        # For multiple labels
        ifp.logging('Starting label iterator for {} labels',
                    len(ifp.anytask_rtrn(np.unique, ids='labels')))

        c = 0
        for lblo in ifp.label_bounds_iterator('labels',
                                              'curlabel',
                                              ids='disttransf',
                                              targetids='curdisttransf',
                                              maskvalue=0,
                                              value=0):

            ifp.logging('------------\nCurrent label {} in iteration {}',
                        lblo['label'], c)
            ifp.logging('Bounding box = {}', lblo['bounds'])

            local_maxima_found = find_local_maxima(ifp)