def gen_channel(seed):
    img = markov.paint_linearly_markov_hierarchy(markov_tree=parent,
                                                 width=WIDTH,
                                                 height=HEIGHT,
                                                 seed=seed)
    img = data.upscale_nearest(img, UPSCALE_FACTOR)
    return img.reshape(HEIGHT * UPSCALE_FACTOR, WIDTH * UPSCALE_FACTOR, 1)
Beispiel #2
0
def generate_image(gridx, gridy, list_color_dict):

    color_keys = [list(i.keys()) for i in list_color_dict]
    img = np.zeros((HEIGHT, WIDTH, 3))

    startx = 0
    starty = 0
    for y in np.append(gridy, HEIGHT):
        endy = y
        for x in np.append(gridx, WIDTH):
            endx = x

            height = endy - starty
            width = endx - startx
            d = r.choice([0, 1, 2])
            c1, c2 = r.choice(color_keys[d], size=2, replace=False)
            img[starty:endy,
                startx:endx] = generate_patch(height, width,
                                              list_color_dict[d],
                                              r.choice([1, -1]))
            startx = endx

        startx = 0
        starty = endy

    final = data.upscale_nearest(img, ny=UPSCALE_FACTOR, nx=UPSCALE_FACTOR)

    return final.astype('uint8')
Beispiel #3
0
    def generate_full_image(color_string, seed):
        r.init_def_generator(seed)

        rkey = r.bind_generator()
        lp = len(PS)
        guard_size = 450
        image = np.zeros((HEIGHT + guard_size * 2, WIDTH + guard_size * 2))

        # num_circles = r.choice_from(rkey,[5,10,15,20,25])
        # num_circles = r.choice_from(rkey,[30,40,50,60,70,80,90,100])
        # num_circles = r.choice_from(rkey,[80,120,140])
        # num_circles = r.choice_from(rkey,[200,220,240])
        num_circles = 10
        ps = r.choice_from(rkey, PS, lp)
        for i in range(num_circles):

            loopkey = r.bind_generator_from(rkey)
            band_size = r.choice_from(loopkey, [10] + [15])
            circle = gradient_circle(band_size, PS[::-1] + PS[::2] + PS[1::2],
                                     r.bind_generator_from(loopkey))

            cheight, cwidth = circle.shape

            xstart = r.choice_from(loopkey, np.arange(WIDTH + 250))
            ystart = r.choice_from(loopkey, np.arange(HEIGHT + 250))

            image[ystart:ystart + cheight, xstart:xstart + cwidth] += circle

        image = image[guard_size:HEIGHT + guard_size,
                      guard_size:WIDTH + guard_size]
        image /= np.max(image)

        return data.upscale_nearest(data.prepare_image_for_export(image * 255),
                                    ny=UPSCALE_FACTOR_Y,
                                    nx=UPSCALE_FACTOR_X)
Beispiel #4
0
def gen_channel(parent):
    img = m.paint_linearly_markov_hierarchy(markov_tree=parent,
                                            width=WIDTH,
                                            height=HEIGHT,
                                            tile_height=TILE_HEIGHT,
                                            tile_width=TILE_WIDTH)
    img = data.upscale_nearest(img, UPSCALE_FACTOR)
    # img = data.upscale_with_circle(img,UPSCALE_FACTOR,bg=0)
    # img = data.upscale_with_shape(img,line,bg=0)
    return img.reshape(img.shape[0], img.shape[1], 1)
Beispiel #5
0
    def generate_full_image(color_string, seed):
        r.init_def_generator(seed)

        rkey = r.bind_generator()

        p = PS[current_iteration]

        image = r.binomial_from(rkey, 1, p, size=(HEIGHT, WIDTH)) * 255

        return data.upscale_nearest(data.prepare_image_for_export(image),
                                    ny=UPSCALE_FACTOR_Y,
                                    nx=UPSCALE_FACTOR_X)
