gpt4 book ai didi

python - 使用 tensorflow 删除图像的最后一行和最后一列

转载 作者:太空宇宙 更新时间:2023-11-04 09:38:09 25 4
gpt4 key购买 nike

我想根据给定的所需高度和宽度删除图像的最后一行和最后一列。

例如,假设我有一张尺寸为 351x572x3 的图像。

我想要尺寸为 350x550x3 的图像,即我想删除图像的最后一行和最后 22 列。

我如何使用 tensorflow 实现这一目标?

预先知道图片的desired_width和desired_height

代码:

def parse_fn(filename,desired_height,desired_width):
"""Decode the bmp image from the filename and convert to [0, 1]."""
image_string = tf.read_file(filename)
image_decoded = tf.image.decode_bmp(image_string)
# This will convert to float values in [0, 1]
image = tf.image.convert_image_dtype(image_decoded, tf.float32)

# I want to do convert the image to desired width and height here

return image

提前致谢

最佳答案

tf.image.crop_to_bounding_box(
image,
offset_height,
offset_width,
target_height,
target_width
)

对于你的情况,

image = tf.image.crop_to_bounding_box(image,0,0,desired_height,desired_width)

link to the doc

关于python - 使用 tensorflow 删除图像的最后一行和最后一列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52883624/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com