示例#1
0
def generate_full_image(color_string, seed):
    r.init_def_generator(seed)

    image = np.zeros((HEIGHT, WIDTH, 3))
    plots = []
    loop_key = r.bind_generator()
    setup_key = r.bind_generator()

    post_process = lambda x: data.integrate_series(
        x, n=2, mean_influences=[0, 0])

    pup = m.SimpleProgression(values=1,
                              self_length=[10, 40, 50],
                              post_process=post_process)
    pdown = m.SimpleProgression(values=-1,
                                self_length=[10, 40, 50],
                                post_process=post_process)
    arc = m.RandomMarkovModel(values=[pup, pdown], self_length=[2])

    p = m.RandomMarkovModel(
        # values=[p1, p2, arc],
        values=[arc],
        parent_rkey=r.bind_generator_from(setup_key))

    # for i in range(-30,30):
    for i in range(1):

        sample = m.sample_markov_hierarchy(p, 1000)
        sample = data.integrate_series(sample, 1, mean_influences=1)
        # sample = data.integrate_series(sample,1,mean_influences=0)
        # sample -= np.min(sample)
        # sample = data.integrate_series(sample,1)

        # slices = [ np.s_[:50],np.s_[50:100], np.s_[100:] ]
        # for slice in slices:
        #     sample[slice] -= np.mean(sample[slice])
        # sample = data.integrate_series(sample,1)
        # sample[:60+i] -= np.mean(sample[:60+i])
        # sample[60+i:] -= np.mean(sample[60+i:])
        # sample = data.integrate_series(sample,1)
        plots += [sample]

    plt.plot(plots[0])
    mng = plt.get_current_fig_manager()
    mng.full_screen_toggle()
    plt.show()
    # viz.animate_plots_y(plots)

    return image
