Beispiel #1
0
    def clustering(n_generations, initial_state, k_thresh, noisy, sensitivity):
        reel = []
        kernel = [[1, 1, 1], [1, 0, 1], [1, 1, 1]]
        for gen in range(n_generations):
            state = np.array(initial_state).flatten()
            ii = 0
            minima = np.array(initial_state).min()
            mean = np.array(initial_state).mean()
            for cell in ndi.convolve(initial_state, kernel).flatten():
                if cell >= k_thresh + mean:
                    state[ii] = 0
                if cell == 0:
                    state[ii] = 1
                ii += 1
            initial_state = state.reshape(np.array(initial_state).shape)
            reel.append(initial_state)
            if noisy and ii > 0 and gen % 10 == 0:
                initial_state += imutils.draw_centered_circle(
                    initial_state,
                    np.array(initial_state).shape[0] / 4, mean, False)
            if noisy and ii > 0 and gen % 10 == 0:
                initial_state -= sensitivity * np.random.random_integers(
                    0, 1, 10000).reshape(100, 100) / 2

        return reel, initial_state
Beispiel #2
0
def main():
    k0 = [[1, 1, 1], [1, 0, 1], [1, 1, 1]]
    k1 = [[1, 1, 1], [1, 1, 1], [1, 1, 1]]
    k2 = [[0, 1, 0], [1, 1, 1], [0, 1, 0]]
    k3 = [[1, 1, 1, 1], [1, 0, 0, 1], [1, 0, 0, 1], [1, 1, 1, 1]]
    k4 = [[0, 0, 0, 0], [0, 1, 1, 0], [0, 1, 1, 0], [0, 0, 0, 0]]

    W = 250
    H = 250

    state_0 = np.array(np.random.random_integers(0, 256, W * H).reshape((W, H)) >= 2).astype(np.int)
    state_1 = imutils.draw_centered_box(np.zeros((W, H)), W / 3, 1, False)
    state_2 = imutils.draw_centered_circle(np.zeros((W, H)), W / 3, 1, False)

    if '-f' in sys.argv:
        sim = {'kernel': k4,
               'render': True,
               'frame_rate': 50,
               'save': False,
               'file_name': '',
               'verbose': True}
        test_run(100, state_2 + state_0, sim)
        sim['kernel'] = k3
        test_run(100, state_1 + state_0, sim)

    if '-d' in sys.argv:
        sim = {'kernel': k4,
               'render': True,
               'frame_rate': 50,
               'save': False,
               'file_name': '',
               'verbose': True}
        dilate(100, state_2 + state_0, sim)
        sim['kernel'] = k3
        dilate(100, state_1 + state_0, sim)
Beispiel #3
0
def main():
    colors = {
        'R': [1, 0, 0],
        'G': [0, 1, 0],
        'B': [0, 0, 1],
        'C': [0, 1, 1],
        'M': [1, 0, 1],
        'Y': [1, 1, 0],
        'K': [0, 0, 0],
        'W': [1, 1, 1]
    }
    width = 250
    height = 250
    n_particles = 100
    state = np.zeros((width, height, 3))
    ''' Adding Electro Circle] '''
    e_sz = 10
    state[:, :, 2] = imutils.draw_centered_circle(state[:, :, 2], e_sz, 1,
                                                  False)
    nucleus = Particle(10, e_sz, [int(width / 2), int(height / 2)])
    ''' Adding particles '''
    add_particles(state, nucleus, n_particles)
Beispiel #4
0
import scipy.misc as misc
import numpy as np
import imutils
import numpy
import time
import sys
import os

if '-circle' in sys.argv:
    try:
        size = int(sys.argv[2])
    except IndexError:
        print '** Incorrect Usage!! **'
        print 'ex: python imagen.py -circle 200'
        exit()
    circle = imutils.draw_centered_circle(np.zeros((2 * size, 2 * size)), size,
                                          1, True)
    if '-save' in sys.argv and len(sys.argv) < 4:
        print '** Incorrect Usage!! **'
        print 'ex:'
        exit()
    elif '-save' in sys.argv and len(sys.argv) == 5:
        print 'Drawing Circle with radius %d and saving as %s' % (size,
                                                                  sys.argv[4])
        try:
            misc.imsave(sys.argv[4], circle)
        except ValueError:
            print '** Illegal File Extension! **'
            exit()
if '-box' in sys.argv:
    try:
        size = int(sys.argv[2])
Beispiel #5
0
                                  film,
                                  blit=True,
                                  interval=save['frame_rate'],
                                  repeat_delay=900)
    if save['save']:
        writer = FFMpegWriter(fps=save['frame_rate'], bitrate=1800)
        a.save(save['name'], writer)
    print 'Simulation FINISHED\t[%ss Elapsed]' % str(time.time() - tic)
    plt.show()


if __name__ == '__main__':
    w = 250
    h = 250
    depth = 150
    initial_state = imutils.draw_centered_circle(np.zeros((w, h)), w / 3, 255,
                                                 False)
    initial_state -= imutils.draw_centered_box(np.zeros((w, h)), w / 4, 128,
                                               False)
    # initial_state = abs(initial_state-imutils.draw_centered_box(np.zeros((w, h)), w/4, 128, False))
    opts = {'save': False, 'frame_rate': 10}

    if '-i' in sys.argv:
        initial_state = np.array(plt.imread(sys.argv[2])).astype(np.float)
        if len(initial_state.shape) == 3:
            initial_state = initial_state[:, :, 2]
            opts = {
                'save': True,
                'frame_rate': 45,
                'name': sys.argv[2].split('.')[0] + '_sim.mp4'
            }
    print '\033[1m\t\t<<_Starting_Simulation_>>\033[0m'
def main():
    dims = [250, 250]
    state = imutils.draw_centered_circle(np.zeros(dims), 100, False)
    g = generative(dims, state)
    imutils.filter_preview(g.slices)
    g.slice_eval()