import tensorflow as tf
def TF_image_Resize(path_to_images, method = 0, height =224, width =224):
"""
using tensorflow to preprocess image data
params: method 0: Bilinear interpolation
method 1: Nearset neighbor interploation
method 2: Bicubic interpolation
method 3: Area interpolation
"""
if not tf.gfile.Exists(path_to_images):
print("path to images does not exist")
else:
#search all jpeg files
path_img_list = files = os.listdir(path_to_images)
#path_img_list = tf.gfile.Glob(os.path.join(path_to_images, '*.jpg'))
print(path_img_list)
total_img = []
for file in path_img_list:
print("the name of jpeg file:", file)
img_jpg = tf.gfile.FastGFile(path_to_images +'/' +file,'rb').read()
img_decode = tf.image.decode_jpeg(img_jpg)
img_data = tf.image.convert_image_dtype(img_decode, dtype = tf.float32)
img_data = tf.image.resize_images(img_data, height, width, method)
total_img.append(img_data)
print(len(total_img))
return total_img
def TF_image_Resize2(path_to_images, height =224, width =224, choice = True):
"""
using tensorflow to preprocess image data
params: method 0: Bilinear interpolation
method 1: Nearset neighbor interploation
method 2: Bicubic interpolation
method 3: Area interpolation
"""
if not tf.gfile.Exists(path_to_images):
print("path to images does not exist")
else:
#search all jpeg files
path_img_list = files = os.listdir(path_to_images)
#path_img_list = tf.gfile.Glob(os.path.join(path_to_images, '*.jpg'))
print(path_img_list)
total_img = []
for file in path_img_list:
#print("the name of jpeg file:", file)
img_jpg = tf.gfile.FastGFile(path_to_images +'/' +file,'rb').read()
img_decode = tf.image.decode_jpeg(img_jpg)
img_data = tf.image.convert_image_dtype(img_decode, dtype = tf.float32)
if choice:
img_data = tf.image.resize_image_with_crop_or_pad(img_data, height, width)
total_img.append(img_data)
else:
img_data = tf.image.central_crop(img_data, 0.5)
total_img.append(img_data)
print(len(total_img))
return total_img