示例#2
0
def gen_coherent_noise(height,width):

    vs = np.linspace(-0.2, 0.2, num=width)
    px_1 = markov.FuzzyProgression(
        values=vs,
        positive_shifts=3, negative_shifts=3,
        repeat_factor=4)

    np.random.seed(120)
    values = []
    for i in range(3):
        mask = np.random.binomial(1, p=0.5, size=width // 10)
        vs = ['0', '1','2' ]
        pattern = ''.join([vs[i] for i in mask])
        print(pattern)
        values += [
            markov.SimplePattern(pattern=pattern, candidates=[-0.5,0,0.5])]

    black_white = markov.RandomMarkovModel(
        values=values,
        child_lengths=[width * i for i in range(1, 2)])
    varied = markov.SimpleProgression(
        values=[px_1],
        child_lengths=[width * i for i in range(10, 15)])
    parent = markov.RandomMarkovModel(
        values=[varied, black_white],
        child_lengths=[1, 2])

    img = markov.paint_linearly_markov_hierarchy(
        markov_tree=parent, width=width, height=height, seed=20)

    return img
    num_tiles = [1,1,2,2,3,4,10,10,20]
    pattern_models = []


    for pat in pats:
        vls = pat['values']
        zeroes = int(NUM_CELLS/3)
        mask = np.random.choice([2,3,4], size=zeroes)
        mask = np.cumsum(mask)
        mask = mask[mask<NUM_CELLS]
        vls[mask] = np.random.choice([NUM_CELLS+1,NUM_CELLS+2,NUM_CELLS+3])
        lngts = pat['lengths']
        model = m.SimpleProgression(values=m.Processor(
            m.SimpleProgression(
                values=vls,
                lenghts=lngts,
                self_length=NUM_CELLS,
                start_probs=[0,1,2,3]),
            num_tiles=num_tiles),self_length=[5,10,15,20,25])
        pattern_models += [model]

    def update_fun(preference_matrix,start_probs):
        return preference_matrix,np.roll(start_probs,shift=1)
    parent = m.RandomMarkovModel(
        values=pattern_models,
        start_probs=0,
        update_fun=update_fun,update_step=1)

    img = gen_portion(
        parent,
        height=HEIGHT,width=WIDTH,
示例#4
0
        current_height += portion_height
        print(current_height, current_tile_width, current_tile_height, l)

        num_segments = current_tile_width // 5
        current_colors = np.random.choice([0, 1, 2, 3, 4, 5],
                                          size=num_segments)
        p = [
            gen_patterns(current_tile_width,
                         num_segments,
                         current_colors,
                         min_length=2) for i in range(np.random.choice([2, 3]))
        ]
        print(p)
        p = [
            m.Processor(m.SimpleProgression(values=i['values'],
                                            lenghts=i['lengths'],
                                            self_length=num_segments,
                                            start_probs=0),
                        num_tiles=[2, 4, 5, 6, 8]) for i in p
        ]

        parent = m.RandomMarkovModel(values=p)

        img = gen_portion(parent,
                          height=portion_height,
                          width=WIDTH,
                          tile_height=current_tile_height,
                          tile_width=current_tile_width)

        portions += [img]
        print(img.shape)
        print(np.min(img))
    def generate_full_image(color_string,seed):
        r.init_def_generator(seed)

        image = np.zeros((HEIGHT,WIDTH,3))
        plots = []
        loop_key = r.bind_generator()
        setup_key = r.bind_generator()


        p1 = m.MarkovModel(
                values=[0.1,-0.1],
                preference_matrix=data.str2mat('1 5, 5 1'),
                self_length=SEGMENT_LENGTH,
                parent_rkey=r.bind_generator_from(setup_key)

            )

        p2 = m.MarkovModel(
            values=[-0.1, 0.1],
            preference_matrix=data.str2mat('1 5, 5 1'),
            self_length=SEGMENT_LENGTH,
            parent_rkey=r.bind_generator_from(setup_key)

        )

        num_coefs = 12
        vs = np.sin(np.linspace(0, 1, num_coefs) * np.pi * 2) * 0.1
        p3 = m.SimpleProgression(
            values=vs,
            start_probs=0,
            self_length=[num_coefs],
            parent_rkey=r.bind_generator_from(loop_key)
        )

        p = m.MarkovModel(
            values=[p1, p2, p3],
            start_probs=2,
            preference_matrix=data.str2mat(
                '0 1 2, 1 0 2, 1 1 4'),
            self_length=HEIGHT//SEGMENT_LENGTH+1,
            parent_rkey=r.bind_generator_from(setup_key)
        )

        num_samples_1 = HEIGHT//2
        sample_scale_1 = m.sample_markov_hierarchy(p, num_samples_1)
        sample_2 = m.sample_markov_hierarchy(p, num_samples_1)
        sample_3 = m.sample_markov_hierarchy(p, num_samples_1)

        # interpolation_h_1 = integrate_and_normalize(sample_scale_1,2)
        # interpolation_h_2 = integrate_and_normalize(sample_2,2)
        interpolation_color = integrate_and_normalize(sample_3,2)

        color_repo = color.build_color_repository(color_string)
        meta = color.get_meta_from_palette(
            color_repo['First'],
            keys=[0,1,2,3],
            meta_cast_function=int)
        print(meta)
        color_lines = compute_color_lines(color_repo,interpolation_color)
        print(color_lines.shape)

        # plt.plot(interpolation_h_1)
        # plt.plot(interpolation_h_2)
        # plt.plot(interpolation_color)
        # plt.show()


        scale_1_freq = r.choice_from(setup_key,config.get('scale-1-freq-options',[0.025]))
        scale_2_freq = r.choice_from(setup_key,config.get('scale-2-freq-options',[0.02]))
        scale_1_scale = r.choice_from(setup_key,config.get('scale-1-scale-options',[0.02]))
        scale_2_scale = r.choice_from(setup_key,config.get('scale-2-scale-options',[0.02]))
        num_sin_coeffs = r.choice_from(setup_key,config.get('num-sin-coefficients-options',[18]))

        f1_scale = r.choice_from(setup_key,config.get('f1-scale-options',[0.2]))
        f2_scale = r.choice_from(setup_key,config.get('f2-scale-options',[0.4]))
        f3_scale = r.choice_from(setup_key,config.get('f3-scale-options',[0.15]))


        for current_row in range(HEIGHT):

            loop_key = r.reset_key(loop_key)

            # self_length = SEGMENT_LENGTH+int(10*np.sin(np.pi*i*0.01))
            self_length = SEGMENT_LENGTH
            # scale_1 = 0.1 * (1 - interpolation_h_1[current_row]) + 0.15 * interpolation_h_1[current_row]
            scale_1 = 0.1 + scale_1_scale * np.sin(np.pi * current_row * scale_1_freq )
            scale_2 = 0.1 + scale_2_scale * np.sin(np.pi * current_row * scale_2_freq )
            p1 = m.MarkovModel(
                values=[scale_1, -scale_2],
                preference_matrix=data.str2mat('1 5, 5 1'),
                self_length=self_length,
                parent_rkey=r.bind_generator_from(loop_key)

            )

            p2 = m.MarkovModel(
                values=[-scale_1, scale_2],
                preference_matrix=data.str2mat('1 5, 5 1'),
                self_length=self_length,
                parent_rkey=r.bind_generator_from(loop_key)

            )

            zeros = m.MarkovModel(
                values=[0,0],
                preference_matrix=data.str2mat('1 1, 1 1'),
                self_length=self_length*3,
                parent_rkey=r.bind_generator_from(loop_key)

            )

            jumps = m.MarkovModel(
                values=[-0.5, 0.5],
                preference_matrix=data.str2mat('1 1, 1 1'),
                self_length=1,
                parent_rkey=r.bind_generator_from(loop_key)

            )

            num_coefs = num_sin_coeffs
            vs = np.sin(np.linspace(0, 1, num_coefs) * np.pi * 2)*0.1
            p3 = m.SimpleProgression(
                values=vs,
                start_probs=0,
                self_length=[num_coefs],
                parent_rkey=r.bind_generator_from(loop_key)
            )

            p = m.MarkovModel(
                values=[p1, p2, p3, jumps, zeros],
                start_probs=2,
                preference_matrix=data.str2mat(
                    '0 1 2 2 1, 1 0 2 2 1, 1 1 4 2 2, 1 1 2 0 0, 1 1 1 1 2'),
                self_length=WIDTH//SEGMENT_LENGTH+1,
                parent_rkey=r.bind_generator_from(loop_key)
            )

            num_samples_1 = WIDTH//4
            num_samples_2 = WIDTH//3
            sample_x_up = m.sample_markov_hierarchy(p, num_samples_1)
            sample_x_down = m.sample_markov_hierarchy(p, num_samples_2)

            sample_x_up_int = data.integrate_series(sample_x_up,2,mean_influence=1)
            sample_x_down_int = data.integrate_series(sample_x_down,2,mean_influence=1)

            f1 = 0.5 + f1_scale * np.sin(np.pi * current_row * 0.002 )
            f2 = -1 - f2_scale * np.sin(np.pi * current_row * 0.002 )
            f3 = 0.3 + f3_scale * np.sin(np.pi * current_row * 0.001 )

            sample_x_up_int = data.concat_signals(
                [sample_x_up_int]*4,
                [f1,f2,f1,f2])

            sample_x_down_int = data.concat_signals(
                [sample_x_down_int,sample_x_down_int,sample_x_down_int],
                [f3, f1, f3])
            sample_x_down_int = np.r_[sample_x_down_int[0],sample_x_down_int]


            # roll_distance = 500 + int((interpolation_h_2[current_row]-0.5)*250)
            # roll_distance = 500 + int(current_row)
            # print(roll_distance)
            # sample_x_down_int = np.roll(sample_x_down_int, roll_distance)


            sample_x = sample_x_up_int + sample_x_down_int
            interpolation_sequence = sample_x[:HEIGHT]


            interpolation_sequence = gaussian_filter(interpolation_sequence,sigma=1)
            interpolation_sequence -= np.min(interpolation_sequence)
            interpolation_sequence /= np.max(interpolation_sequence)
            # interpolation_sequence = data.ease_inout_sin(interpolation_sequence)
            interpolation_sequence *= 3

            # interpolation_sequence *= 2
            # print(interpolation_sequence)

            gradient = data.interpolate(
                color_lines[:,current_row,:],
                interpolation_sequence,
                value_influences=meta
            )
            gradient = color.cam02_2_srgb(gradient)
            image[current_row] = gradient

            plots += [np.copy(interpolation_sequence)]

        image = data.upscale_nearest(image,ny=UPSCALE_FACTOR_Y,nx=UPSCALE_FACTOR_X)
        image[image<0] = 0
        image[image>255] = 255

        if SHOW_DEBUG_DATA is True:
            viz.animate_plots_y(plots)

        return image
示例#6
0
                PATTERN_LENGTH,
                size=np.random.choice(PATTERN_LENGTH // 2 - 1) + 1,
                replace=False)) for i in range(30)
    ] + ['0' * PATTERN_LENGTH]

    patterns_white = [
        m.SimplePattern(pattern=i, candidates=[0, 1]) for i in patterns_white
    ]

    patterns_black = [
        m.SimplePattern(pattern=i, candidates=[0, 1]) for i in patterns_black
    ]

    row_patterns_white = [
        m.SimpleProgression(values=m.RandomMarkovModel(values=patterns_white,
                                                       child_lengths=[i]),
                            child_lengths=j)
        for (i, j) in [[50, 4], [100, 20], [200, 1]]
    ]

    row_patterns_white = m.RandomMarkovModel(values=row_patterns_white,
                                             child_lengths=5)

    row_patterns_black = [
        m.SimpleProgression(values=m.RandomMarkovModel(values=patterns_black,
                                                       child_lengths=[i]),
                            child_lengths=j)
        for (i, j) in [[50, 4], [100, 20], [200, 1]]
    ]

    row_patterns_black = m.RandomMarkovModel(values=row_patterns_black,
示例#7
0
                       self_length=self_length_1)

    p2 = m.MarkovModel(values=[-0.02, -0.02],
                       preference_matrix=data.str2mat('1 1, 1 1'),
                       self_length=self_length_1)

    p3 = m.MarkovModel(values=[0.01, 0.01],
                       preference_matrix=data.str2mat('1 1, 1 1'),
                       self_length=self_length_1)

    p4 = m.MarkovModel(values=[0.02, 0.02],
                       preference_matrix=data.str2mat('1 1, 1 1'),
                       self_length=self_length_1)

    p5 = m.SimpleProgression(
        values=[-0.02, -0.01, 0, 0.01, 0.02, 0.02, 0.01, 0, -0.01, -0.02],
        self_length=self_length_2)

    p = m.MarkovModel(
        values=[p1, p2, p3, p4, p5],
        preference_matrix=data.str2mat(
            ' 1 0 1 0 1, 0 0 0 0 1, 1 0 1 0 1, 0 0 0 0 1 ,1 1 1 1 1 '),
    )

    num_samples = 1000
    sample_x = m.sample_markov_hierarchy(p, num_samples)
    sample_x_1 = np.cumsum(sample_x)
    sample_x_2 = np.cumsum(sample_x_1)
    sample_x_2 /= np.max(np.abs(sample_x_2))

    plt.plot(sample_x_2 + i * 0.05, label=str(i), c='b', alpha=0.1)
