<jupyter_start><jupyter_text>resize(缩放) crop(裁剪) flip(翻转) brightness & contrast(改变光照和对比度)<jupyter_code>import numpy as np
import tensorflow.compat.v1 as tf
from matplotlib.pyplot import imshow

tf.compat.v1.disable_eager_execution()
name = "./test.jpg"
img_string = tf.read_file(name)
image_decoded = tf.image.decode_image(img_string)
sess = tf.Session()
image_decoded_val = sess.run(image_decoded)
print(image_decoded_val.shape)

imshow(image_decoded_val)
# reesize
# tf.image.resize_area
# tf.image.resize_bicubic
# tf.image.resize_nearest_neighbor

name = "./test.jpg"
img_string = tf.read_file(name)
image_decoded = tf.image.decode_image(img_string)
image_decoded = tf.reshape(image_decoded, [1, 1440, 2560, 3])
resize_img = tf.image.resize_bicubic(image_decoded, [2880, 5120])

sess = tf.Session()
image_decoded_val = sess.run(resize_img)
image_decoded_val = image_decoded_val.reshape((2880, 5120, 3))
image_decoded_val = np.asarray(image_decoded_val, np.uint8)
print(image_decoded_val.shape)

imshow(image_decoded_val)
# crop
# tf.image.pad_to_bounding_box
# tf.image.crop_to_bounding_box
# tf.random_crop

name = "./test.jpg"
img_string = tf.read_file(name)
image_decoded = tf.image.decode_image(img_string)
image_decoded = tf.reshape(image_decoded, [1, 1440, 2560, 3])

# 2000x3000 画布上,把图片放在200x300位置上
padded_img = tf.image.pad_to_bounding_box(
    image_decoded,
    200,300,2000,3000
)

sess = tf.Session()
image_decoded_val = sess.run(padded_img)
image_decoded_val = image_decoded_val.reshape((2000,3000, 3))
image_decoded_val = np.asarray(image_decoded_val, np.uint8)
print(image_decoded_val.shape)

imshow(image_decoded_val)
# flip
# tf.image.flip_up_down
# tf.image.flip_left_right
# tf.image.random_flip_up_down
# tf.image.random_flip_left_right

name = "./test.jpg"
img_string = tf.read_file(name)
image_decoded = tf.image.decode_image(img_string)
image_decoded = tf.reshape(image_decoded, [1, 1440, 2560, 3])

flipped_img = tf.image.flip_up_down(image_decoded)

sess = tf.Session()
image_decoded_val = sess.run(flipped_img)
image_decoded_val = image_decoded_val.reshape((1440,2560, 3))
image_decoded_val = np.asarray(image_decoded_val, np.uint8)
print(image_decoded_val.shape)

imshow(image_decoded_val)
# brightness
# tf.image.adjust_brightness
# tf.image.random_brightness
# tf.image.adjust_contrast
# tf.image.random_contrast

name = "./test.jpg"
img_string = tf.read_file(name)
image_decoded = tf.image.decode_image(img_string)
image_decoded = tf.reshape(image_decoded, [1, 1440, 2560, 3])

new_img = tf.image.adjust_brightness(image_decoded, 0.5)

sess = tf.Session()
image_decoded_val = sess.run(new_img)
image_decoded_val = image_decoded_val.reshape((1440,2560, 3))
image_decoded_val = np.asarray(image_decoded_val, np.uint8)
print(image_decoded_val.shape)

imshow(image_decoded_val)<jupyter_output>(1440, 2560, 3)
{'fraction_non_alphanumeric': 0.12050739957716702, 'fraction_numerical': 0.045454545454545456, 'mean_word_length': 7.088319088319088, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '37873', 'license': 'Apache-2.0', 'n_tokens_mistral': 1274, 'n_tokens_neox': 1179, 'n_words': 161, 'path': 'DeepLearning/jupyter notebook file/Image enhancement.ipynb', 'repo_name': 'bufanx/ML-Learning', 'size': '2838'}