Skip to content

Resize and pad tensor to a fixed size while keeping the original apspect ratio with tensor operations in TensorFlow

License

Notifications You must be signed in to change notification settings

Kongsea/Resize-keeping-aspect-ratio

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Resize-to-fixed-size-keeping-aspect-ratio

Resize and pad images to a fixed size while keeping the original apspect ratio with tensor operations in TensorFlow

Please refer to this Blog.

1.resize images to a fixed size

Use tf.image.resize_images():

  • image = tf.image.resize_images(image, [new_height, new_width])

But the original aspect ratio of images was changed.

2.pad images to a fixed size, or resize to fixed size keeping the original aspect ratio

Use tf.image.pad_to_bounding_box:

  • image = tf.image.pad_to_bounding_box(image, offset_height, offset_width, new_height, new_width)

We need to calculate the offsets first and then pad images to the new sizes. However, the padding values is contrined to 0. We can modify the function to accept a parameter constant_values to set the padding values. But we still cannot pad different values for different channels respectively.

3.pad specific values to resize images

  • combine tf.image.resize_images() and tf.image.pad_to_bounding_box
  • split 3 channels and pad every channel respectively
  • concat 3 channels to restore images

About

Resize and pad tensor to a fixed size while keeping the original apspect ratio with tensor operations in TensorFlow

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages