当前位置:网站首页>Use tf.image.resize() and tf.image.resize_with_pad() to resize images
Use tf.image.resize() and tf.image.resize_with_pad() to resize images
2022-08-03 22:54:00 【Erosion_ww】
tf.image.resize和tf.image.resize_with_pad使用方法
tf.image.resize()
作用
~~~~ Resize the image using the specified method.
~~~~ If the original aspect ratio is different from the size,The resized image will be distorted. to avoid distortion,可用tf.image.resize_with_pad()
参数
tf.image.resize(
images, # 形状 [batch, height, width, channels] 的 4-D tensor or shape [height, width, channels] 的 3-D 张量.
size, # 2 个元素的一维 int32 张量:new_height,new_width. 图像的新尺寸.
method=ResizeMethod.BILINEAR, # 一个 image.ResizeMethod,or the equivalent string. The default is bilinear.
preserve_aspect_ratio=False, # Whether to preserve the aspect ratio.
# true,The image will be resized to fit the size,While preserving the aspect ratio of the original image.
# If the size is larger than the current size of the image,则放大图像. 默认为false.
antialias=False, # Whether to use when downsampling the imageanti-aliasing filter.
name=None # 此操作的名称(可选).
)
~~~~ 其中,Image.ResizeMethod()的选项有:
~~~~ • bilinear: 双线性插值.若antialisa为true,Then it becomes the radius when downsampling1的hat/tent filter.
~~~~ • lanczos3: Lanczos kernel with radius 3.High quality practical filter,But there may be someringing,Especially on composite images.
~~~~ • lanzos5:Lanczos kernel with radius 5.Very high quality filter,But there may be stronger onesringing.
~~~~ • bicubic:三次插值.相当于Catmull-Rom kernel,与lanczos3kernel相比较,质量相当好,速度更快,Especially when upsampling.
~~~~ • gaussian:Gaussian kernel with radius 3, sigma = 1.5 / 3.0.
~~~~ • nearest:最近邻插值. When used with nearest neighbor interpolation,antialias无效.
~~~~ • area:Antialiased resampling using region interpolation. When used with area interpolation,antialias没有效果.
~~~~ •mitchellcubic:Mitchell-Netravali Cubic non-interpolating filter. For composite images(Especially those images that lack proper pre-filtering),ringing比Cubic interpolant of Keys少,Not as sharp.
返回值
~~~~ If images was 4-D, a 4-D float Tensor of shape [batch, new_height, new_width, channels].
~~~~ If images was 3-D, a 3-D float Tensor of shape [new_height, new_width, channels].
例子
import tensorflow as tf # 导入tensorflow
img_path ='C:\\Users\\xxx\\.keras\\datasets\\flower_photos\\roses\\6158504080_b844a9ae05.jpg' # 输入图片路径
img_raw = tf.io.read_file(img_path) # 读取图片内容,返回值时string的tensor
img_tensor = tf.image.decode_image(img_raw) # 对输入的string的tensor进行解码
print(img_tensor.shape) # Enter the decoded image shape
print(img_tensor.dtype) # Enter the decoded image representation type
img_final = tf.image.resize(img_tensor, [192, 192]) # 调整图像大小
print(img_final.shape) # Enter the resized image size
(333, 500, 3)
<dtype: 'uint8'>
(192, 192, 3)
tf.image.resize_with_pad()
作用
~~~~ Resize and fill the image to the target width and height.
~~~~ No distortion by keeping the aspect ratio the same,Resize the image to the target width and height. If the target size does not match the image size,will resize the image,It is then padded with zeros to match the requested dimensions.
参数
tf.image.resize_with_pad(
image, # 形状 [batch, height, width, channels] 的 4-D tensor or shape [height, width, channels] 的 3-D 张量.
target_height, # 目标高度
target_width, # 目标宽度
method=ResizeMethod.BILINEAR, # The method used to resize the image. 见 image.resize()
antialias=False # Whether to use antialiasing when resizing. 参见“image.resize()”.
)
返回值
~~~~ Resized and padded image.
~~~~ If images was 4-D, a 4-D float Tensor of shape [batch, new_height, new_width, channels].
~~~~ If images was 3-D, a 3-D float Tensor of shape [new_height, new_width, channels].
主要参考:
tf.image.resize | TensorFlow Core v2.9.1 (google.cn)
tf.image.resize_with_pad | TensorFlow Core v2.9.1 (google.cn)
边栏推荐
- 走迷宫 BFS
- 完全二叉树问题
- Codeup brushing notes - simple simulation
- 一个函数有多少种调用方式?
- 获国际权威认可 | 云扩科技入选《RPA全球市场格局报告,Q3 2022》
- Teach a Man How to Fish - How to Query the Properties of Any SAP UI5 Control by Yourself Documentation and Technical Implementation Details Demo
- 静态文件快速建站
- LabVIEW代码生成错误 61056
- Conditional Statements for Shell Programming
- for loop exercises
猜你喜欢

Interpretation of ML: A case of global interpretation/local interpretation of EBC model interpretability based on titanic titanic rescued binary prediction data set using interpret

rosbridge-WSL2 && carla-win11

Embedded systems: overview

FinClip,助长智能电视更多想象空间

AOSP CameraLatencyHistogram的原理与使用

Zilliz 2023 Fall Campus Recruitment Officially Launched!

First domestic open source framework 】 【 general cloud computing framework, any program can be made into cloud computing.

Adobe是什么?

【bug】汇总Elipse项目中代码中文乱码解决方法!

On the Qixi Festival of 2022, I will offer 7 exquisite confession codes, and at the same time teach you to quickly change the source code for your own use
随机推荐
[2022安恒夏令营] 5个小题
What is memoization and what is it good for?
On the Qixi Festival of 2022, I will offer 7 exquisite confession codes, and at the same time teach you to quickly change the source code for your own use
Click the icon in Canvas App to generate PDF and save it to Dataverse
start with connect by implements recursive query
Binary search tree to solve the fallen leaves problem
websocket多线程发送消息报错TEXT_PARTIAL_WRITING--自旋锁替换synchronized独占锁的使用案例
BMN: Boundary-Matching Network for Temporal Action Proposal Generation Reading Notes
Bytebase database schema change management tool
举一个 web worker 的例子
Scala基础【正则表达式、框架式开发原则】
utlis 线程池
Optimize the query (work in progress)
noip初赛
完全二叉树问题
使用tf.image.resize() 和tf.image.resize_with_pad()调整图像大小
七夕活动浪漫上线,别让网络拖慢和小姐姐的开黑时间
软件测试内卷严重,如何提升自己的竞争力呢?
3D 语义分割——2DPASS
Network basic learning series four (network layer, data link layer and some other important protocols or technologies)