python调整图片大小reshape,Scipy旋转和缩放图像而不更改其尺寸

本文介绍如何使用Python的scipy库对图像进行旋转和缩放操作,同时保持图片尺寸不变。通过设置scipy.ndimage.rotate的reshape参数为False来避免尺寸变化,并提供了一个名为clipped_zoom的函数,用于在缩放图像时仅保留边界内的部分。
摘要由CSDN通过智能技术生成

For my neural network I want to augment my training data by adding small random rotations and zooms to my images. The issue I am having is that scipy is changing the size of my images when it applies the rotations and zooms. I need to to just clip the edges if part of the image goes out of bounds. All of my images must be the same size.

def loadImageData(img, distort = False):

c, fn = img

img = scipy.ndimage.imread(fn, True)

if distort:

img = scipy.ndimage.zoom(img, 1 + 0.05 * rnd(), mode = 'constant')

img = scipy.ndimage.rotate(img, 10 * rnd(), mode = 'constant')

print(img.shape)

img = img - np.min(img)

img = img / np.max(img)

img = np.reshape(img, (1, *img.shape))

y = np.zeros(ncats)

y[c] = 1

return (img, y)

解决方案<

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值