Beispiel #6
0
    def generate_full_image(color_string, seed):
        r.init_def_generator(seed)

        rkey = r.bind_generator()
        image = np.zeros((HEIGHT, WIDTH))

        for i in range(NUM_SEGMENTS):
            start = i * SEGMENT_LENGTH
            end = (i + 1) * SEGMENT_LENGTH
            image[:,
                  start:end] = r.binomial_from(rkey,
                                               1,
                                               PS[i],
                                               size=(HEIGHT, SEGMENT_LENGTH))

        return data.upscale_nearest(data.prepare_image_for_export(image * 255),
                                    ny=UPSCALE_FACTOR_Y,
                                    nx=UPSCALE_FACTOR_X)
Beispiel #7
0
    def generate_full_image(color_string,seed):
        r.init_def_generator(seed)

        rkey = r.bind_generator()
        image = np.zeros((HEIGHT,WIDTH))

        p1,p2 = PS[current_iteration]


        image[:,:WIDTH//2] = r.binomial_from(rkey,1,p1,size=(HEIGHT,WIDTH//2))
        image[:,WIDTH//2:] = r.binomial_from(rkey,1,p2,size=(HEIGHT,WIDTH//2))



        return  data.upscale_nearest(
            data.prepare_image_for_export(image*255),
            ny=UPSCALE_FACTOR_Y,
            nx=UPSCALE_FACTOR_X
        )
Beispiel #8
0
    def generate_full_image(color_string, seed):
        r.init_def_generator(seed)

        rkey = r.bind_generator()
        lp = len(PS)
        template_height = lp * BAND_LEN
        image = np.zeros((template_height, template_height))

        for i, p in enumerate(PS):
            cheight = (lp - i) * BAND_LEN
            c = gen.circle((template_height, template_height), cheight // 2)
            p = r.binomial_from(rkey,
                                1,
                                p,
                                size=(template_height, template_height))
            mask = c == 1
            image[mask] = p[mask]

        return data.upscale_nearest(data.prepare_image_for_export(image * 255),
                                    ny=UPSCALE_FACTOR_Y,
                                    nx=UPSCALE_FACTOR_X)
Beispiel #9
0
    def generate_full_image(color_string, seed):
        r.init_def_generator(seed)

        rkey = r.bind_generator()

        template_height = NUM_BANDS * BAND_LEN
        image = np.zeros((template_height, template_height))

        for i, p in enumerate(range(NUM_BANDS)):
            cheight = (NUM_BANDS - i) * BAND_LEN
            c = gen.circle((template_height, template_height), cheight // 2)
            p = r.poisson_from(rkey,
                               i + 1.1,
                               size=(template_height, template_height))
            mask = c == 1
            image[mask] = p[mask]

        image = image / np.max(image)

        return data.upscale_nearest(data.prepare_image_for_export(image * 255),
                                    ny=UPSCALE_FACTOR_Y,
                                    nx=UPSCALE_FACTOR_X)
Beispiel #10
0
    def generate_full_image(color_string,seed):
        r.init_def_generator(seed)

        rkey = r.bind_generator()
        guard_size = 200
        image = np.zeros((HEIGHT+guard_size*2,WIDTH+guard_size*2))

        num_circles = r.choice_from(rkey,[5,10,15,20,25])
        # num_circles = r.choice_from(rkey,[30,40,50,60,70,80,90,100])
        # num_circles = r.choice_from(rkey,[400,500,600,700,800])
        for i in range(num_circles):

            loopkey = r.bind_generator_from(rkey)
            band_size = r.choice_from(loopkey,np.arange(5,10))
            circle = gradient_circle(
                band_size,
                r.bind_generator_from(loopkey)
            )

            cheight,cwidth = circle.shape

            xstart = r.choice_from(loopkey,np.arange(WIDTH+100))
            ystart = r.choice_from(loopkey,np.arange(HEIGHT+100))
            image[ystart:ystart+cheight,xstart:xstart+cwidth] += circle

        image /= np.max(image)
        image = image[
                guard_size:HEIGHT+guard_size,
                guard_size:WIDTH+guard_size]


        return  data.upscale_nearest(
            data.prepare_image_for_export(image*255),
            ny=UPSCALE_FACTOR_Y,
            nx=UPSCALE_FACTOR_X
        )
                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,
        tile_height=None,tile_width=None)

    final_img_prototype = data.upscale_nearest(img,UPSCALE_FACTOR)
    final_img = color.replace_indices_with_colors(final_img_prototype,COLOR_DICT).astype('uint8')
    if N==1:
        viz.start_color_editing_tool(
            blueprint=final_img_prototype,
            color_dict=COLOR_DICT,
            downsample=2)
    else:
        file.export_image(
            '%d_%d' % (current_iteration,int(round(time.time() * 1000))),
            final_img,format='png')
    child_lengths = [2 * WIDTH // 10, 3 * WIDTH // 10, 4 * WIDTH // 10]
    patterns = m.Proc(m.RMM(values=patterns,
                            child_lengths=child_lengths,
                            self_length=15),
                      length_limit=WIDTH,
                      num_tiles=[2, 3])

    patterns = m.SProg(values=patterns, self_length=[1, 2, 3])

    parent = m.RMM(values=[base_pattern, patterns])

    img = gen_portion(parent, HEIGHT, WIDTH)
    print(img)
    img_acum = np.cumsum(img, axis=1)
    img_acum = data.upscale_nearest(img_acum, UPSCALE_FACTOR)
    colors = data.upscale_nearest(colors, ny=1, nx=UPSCALE_FACTOR)

    if N == 1:
        viz.start_color_editing_tool(
            blueprint=img_acum,
            color_dict=COLOR_DICT,
            downsample=2,
            gen_fun=lambda x, y: gen_img_from_accumulations_blueprint(
                x, colors[:, ::2], y))
    else:
        final_img = gen_img_from_accumulations_blueprint(
            img_acum, colors, COLOR_DICT)
        file.export_image('%d_%d' %
                          (current_iteration, int(round(time.time() * 1000))),
                          final_img.astype('uint8'),
def generate_image(gridx, gridy, list_color_dict):

    img = np.zeros((HEIGHT, WIDTH, 3), dtype='float64')

    startx = 0
    starty = 0

    y_iteration = 0
    gridyextended = np.append(gridy, HEIGHT)
    gridxextended = np.append(gridx, HEIGHT)
    occupied = np.zeros((gridyextended.size, gridxextended.size), dtype='bool')
    for i, y in enumerate(gridyextended):
        endy = y
        y_iteration += 1
        for j, x in enumerate(gridxextended):
            endx = x

            if occupied[i, j] > 0:
                startx = endx
                continue

            p = 0.5
            elongatey = r.choice([True, False], p=[p, 1 - p])
            elongatex = r.choice([True, False], p=[p, 1 - p])
            if i >= gridyextended.size - 1: elongatey = False
            if j >= gridxextended.size - 1: elongatex = False

            startyactual = starty
            endyactual = endy
            startxactual = startx
            endxactual = endx

            height = endy - starty
            width = endx - startx

            if elongatey:
                add_height = gridyextended[i + 1] - gridyextended[i]
                height = endy + add_height - starty
                endyactual += add_height

            if elongatex:
                add_width = gridxextended[j + 1] - gridxextended[j]
                width = endx + add_width - startx
                endxactual += add_width

            if elongatex and elongatey:
                occupied[i:i + 2, j:j + 2] = True
            elif elongatex and not elongatey:
                occupied[i, j:j + 2] = True
            elif elongatey and not elongatex:
                occupied[i:i + 2, j] = True
            else:
                occupied[i, j] = True

            patch = generate_patch(height, width, list_color_dict[0],
                                   list_color_dict[1])
            img[startyactual:endyactual, startxactual:endxactual] = patch

            startx = endx

        startx = 0
        starty = endy

    final = data.upscale_nearest(img, ny=UPSCALE_FACTOR, nx=UPSCALE_FACTOR)

    return final.astype('uint8')
    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
Beispiel #15
0
to_space = [lab, srgb, cam, camucs]
space_back = [lab_back, srgb_back, cam_back, camucs_back]
name = ['lab', 'srgb', 'cam', 'camucs']

for current_iteration in range(N):
    print('CURRENT_ITERATION:', current_iteration)
    np.random.seed(SEED + current_iteration)

    start_rgb = color.hex_2_rgb(START_COLOR)
    end_rgb = color.hex_2_rgb(END_COLOR)

    start_conv = to_space[current_iteration](start_rgb)
    end_conv = to_space[current_iteration](end_rgb)

    num_steps = 50
    interp_j = np.linspace(start_conv[0], end_conv[0], num_steps)
    interp_c = np.linspace(start_conv[1], end_conv[1], num_steps)
    interp_h = np.linspace(start_conv[2], end_conv[2], num_steps)

    gradient = np.stack((interp_j, interp_c, interp_h),
                        axis=1).reshape(1, num_steps, 3)
    gradient = space_back[current_iteration](gradient)
    gradient = np.clip(gradient, 0, 255)
    img = data.upscale_nearest(gradient, ny=1000, nx=20).astype('uint8')
    print(img.shape)

    file.export_image(name[current_iteration] + '%d_%d' %
                      (current_iteration, int(round(time.time() * 1000))),
                      img,
                      format='png')
def generate_image(gridx, gridy, color_repository, rkey):
    keys = list(color_repository.keys())
    key_probabilities = [0.4, 0.4, 0.2]
    img = np.zeros((HEIGHT, WIDTH, 3), dtype='float64')

    startx = 0
    starty = 0

    y_iteration = 0
    gridyextended = np.append(gridy, HEIGHT)
    gridxextended = np.append(gridx, HEIGHT)
    occupied = np.zeros((gridyextended.size, gridxextended.size), dtype='bool')
    for i, y in enumerate(gridyextended):
        endy = y
        y_iteration += 1
        rxkey = r.bind_generator_from(rkey)
        for j, x in enumerate(gridxextended):

            endx = x

            if occupied[i, j] > 0:
                startx = endx
                continue

            p = 0.5
            elongatey = r.choice_from(rxkey, [True, False], p=[p, 1 - p])
            elongatex = r.choice_from(rxkey, [True, False], p=[0, 1])
            if i >= gridyextended.size - 1: elongatey = False
            if j >= gridxextended.size - 1: elongatex = False

            startyactual = starty
            endyactual = endy
            startxactual = startx
            endxactual = endx

            height = endy - starty
            width = endx - startx

            if elongatey:
                add_height = gridyextended[i + 1] - gridyextended[i]
                height = endy + add_height - starty
                endyactual += add_height

            if elongatex:
                add_width = gridxextended[j + 1] - gridxextended[j]
                width = endx + add_width - startx
                endxactual += add_width

            if elongatex and elongatey:
                occupied[i:i + 2, j:j + 2] = True
            elif elongatex and not elongatey:
                occupied[i, j:j + 2] = True
            elif elongatey and not elongatex:
                occupied[i:i + 2, j] = True
            else:
                occupied[i, j] = True

            key = r.choice_from(rxkey, keys, p=key_probabilities)

            patch = r.call_and_bind_from(rxkey, generate_patch, height, width,
                                         color_repository[key])
            img[startyactual:endyactual, startxactual:endxactual] = patch

            startx = endx

        startx = 0
        starty = endy

    final = data.upscale_nearest(img, ny=UPSCALE_FACTOR, nx=UPSCALE_FACTOR)

    return final.astype('uint8')