一、图片的放大缩小
在使用TensorFlow进行图片的放大缩小时,有三种方式:
1、tf.image.resize_nearest_neighbor():临界点插值
2、tf.image.resize_bilinear():双线性插值
3、tf.image.resize_bicubic():双立方插值算法
下面是示例代码:
# encoding:utf-8
# 使用TensorFlow进行图片的放缩
import tensorflow as tf
import cv2
import numpy as np
# 读取图片
img = cv2.imread("1.jpg")
# 显示原始图片
cv2.imshow("resource", img)
h, w, depth = img.shape
img = np.expand_dims(img, 0)
# 临界点插值
nn_image = tf.image.resize_nearest_neighbor(img, size=[h+100, w+100])
nn_image = tf.squeeze(nn_image)
with tf.Session() as sess:
# 运行 'init' op
nn_image = sess.run(nn_image)
nn_image = np.uint8(nn_image)
# 双线性插值
bi_image = tf.image.resize_bilinear(img, size=[h+100, w+100])
bi_image = tf.squeeze(bi_image)
with tf.Session() as sess: