Example #1
0
    def visualize(num_osc, steps, type_conn, repr_type, stimulus, height, width, ccore):
        net = pcnn_network(num_osc, None, type_conn, repr_type, None, None, ccore);
        dynamic = net.simulate(steps, stimulus);

        pcnn_visualizer.show_time_signal(dynamic);
        pcnn_visualizer.show_output_dynamic(dynamic);
        pcnn_visualizer.animate_spike_ensembles(dynamic, (height, width));
def template_segmentation_image(image, parameters, simulation_time, brightness, scale_color = True, fastlinking = False, show_spikes = False, ccore_flag = True):
    image_source = Image.open(image);
    image_size = image_source.size;
    
    width = image_size[0];
    height = image_size[1];
    
    stimulus = read_image(image);
    stimulus = rgb2gray(stimulus);
    
    if (brightness != None):
        for pixel_index in range(len(stimulus)):
            if (stimulus[pixel_index] < brightness): stimulus[pixel_index] = 1;
            else: stimulus[pixel_index] = 0;
    else:
        maximum_stimulus = float(max(stimulus));
        minimum_stimulus = float(min(stimulus));
        delta = maximum_stimulus - minimum_stimulus;
        
        for pixel_index in range(len(stimulus)):
            if (scale_color is True):
                stimulus[pixel_index] = 1.0 - ((float(stimulus[pixel_index]) - minimum_stimulus) / delta);
            else:
                stimulus[pixel_index] = float(stimulus[pixel_index]) / 255;
    
    if (parameters is None):
        parameters = pcnn_parameters();
    
        parameters.AF = 0.1;
        parameters.AL = 0.1;
        parameters.AT = 0.8;
        parameters.VF = 1.0;
        parameters.VL = 1.0;
        parameters.VT = 30.0;
        parameters.W = 1.0;
        parameters.M = 1.0;
        
        parameters.FAST_LINKING = fastlinking;
    
    net = pcnn_network(len(stimulus), parameters, conn_type.GRID_EIGHT, height = height, width = width, ccore = ccore_flag);
    output_dynamic = net.simulate(simulation_time, stimulus);
    
    pcnn_visualizer.show_output_dynamic(output_dynamic);
    
    ensembles = output_dynamic.allocate_sync_ensembles();
    draw_image_mask_segments(image, ensembles);
    
    pcnn_visualizer.show_time_signal(output_dynamic);
    
    if (show_spikes is True):
        spikes = output_dynamic.allocate_spike_ensembles();
        draw_image_mask_segments(image, spikes);
        
        pcnn_visualizer.animate_spike_ensembles(output_dynamic, image_size);
def template_segmentation_image(image, parameters, simulation_time, brightness, scale_color = True, fastlinking = False, show_spikes = False, ccore_flag = True):
    image_source = Image.open(image);
    image_size = image_source.size;
    
    width = image_size[0];
    height = image_size[1];
    
    stimulus = read_image(image);
    stimulus = rgb2gray(stimulus);
    
    if (brightness != None):
        for pixel_index in range(len(stimulus)):
            if (stimulus[pixel_index] < brightness): stimulus[pixel_index] = 1;
            else: stimulus[pixel_index] = 0;
    else:
        maximum_stimulus = float(max(stimulus));
        minimum_stimulus = float(min(stimulus));
        delta = maximum_stimulus - minimum_stimulus;
        
        for pixel_index in range(len(stimulus)):
            if (scale_color is True):
                stimulus[pixel_index] = 1.0 - ((float(stimulus[pixel_index]) - minimum_stimulus) / delta);
            else:
                stimulus[pixel_index] = float(stimulus[pixel_index]) / 255;
    
    if (parameters is None):
        parameters = pcnn_parameters();
    
        parameters.AF = 0.1;
        parameters.AL = 0.1;
        parameters.AT = 0.8;
        parameters.VF = 1.0;
        parameters.VL = 1.0;
        parameters.VT = 30.0;
        parameters.W = 1.0;
        parameters.M = 1.0;
        
        parameters.FAST_LINKING = fastlinking;
    
    net = pcnn_network(len(stimulus), parameters, conn_type.GRID_EIGHT, height = height, width = width, ccore = ccore_flag);
    output_dynamic = net.simulate(simulation_time, stimulus);
    
    pcnn_visualizer.show_output_dynamic(output_dynamic);
    
    ensembles = output_dynamic.allocate_sync_ensembles();
    draw_image_mask_segments(image, ensembles);
    
    pcnn_visualizer.show_time_signal(output_dynamic);
    
    if (show_spikes is True):
        spikes = output_dynamic.allocate_spike_ensembles();
        draw_image_mask_segments(image, spikes);
        
        pcnn_visualizer.animate_spike_ensembles(output_dynamic, image_size);
def template_segmentation_image(image,
                                parameters,
                                simulation_time,
                                brightness,
                                scale_color=True,
                                fastlinking=False,
                                show_spikes=False,
                                ccore_flag=True):
    image_source = Image.open(image)
    image_size = image_source.size

    width = image_size[0]
    height = image_size[1]

    stimulus = read_image(image)
    stimulus = rgb2gray(stimulus)

    if brightness is not None:
        for pixel_index in range(len(stimulus)):
            if stimulus[pixel_index] < brightness:
                stimulus[pixel_index] = 1
            else:
                stimulus[pixel_index] = 0
    else:
        maximum_stimulus = float(max(stimulus))
        minimum_stimulus = float(min(stimulus))
        delta = maximum_stimulus - minimum_stimulus

        for pixel_index in range(len(stimulus)):
            if scale_color is True:
                stimulus[pixel_index] = 1.0 - (
                    (float(stimulus[pixel_index]) - minimum_stimulus) / delta)
            else:
                stimulus[pixel_index] = float(stimulus[pixel_index]) / 255

    if parameters is None:
        parameters = pcnn_parameters()

        parameters.AF = 0.1
        parameters.AL = 0.1
        parameters.AT = 0.8
        parameters.VF = 1.0
        parameters.VL = 1.0
        parameters.VT = 30.0
        parameters.W = 1.0
        parameters.M = 1.0

        parameters.FAST_LINKING = fastlinking

    net = pcnn_network(len(stimulus),
                       parameters,
                       conn_type.GRID_EIGHT,
                       height=height,
                       width=width,
                       ccore=ccore_flag)
    output_dynamic = net.simulate(simulation_time, stimulus)

    pcnn_visualizer.show_output_dynamic(output_dynamic)

    ensembles = output_dynamic.allocate_sync_ensembles()
    draw_image_mask_segments(image, ensembles)

    pcnn_visualizer.show_time_signal(output_dynamic)

    if show_spikes is True:
        spikes = output_dynamic.allocate_spike_ensembles()
        draw_image_mask_segments(image, spikes)

        pcnn_visualizer.animate_spike_ensembles(output_dynamic, image_size)