Ejemplo n.º 1
0
def main():
    parser = argparse.ArgumentParser()

    parser.add_argument('-i', '--input_dir', action='store', type=str, default=INPUT_DIR,
                        help=f'Specify name of input image directory --in_path=path. Default: {INPUT_DIR}',
                        dest='input_dir')
    parser.add_argument('-od', '--output_dir', action='store', type=str, default=OUTPUT_DIR,
                        help=f'Specify name of output directory. Default: {OUTPUT_DIR}',
                        dest='output_dir')
    parser.add_argument('-o', '--output_file', action='store', type=str, default=OUTPUT_FILENAME,
                        help=f'Specify name of output file. Default: {OUTPUT_FILENAME}',
                        dest='output_file')
    parser.add_argument('-d', '--img_dim', action='store', type=int, default=IMG_DIMS,
                        help=f'Specify dimensions of square image to be created. Default: {IMG_DIMS}',
                        dest='img_dims')

    args = parser.parse_args()

    sequence_length = args.img_dims ** 2

    # current working directory
    cwd = os.getcwd()

    # fix problem from running from different directory
    if "scripts" in cwd:
        cwd = cwd.replace("scripts", "")

    dog_names = DOG_NAMES

    # probability of the first pixel (upper left corner) is each dog
    prior = PRIOR

    # transition matrix
    transition = [ROSIE_TRANSITION, CALLIE_TRANSITION, VENUS_TRANSITION, BEAR_TRANSITION, JAMIE_TRANSITION,
                  COOPER_TRANSITION, WINSTON_TRANSITION, BRUNO_TRANSITION, MAISY_TRANSITION, SPEEDY_TRANSITION,
                  BELLA_TRANSITION, BOOMER_TRANSITION, SASHA_TRANSITION]

    all_states = []

    # create State object for each dog in dog names
    for i, dog in enumerate(dog_names):
        new_state = State(id=i, name=dog)
        all_states.append(new_state)

    # run markov chain using states, prior probability vector, and transition matrix
    m = MarkovChain(states=all_states, prior=prior, transition=transition)
    sequence = m.run(sequence_length=sequence_length)

    # create output_path variable
    output_path = os.path.join(cwd, args.output_dir)
    output_path = os.path.join(output_path, args.output_file)

    # generate image from markov chain, input images, and output_path
    i = ImgGenerator(order=sequence, input_dir=os.path.join(cwd, args.input_dir), output_path=output_path,
                     num_rows=args.img_dims,
                     num_cols=args.img_dims, all_states=all_states)
    i.generate_img()