I want to resize image without loosing its original quality. for example I've 10 multiple 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
Asked
Active
Viewed 940 times
0
1 Answers
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()

Nicholas Shaffer
- 80
- 13
-
I wanna do it via python. β afaq Oct 19 '17 at 21:14
-
please allow me some time to research this issue and I will post again β Nicholas Shaffer Oct 19 '17 at 21:16
-
if you have never used PIP, you will need to install this module for python using PIP and an easy reference for PIP usage can be found here... https://packaging.python.org/tutorials/installing-packages/ β Nicholas Shaffer Oct 19 '17 at 21:23