0

I want to resize image without loosing its original quality. for example I've 10 multiple 2D images in different size with white background. i want to make them in a same size 50*50. so that symbols should stay on same place and add extra white pixel outside. I'm using cv2.resize(template[1], (25, 45), 255) but my symbol scattered. I don't want to loose quality. I also seen this post resize image canvas to maintain square aspect ratio in Python, OpenCV but didn't find suitable

Jeru Luke
  • 20,118
  • 13
  • 80
  • 87
afaq
  • 109
  • 3
  • 11

1 Answers1

0

here is a good reference link for this issue and using the module I am posting about.

https://pypi.python.org/pypi/python-resize-image

but the syntax you are looking for is as follows:

resize_contain

this will resize the image so that it can fit in the specified area, keeping the ratio and without crop (same behavior as background-size: contain).

syntax example:

resize_contain(image, size, validate=True)

Resize the image so that it can fit in the specified area, keeping the ratio and without crop. It’s the same behavior as css background-size: contain property. A white a background border is created.

Resize the image to minimum so that it is contained in a 200x100 rectangle is the ratio between source and destination image.

from PIL import Image
from resizeimage import resizeimage

fd_img = open('test-image.jpeg', 'r')
img = Image.open(fd_img)
img = resizeimage.resize_contain(img, [200, 100])
img.save('test-image-contain.jpeg', img.format)
fd_img.close()