def resize(images, size=(100, 100)):
""" Function to resize the number of pixels in an image.
To achieve a standarized pixel number accros different images, it is
desirable to make every picture of the same pixel size. By using an OpenCV
method we increase or reduce the number of pixels accordingly.
"""
images_norm = []
for image in images:
is_color = len(image.shape) == 3
if is_color:
image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
# using different OpenCV method if enlarging or shrinking
if image.shape < size:
image_norm = cv2.resize(image, size, interpolation=cv2.INTER_AREA)
else:
image_norm = cv2.resize(image, size, interpolation=cv2.INTER_CUBIC)
images_norm.append(image_norm)
return images_norm
operations.py 文件源码
python
阅读 26
收藏 0
点赞 0
评论 0
评论列表
文章目录