Coder Social home page Coder Social logo

kongsea / resize-keeping-aspect-ratio Goto Github PK

View Code? Open in Web Editor NEW
4.0 2.0 1.0 129 KB

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

License: MIT License

Python 100.00%
augmentation image-processing resize-images tensorflow

resize-keeping-aspect-ratio's Introduction

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

resize-keeping-aspect-ratio's People

Contributors

kongsea avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

amirunpri2018

resize-keeping-aspect-ratio's Issues

Logo Proposal

Greetings, @Kongsea

I'm an open source enthusiast, and just noticed you've just started this project!
I wanted to collaborate! I'd like to propose a logo for free
If thats something that might interest you, let me know!

Graphic Designer - Luigi.
Cheers!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.