1234567891011121314151617181920212223242526272829303132333435 |
- import argparse
- import os
- from PIL import Image
- from skimage import exposure, img_as_float, io
- from tqdm import tqdm
- def work(img_path, img_dir):
- if img_dir == '':
- # 读取图像
- img_org = Image.open(img_path)
- # 转换为 skimage 可操作的格式
- img = img_as_float(img_org)
- img_bright = exposure.adjust_gamma(img, 0.5)
- img_dark = exposure.adjust_gamma(img, 1.5)
- io.imsave(str(img_path)[0:-4] + '_dark.png', img_dark)
- io.imsave(str(img_path)[0:-4] + '_bright.png', img_bright)
- else:
- img_list = os.listdir(img_dir)
- for img_p in tqdm(img_list):
- img_p = img_dir + '/' + img_p
- img = Image.open(img_p)
- img_bright = exposure.adjust_gamma(img, 0.5)
- img_dark = exposure.adjust_gamma(img, 1.5)
- io.imsave(img_dir + '/' + str(img_p).split('.')[0] + '_dark.png', img_dark)
- io.imsave(img_dir + '/' + str(img_p).split('.')[0] + '_bright.png', img_bright)
- if __name__ == '__main__':
- parser = argparse.ArgumentParser()
- parser.add_argument('--img_dir', type=str, default='')
- parser.add_argument('--img_path', type=str, default='./img/idcard_0_02.png')
- args = parser.parse_args()
- work(args.img_path, args.img_dir)
|