示例#8
0
            gen_all_possible_permutations('11100-11100', ['0', '1', '2']),
            gen_all_possible_permutations('00111-00111', ['0', '1', '2']),
            gen_all_possible_permutations('01122-01122', ['0', '1', '2']),
            gen_all_possible_permutations('11220-11220', ['0', '1', '2']),
            gen_all_possible_permutations('21200-21200', ['0', '1', '2']),
            gen_all_possible_permutations('00212-00212', ['0', '1', '2']),
            gen_all_possible_permutations('01000-00220', ['0', '1', '2']),
            gen_all_possible_permutations('02200-00010', ['0', '1', '2']),
        ]

        pats = [j for i in pats for j in i]

        pats = [
            m.SimpleProgression(values=m.SimplePattern(pattern=i,
                                                       candidates=[0] +
                                                       [int(a), int(b)],
                                                       start_probs=0),
                                child_lengths=TILE_WIDTH) for i in pats
        ]

        pats = m.Processor(m.SimpleProgression(values=m.RandomMarkovModel(
            values=pats, child_lengths=1),
                                               child_lengths=TILE_HEIGHT),
                           num_tiles=TILING_OPTIONS)

        basic_tiles += [pats]

    basic_tiles = m.SimpleProgression(values=basic_tiles, child_lengths=1)

    r = [m.SimpleProgression(values=i) for i in [2, 3, 10, 11, 12]]
    random_tiles = m.Processor(m.SimpleProgression(
                                 lengths=lengths,
                                 candidates=[11, 12, 13]),
            markov.SimplePattern(pattern,
                                 lengths=lengths,
                                 candidates=[11, 12, 13])
        ]

    base = markov.Processor(markov.Processor(markov.RandomMarkovModel(
        values=base_values,
        child_lengths=[WIDTH // 10],
        seed=current_iteration * 50),
                                             num_tiles=[7]),
                            num_tiles=[4, 5])

    bg = [
        markov.Processor(markov.SimpleProgression(values=[i]),
                         num_tiles=WIDTH * 3) for i in [11, 13]
    ]

    bg = markov.RandomMarkovModel(values=bg, child_lengths=[1])

    pure = [
        markov.Processor(markov.SimpleProgression(values=[i]),
                         num_tiles=WIDTH // 10) for i in [1, 2, 3, 4, 5]
    ]

    pure = markov.Processor(markov.SimpleProgression(values=[
        markov.RandomMarkovModel(values=pure,
                                 child_lengths=[1, 2, 3],
                                 seed=current_iteration)
    ],