scipy.misc.imresize()的替代方法 [英] Alternative to scipy.misc.imresize()

查看:3511
本文介绍了scipy.misc.imresize()的替代方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用仍然使用scipy.misc.imresize()的旧脚本,该脚本不仅已弃用,而且已从scipy中完全删除.相反,开发人员建议使用numpy.array(Image.fromarray(arr).resize())skimage.transform.resize().

I want to use an old script which still uses scipy.misc.imresize() which is not only deprevated but removed entirely from scipy. Instead the devs recommend to use either numpy.array(Image.fromarray(arr).resize()) or skimage.transform.resize().

不再起作用的确切代码行是这样的:

The exact code line that is no longer working is this:

new_image = scipy.misc.imresize(old_image, 0.99999, interp = 'cubic')

不幸的是,我现在不确定确切的功能了.恐怕如果我开始使用较旧的scipy版本,我的较新脚本将停止工作. 我一直在使用它作为模糊滤镜的一部分.如何使numpy.array(Image.fromarray(arr).resize())skimage.transform.resize()执行与上述代码行相同的操作?很抱歉,我提供的信息不足.

Unfortunately I am not exactly sure anymore what it does exactly. I'm afraid that if I start playing with older scipy versions, my newer scripts will stop working. I have been using it as part of a blurr filter. How do I make numpy.array(Image.fromarray(arr).resize()) or skimage.transform.resize() perform the same action as the above code line? Sorry for the lack of information I provide.

修改

我已经能够确定此行的用途.它将由此转换图像数组:

I have been able to determine what this line does. It converts an image array from this:

[[[0.38332759 0.38332759 0.38332759]
  [0.38770704 0.38770704 0.38770704]
  [0.38491378 0.38491378 0.38491378]
  ...

对此:

[[[57 57 57]
  [59 59 59]
  [58 58 58]
  ...

Edit2

当我使用詹森斯方法时,输出为:

When I use jhansens approach the output is this:

[[[ 97  97  97]
  [ 98  98  98]
  [ 98  98  98]
  ...

我不明白scipy.misc.imresize的作用.

推荐答案

您可以查找源代码.简而言之,使用枕头(

You can lookup the documentation and the source code of the deprecated function. In short, using Pillow (Image.resize) you can do:

im = Image.fromarray(old_image)
size = tuple((np.array(im.size) * 0.99999).astype(int))
new_image = np.array(im.resize(size, PIL.Image.BICUBIC))

使用 skimage (

With skimage (skimage.transform.resize) you should get the same with:

size = (np.array(old_image.size) * 0.99999).astype(int)
new_image  = skimage.transform.resize(old_image, size, order=3)

这篇关于scipy.misc.imresize()的替代方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