# Best way to fill an image placed into a larger box without creating artificial edges?

If you are training a neural net for a bunch of images of different size, and you have to put them all in a same-size enclosing box for input to the neural net, what's the best way to fill the background, if at all, where the inserted image is not covering the box?

It's basically the flip side of these questions:

• The question isn't clear. Could you try to explain it in a clearer fashion? – Royi May 26 '18 at 6:25
• @Royi: If you are training a neural net for a bunch of images of different size, and you have to put them all in a same-size enclosing box for input to the neural net, what's the best way to fill the background, if at all, where the inserted image is not covering the box? – Lars Ericson May 27 '18 at 1:38
• This is a much clearer explanation. You should rewrite the question in that spirit and I will be able to answer. – Royi May 27 '18 at 4:07

## 1 Answer

I think I found the appropriate answer in this patch of code from Google Tensorflow for Poets 2. It does what I needed to do at the moment it needed to get done. The variables input_height and input_width are the destination sizes, not the source sizes:

  float_caster = tf.cast(image_reader, tf.float32)
dims_expander = tf.expand_dims(float_caster, 0)
resized = tf.image.resize_bilinear(dims_expander, [input_height, input_width])
normalized = tf.divide(tf.subtract(resized, [input_mean]), [input_std])