Ejemplo n.º 1
0
def merge_files(src_directory: str,
                output_shape: Tuple[int, int, int] = (1200, 1600, 3),
                input_shape: Tuple[int, int] = (200, 200),
                pocket: Tuple[int, int] = (100, 100),
                output_filename: str = 'out.png'):

    container = np.zeros(output_shape)
    images = os.listdir(src_directory)
    vertical_step, horizontal_step = input_shape
    vertical_pocket, horizontal_pocket = pocket

    with cb(f'Merging {src_directory}: ', max=len(images)) as bar:
        for image in images:
            row, column = parse_name(image)
            start_row = row * (vertical_step - vertical_pocket)
            start_column = column * (horizontal_step - horizontal_pocket)
            end_row = start_row + vertical_step
            end_column = start_column + horizontal_step
            container[start_row:end_row, start_column:end_column] = np.array(
                Image.open(os.path.join(src_directory, image)))
            bar.next()

    container = container.astype('uint8')
    img = Image.fromarray(container)
    img.save(output_filename)
Ejemplo n.º 2
0
def merge_directories(directories: list[str],
                      output_shape: Tuple[int, int, int] = (1200, 1600, 3),
                      input_shape: Tuple[int, int] = (200, 200),
                      pocket: Tuple[int, int] = (100, 100),
                      output_filename='out.png'):

    with cb('Merging', max=len(directories)) as bar:
        for directory in directories:
            merge_files(directory, output_shape, input_shape, pocket,
                        f'{directory}_{output_filename}')
            bar.next()
Ejemplo n.º 3
0
def split_images_in_directory(directory_name: str,
                              output_shape: Tuple[int, int] = (200, 200),
                              pocket: Tuple[int, int] = (100, 100),
                              extension: str = '.png'):
    if not os.path.isdir(directory_name):
        raise NotADirectoryError()
    files = os.listdir(directory_name)
    with cb('Splitting', max=len(files)) as bar:
        for f in files:
            file_path = os.path.join(directory_name, f)
            if not os.path.isdir(file_path):
                dir_name = f'out_{directory_name}'
                if not os.path.exists(dir_name):
                    os.makedirs(dir_name)
                split_image(file_path, dir_name, output_shape, pocket,
                            extension)
            bar.next()
Ejemplo n.º 4
0
def make_predictions_for_images_in_directory(model: tf.keras.Model,
                                             input_directory: str,
                                             output_directory: str = 'out'):
    if not os.path.exists(input_directory):
        raise ValueError('Directory does not exists')
    if not os.path.isdir(input_directory):
        raise NotADirectoryError()
    if not os.path.exists(output_directory):
        os.makedirs(output_directory)

    # Loading data
    images = os.listdir(input_directory)
    with cb('Predicting', max=len(images)) as b:
        for image in images:
            make_prediction_for_image(
                model, os.path.join(input_directory, image),
                os.path.join(output_directory,
                             f"{os.path.splitext(image)[0]}_prediction.png"))
            b.next()
    print('Finished!')
Ejemplo n.º 5
0
def blur_dir(dir, parameter=2):
    files = os.listdir(dir)
    with cb('Bluring', max=len(files)) as bar:
        for file in files:
            blur_file(os.path.join(dir, file), parameter)
            bar.next()
Ejemplo n.º 6
0
def remove_alpha_dir(dir, threshold=125):
    files = os.listdir(dir)
    with cb('Removeing alpha', max=len(files)) as bar:
        for file in files:
            remove_alpha_file(os.path.join(dir, file), threshold)
            bar.next()