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

查看:46
本文介绍了替代 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

当我使用 jhansens 方法时,输出是这样的:

When I use jhansens approach the output is this:

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

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

推荐答案

您可以查找 文档不推荐使用的函数的源代码.简而言之,使用 Pillow (Image.resize) 你可以这样做:

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 (skimage.transform.resize) 你应该得到相同的:

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天全站免登陆