jdhao / jdhao.github.io

My personal blog: https://jdhao.github.io/
24 stars 6 forks source link

2017/11/06/resize-image-to-square-with-padding/ #54

Open utterances-bot opened 2 years ago

utterances-bot commented 2 years ago

How to Resize, Pad Image to Square Shape and Keep Its Aspect Ratio in Python - jdhao's digital space

When we are using convolutional neural networks, most of the time, we need to fix the input image size to feed it to the network. The usual practice is to resize the input image to the given size (the image aspect ratio is no longer kept) and then crop a fixed size patch randomly from the resized image. This practice may work well for image classification where fine details may not be necessary. But for Image retrieval, we want to keep the image aspect ration unchanged. In this post, I will summarize ways to resize an image to square shape with padding and keep its aspect ratio.

https://jdhao.github.io/2017/11/06/resize-image-to-square-with-padding/

jhgit0219 commented 2 years ago

Hello jdhao,

Found this blog while looking for reference for image resizing methods. The OpenCV method works great, but I did have to modify the new_size variable as a Kotlin implementation. As you mentioned in the comments, it's in a (width, height) format, but isn't it still in a (height, width) format since it uses the order of the old_size variable which is in (height, width) format as reference? Would just like to point that out if that's something different from the python implementation of OpenCV.

Best regards!