代码拉取完成,页面将自动刷新
# -*- coding: utf-8 -*-
"""
Created on Sun Feb 24 16:31:16 2019
@author: wmy
"""
import os
import numpy as np
import matplotlib.pyplot as plt
from PIL import Image
import tensorflow as tf
original_images_path = r'.\datasets\OriginalImages'
color_images_path = r'.\datasets\ColorImages'
grayscale_images_path = r'.\datasets\GrayscaleImages'
combined_images_path = r'.\datasets\CombinedImages'
resize_height = 256
resize_weidth = 256
def find_images(path):
result = []
for filename in os.listdir(path):
_, ext = os.path.splitext(filename.lower())
if ext == ".jpg" or ext == ".png":
result.append(os.path.join(path, filename))
pass
pass
result.sort()
return result
if __name__ == '__main__':
search_result = find_images(original_images_path)
for image_path in search_result:
img_name = image_path[len(original_images_path):]
img = Image.open(image_path)
img_color = img.resize((resize_weidth, resize_height), Image.ANTIALIAS)
img_color.save(color_images_path + img_name, quality=95)
print("Info: image '" + color_images_path + img_name + "' saved.")
img_gray = img_color.convert('L')
img_gray = img_gray.convert('RGB')
img_gray.save(grayscale_images_path + img_name, quality=95)
print("Info: image '" + grayscale_images_path + img_name + "' saved.")
combined_image = Image.new('RGB', (resize_weidth*2, resize_height))
combined_image.paste(img_color, (0, 0, resize_weidth, resize_height))
combined_image.paste(img_gray, (resize_weidth, 0, resize_weidth*2, resize_height))
combined_image.save(combined_images_path + img_name, quality=95)
print("Info: image '" + combined_images_path + img_name + "' saved.")
pass
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。