diff options
| author | Adam Harvey <adam@ahprojects.com> | 2018-12-23 01:37:03 +0100 |
|---|---|---|
| committer | Adam Harvey <adam@ahprojects.com> | 2018-12-23 01:37:03 +0100 |
| commit | 4452e02e8b04f3476273574a875bb60cfbb4568b (patch) | |
| tree | 3ffa44f9621b736250a8b94da14a187dc785c2fe /megapixels/datasets/commands/resize.py | |
| parent | 2a65f7a157bd4bace970cef73529867b0e0a374d (diff) | |
| parent | 5340bee951c18910fd764241945f1f136b5a22b4 (diff) | |
.
Diffstat (limited to 'megapixels/datasets/commands/resize.py')
| -rw-r--r-- | megapixels/datasets/commands/resize.py | 81 |
1 files changed, 0 insertions, 81 deletions
diff --git a/megapixels/datasets/commands/resize.py b/megapixels/datasets/commands/resize.py deleted file mode 100644 index 5e2d31aa..00000000 --- a/megapixels/datasets/commands/resize.py +++ /dev/null @@ -1,81 +0,0 @@ -""" -Crop images to prepare for training -""" - -import click - -from app.settings import types -from app.utils import click_utils -from app.settings import app_cfg as cfg - -""" -Filter Q-Down Q-Up Speed -NEAREST ⭐⭐⭐⭐⭐ -BOX ⭐ ⭐⭐⭐⭐ -BILINEAR ⭐ ⭐ ⭐⭐⭐ -HAMMING ⭐⭐ ⭐⭐⭐ -BICUBIC ⭐⭐⭐ ⭐⭐⭐ ⭐⭐ -LANCZOS ⭐⭐⭐⭐ ⭐⭐⭐⭐ ⭐ -""" - -@click.command() -@click.option('-i', '--input', 'opt_dir_in', required=True, - help='Input directory') -@click.option('-o', '--output', 'opt_dir_out', required=True, - help='Output directory') -@click.option('-e', '--ext', 'opt_glob_ext', - default='jpg', type=click.Choice(['jpg', 'png']), - help='File glob ext') -@click.option('--size', 'opt_size', - type=(int, int), default=(256, 256), - help='Output image size (square)') -@click.option('--method', 'opt_scale_method', - type=click.Choice(['LANCZOS', 'BICUBIC', 'HAMMING', 'BILINEAR', 'BOX', 'NEAREST']), - default='LANCZOS', - help='Scaling method to use') -@click.pass_context -def cli(ctx, opt_dir_in, opt_dir_out, opt_glob_ext, opt_size, opt_scale_method): - """Crop, mirror images""" - - import os - from os.path import join - from pathlib import Path - from glob import glob - from tqdm import tqdm - from PIL import Image, ImageOps, ImageFilter - from app.utils import logger_utils, file_utils, im_utils - - # ------------------------------------------------- - # init - - log = logger_utils.Logger.getLogger() - - methods = { - 'LANCZOS': Image.LANCZOS, - 'BICUBIC': Image.BICUBIC, - 'HAMMING': Image.HAMMING, - 'BILINEAR': Image.BILINEAR, - 'BOX': Image.BOX, - 'NEAREST': Image.NEAREST - } - - # ------------------------------------------------- - # process here - - # get list of files to process - fp_ims = glob(join(opt_dir_in, '*.{}'.format(opt_glob_ext))) - log.info('processing {:,} files'.format(len(fp_ims))) - - # set scale method - scale_method = methods[opt_scale_method] - - # ensure output dir exists - file_utils.mkdirs(opt_dir_out) - - # resize and save images - for fp_im in tqdm(fp_ims): - im = Image.open(fp_im) - im = ImageOps.fit(im, opt_size, method=scale_method, centering=(0.5, 0.5)) - fp_out = join(opt_dir_out, Path(fp_im).name) - im.save(fp_out) - |
