原图像
图像加载
原码:
import matplotlib.pyplot as plt
import tensorflow as tf
image_path = "/xxx/timg.jpeg"
image_data = tf.gfile.FastGFile(image_path,'r').read()
with tf.Session() as sess:
image_data = tf.image.decode_jpeg(image_data)
print(image_data.eval())
打印出的图像像素点
[[[254 254 254]
[254 254 254]
[254 254 254]
...,
[254 254 254]
[254 254 254]
[254 254 254]]
[[254 254 254]
[254 254 254]
[254 254 254]
...,
[254 254 254]
[254 254 254]
[254 254 254]]
[[254 254 254]
[254 254 254]
[254 254 254]
...,
图像修剪
resize_image = tf.image.resize_images(image_data,[50,50],method=1)
plt.imshow(resize_image.eval())
plt.show()
resize_image = tf.image.resize_image_with_crop_or_pad(image_data,400,400)
plt.imshow(resize_image.eval())
plt.show()
resize_image = tf.image.resize_image_with_crop_or_pad(image_data,600,600)
plt.imshow(resize_image.eval())
plt.show()
图像翻转
resize_image = tf.image.flip_left_right(image_data)
plt.imshow(resize_image.eval())
plt.show()
resize_image = tf.image.flip_up_down(image_data)
plt.imshow(resize_image.eval())
plt.show()
图像亮度调整
resize_image = tf.image.adjust_brightness(image_data,-0.5)
plt.imshow(resize_image.eval())
plt.show()
resize_image = tf.image.adjust_brightness(image_data,+0.5)
plt.imshow(resize_image.eval())
plt.show()
图像对比度调整
resize_image = tf.image.adjust_contrast(image_data,3)
plt.imshow(resize_image.eval())
plt.show()
resize_image = tf.image.adjust_contrast(image_data,-3)
plt.imshow(resize_image.eval())
plt.show()
图像饱和度调整
resize_image = tf.image.adjust_saturation(image_data,-3)
plt.imshow(resize_image.eval())
plt.show()
resize_image = tf.image.adjust_saturation(image_data,3)
plt.imshow(resize_image.eval())
plt.show()
图像存储
resize_image = tf.image.adjust_saturation(image_data,3)
encode_image = tf.image.encode_jpeg(resize_image)
with tf.gfile.GFile("/home/abig/vscode/project1/save.jpeg","wb") as f:
f.write(encode_image.eval())
存储后的图片