原图像
图像加载
原码:
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())
存储后的图片
本文介绍如何使用TensorFlow进行图像处理,包括加载、修剪、翻转、调整亮度、对比度和饱和度等操作,并展示了如何将处理后的图像保存。
图像预处理&spm=1001.2101.3001.5002&articleId=79080565&d=1&t=3&u=52050856160a45b0ab5c4ecaf15f1804)
3万+

被折叠的 条评论
为什么被折叠?



