Пример #1
0
def texture_transfer(args):
    print "Texture Transfer Starting..."
    source_texture = Texture()
    source_texture.load_texture(args.source_texture)
    target_image = Texture()
    target_image.load_texture(args.target_image)
    
    source_corr_texture = Texture()
    target_corr_texture = Texture()
    if args.corr_map_type == 0:
        source_corr_texture.load_texture(args.source_texture, gray=True)
        target_corr_texture.load_texture(args.target_image, gray=True)
    elif args.corr_map_type == 1:
        source_corr_texture.load_texture(args.source_texture,
                                         gray=True, blur=True)
        
        target_corr_texture.load_texture(args.target_image,
                                         gray=True, blur=True)
    patch_width = args.patch_width
    patch_height = args.patch_height

    new_t_height, new_t_width, dim = target_image.pixels.shape

    texture = Texture()
    texture.init_empty_texture(new_t_height, new_t_width, dim) 
    for step in range(args.iterations):
        if args.iterations == 1:
            alpha = .1
        else:
            alpha = .8 * step / (args.iterations-1) + .1
        patches, source_patch_cmap = \
            source_texture.create_patches(patch_height,
                                          patch_width,
                                          overlap=args.overlap_percent,
                                          cmap=source_corr_texture)
    
        texture = \
            Texture.create_from_source_transfer_target(patches,
                                                       source_patch_cmap,
                                                       target_corr_texture,
                                                       texture,
                                                       alpha)

        patch_width = int(patch_width * (1-args.patch_len_reduction))
        patch_height = int(patch_height * (1-args.patch_len_reduction))
        if patch_width == 0 or patch_height == 0:
            print "patch width or height reduced to 0, stopping iterations"
            break 
    texture.save_texture(args.output_file)
    
    return