图片操作scipy.ndimage.imread和scipy.misc.imresize

简介: 读图片str or file object--ndarray scipy.ndimage.imread(*args, **kwds) imread is deprecated! imread is deprecated in SciPy 1.

读图片str or file object--ndarray

scipy.ndimage.imread(*args, **kwds)

imread is deprecated! imread is deprecated in SciPy 1.0.0, and will be removed in 1.2.0. Use imageio.imread instead.

在1.2.0版本用imageio.imread代替

Read an image from a file as an array.从文件中把图片读成数组

This function is only available if Python Imaging Library (PIL) is installed.该功能只在安装了PIL情况下使用

 

Parameters:

fname : str or file object

The file name or file object to be read.

flatten : bool, optional

If True, flattens(扁平化) the color layers into a single gray-scale(灰度) layer.

将彩色层转化成单个灰度层

mode : str, optional

Mode to convert image to, e.g. 'RGB'. See the Notes for more details.

Returns:

imread : ndarray(多维数组)

The array obtained by reading the image.

Notes

imread uses the Python Imaging Library (PIL) to read an image. The following notes are from the PIL documentation.

mode can be one of the following strings:

·  ‘L’ (8-bit pixels, black and white)

·  ‘P’ (8-bit pixels, mapped to any other mode using a color palette)

·  ‘RGB’ (3x8-bit pixels, true color)

·  ‘RGBA’ (4x8-bit pixels, true color with transparency mask)

·  ‘CMYK’ (4x8-bit pixels, color separation)

·  ‘YCbCr’ (3x8-bit pixels, color video format)

·  ‘I’ (32-bit signed integer pixels)

·  ‘F’ (32-bit floating point pixels)

PIL also provides limited support for a few special modes, including ‘LA’ (‘L’ with alpha), ‘RGBX’ (true color with padding) and ‘RGBa’ (true color with premultiplied alpha).

When translating a color image to black and white (mode ‘L’, ‘I’ or ‘F’), the library uses the ITU-R 601-2 luma transform:

L = R * 299/1000 + G * 587/1000 + B * 114/1000

When flatten is True, the image is converted using mode ‘F’. When mode is not None and flatten is True, the image is first converted according to mode, and the result is then flattened using mode ‘F’.


调整图片尺寸ndarray--ndarray

scipy.misc.imresize(*args, **kwds)

imresize is deprecated! imresize is deprecated in SciPy 1.0.0, and will be removed in 1.2.0. Use skimage.transform.resize instead.

imresize功能将在1.2.0版本中,被skimage.transform.resize取代

Resize an image.调整图片大小

This function is only available if Python Imaging Library (PIL) is installed.该功能只在安装了PIL情况下使用

 

Warning

This function uses bytescale under the hood to rescale images to use the full (0, 255) range if mode is one of None, 'L', 'P', 'l'. It will also cast data for 2-D images to uint32 for mode=None (which is the default).

如果是None, 'L', 'P', 'l模式之一,该函数使用bytescale在底层调整图片,到(0, 255)全范围内。并在默认模式mode=None,计算二维图片的32位(uint32)数据。

 

Parameters:

arr : ndarray(多维数组)

The array of image to be resized.

size : int, float or tuple

·  int - Percentage of current size.

·  float - Fraction of current size.

·  tuple - Size of the output image (height, width).

interp : str, optional

Interpolation to use for re-sizing (‘nearest’(最近邻插值), ‘lanczos’(lanczos兰佐斯 interpolation), ‘bilinear(双线性插值)’, ‘bicubic’(双三次插值) or ‘cubic’(三次样条插值)).

mode : str, optional

The PIL image mode (‘P’, ‘L’, etc.) to convert arr before resizing. If mode=None (the default), 2-D images will be treated like mode='L', i.e. casting to long integer. For 3-D and 4-D arrays, mode will be set to'RGB' and 'RGBA' respectively.

Returns:

imresize : ndarray

The resized array of image.

See also

toimage

Implicitly used to convert arr according to mode.

scipy.ndimage.zoom

More generic implementation that does not use PIL.


目录
相关文章
|
2天前
|
监控 网络协议 算法
2026年起SSL证书有效期逐年缩短:企业如何避免“续期风暴”!
SSL证书有效期将从2026年起分三阶段逐步缩短至47天,人工续期难以为继。阿里云“WoSign SSL证书+自动化服务”,支持域名监控、自动托管、云产品/服务器一键部署及智能提醒,助力企业高效应对高频续期挑战。
8081 2
|
11天前
|
域名解析 人工智能 Linux
|
19天前
|
人工智能
Google 提示「所在地区不可用」?进不去 Antigravity 或 Gemini,先查账号这个设置
进不去 Antigravity 或 Gemini,提示所在地区不可用?三步查清 Google 账号关联地区、官方更正表单理由选法与改区注意事项。
10299 13
Google 提示「所在地区不可用」?进不去 Antigravity 或 Gemini,先查账号这个设置
|
5天前
|
人工智能 安全 网络安全
|
10天前
|
Linux API iOS开发
【DSH】DeepSeek Harness新手保姆教程(下载+安装+配置+使用,2026最新实测)
DeepSeek Harness(dsh)是 DeepSeek AI 开源的智能体框架,秉持“一切皆插件”理念,支持读文件、改代码、执行命令、处理表格等自动化任务;免费开源,兼容 Win/macOS,需配 API 密钥使用。(239字)
1554 5
|
9天前
|
云安全 数据采集 人工智能
|
17天前
|
人工智能 开发工具 开发者
2026最新codex下载安装保姆级使用教程(下载+安装+登录+使用,含所有历史版本)
Codex 是 OpenAI 推出的开源 AI 编程智能体,跑在本地终端和桌面客户端里,能读懂整个代码仓库,一句自然语言就能让它改代码、执行命令、跑测试、修 Bug,支持 Windows、macOS、Linux 三大平台。本文把 Codex下载、安装、登录、汉化、基础使用一次讲全,并整理了国内用户最常踩的坑,跟着做 10 分钟就能跑起来。
2706 8
|
9天前
|
Web App开发 缓存 安全
巨魔商店 TrollStore 安装教程(2026):免电脑在线安装与全机型安装器矩阵_iOS巨魔安装
巨魔商店(TrollStore)是iOS 14–17.0(特定版本)的永久签名工具,无需越狱,利用CoreTrust漏洞实现IPA签名长期有效,彻底告别7天重签。支持免电脑在线安装(TrollHelperOTA),适配多机型/系统组合,开源免费,安全可控。(239字)
2429 0