python调整屏幕缩放比例,Numpy调整大小/重新缩放图像

在Python中,可以使用OpenCV库的cv2.resize函数来调整图像的尺寸,同时保持原始图像的内容。通过指定目标尺寸和插值方法(如INTER_CUBIC),可以实现图像的缩放。原始图像作为Numpy数组读入,调整尺寸后的图像也会返回为Numpy数组。
摘要由CSDN通过智能技术生成

I would like to take an image and change the scale of the image, while it is a numpy array.

For example I have this image of a coca-cola bottle:

bottle-1

Which translates to a numpy array of shape (528, 203, 3) and I want to resize that to say the size of this second image:

bottle-2

Which has a shape of (140, 54, 3).

How do I change the size of the image to a certain shape while still maintaining the original image? Other answers suggest stripping every other or third row out, but what I want to do is basically shrink the image how you would via an image editor but in python code. Are there any libraries to do this in numpy/SciPy?

解决方案

Yeah, you can install opencv (this is a library used for image processing, and computer vision), and use the cv2.resize function. And for instance use:

import cv2

import numpy as np

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值