示例#1
0
def test_run_algo():
    """Unit test for runAlgo function.
     Checks to see if the output is what it's supposed to be in this case."""
    individual = Segmentors.segmentor()
    data = pipedata()
    data.img = TEST_IM_COLOR
    data.gmask = TEST_IM_COLOR[:, :, 0]
    individual.runAlgo(data)
示例#2
0
def segmentwidget(img, gmask, params=None, alg=None):
    """Generate GUI. Produce slider for each parameter for the current segmentor.
     Show both options for the masked image.

    Keyword arguments:
    img -- original image
    gmask -- ground truth segmentation mask for the image
    params -- list of parameter options
    alg -- algorithm to search parameters over

    """
    if params:
        if alg:
            params[0] = alg;
        seg = Segmentors.algoFromParams(params)
    else:
        if alg:
            algorithm_gen = Segmentors.algorithmspace[alg]
            seg = algorithm_gen()
        else:
            seg = Segmentors.segmentor()

    widg = dict()
    widglist = []

    for ppp, ind in zip(seg.paramindexes, range(len(seg.paramindexes))):
        thislist = eval(seg.params.ranges[ppp])
        name = ppp
        current_value = seg.params[ppp]
        if not current_value in thislist:
            #TODO: We should find the min distance between current_value and this list and use that instead.
            current_value = thislist[0]
            
        thiswidg = widgets.SelectionSlider(options=tuple(thislist),
                                           disabled=False,
                                           description=name,
                                           value=current_value,
                                           continuous_update=False,
                                           orientation='horizontal',
                                           readout=True
                                          )

        widglist.append(thiswidg)
        widg[ppp] = thiswidg

#     algorithms = list(Segmentors.algorithmspace.keys())
#     w = widgets.Dropdown(
#         options=algorithms,
#         value=algorithms[0],
#         description='Choose Algorithm:',
#     )
    

    
    def func(img=img, mask=gmask, **kwargs):
        """Find mask and fitness for current algorithm. Show masked image."""
        print(seg.params["algorithm"])
        for k in kwargs:
            seg.params[k] = kwargs[k]
        mask = seg.evaluate(img)
        fit = Segmentors.FitnessFunction(mask, gmask)
        fig = showtwo(img, mask)
        # I like the idea of printing the sharepython but it should be below the figures. 
        #print(seg.sharepython(img))
#         plt.title('Fitness Value: ' + str(fit[0]))

    
    layout = widgets.Layout(grid_template_columns='1fr 1fr 1fr')
    u_i = widgets.GridBox(widglist, layout=layout)
    out = widgets.interactive_output(func, widg)
    display(u_i, out)
    
    return seg.params
示例#3
0
def test_parameter_len():
    """Unit test for parameters function. Checks formatting of parameter."""
    param = Segmentors.segmentor().params
    assert len(param) > 1