图片操作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.


目录
相关文章
|
云安全 安全 网络安全
|
7天前
|
JavaScript 安全 前端开发
Nodejs Brotli decoder 代码执行漏洞 (CVE-2026-111497)10629
Node.js发布安全更新修复Brotli解码器高危RCE漏洞(CVE-2026-111497),建议受影响版本用户立即升级。
2014 1
|
15天前
|
JSON 程序员 数据格式
最新版Notepad++下载、安装、配置保姆级教程(附官网安装包)
Notepad++ 是一款免费开源、轻量快速的 Windows 文本编辑器,支持多标签、语法高亮、代码折叠与宏录制,体积小、启动快、资源占用低,兼容 x64/x32/ARM 架构,是程序员和文字工作者的高效利器。
3321 0
|
14天前
|
人工智能 API 开发工具
DeepSeek Harness 神插件:白嫖 13 家大厂模型
`dsh-our-free-model` 是 DeepSeek Harness 神级插件:零配置、零API Key、零账号,聚合13家大厂免费模型(含DeepSeek V4.1 Flash、Kimi K3等),支持本地网关、用量看板与自动降级,真正实现“白嫖即用”。
2343 44
|
11天前
|
Web App开发 人工智能 前端开发
2026 年 AI 浏览器怎么选?Ego Lite、Tabbit、Chrome DevTools MCP 深度对比,开发者到底该用哪个?
2026年AI浏览器选型指南:Ego Lite专注多Agent协同(Mac优先),Tabbit国产首选,原生支持Windows与Codex控制;Chrome DevTools MCP非浏览器而是开发者利器,深度集成Console/Network/Performance调试能力,让AI真正“看懂并验证”前端代码。
1443 3
|
8天前
|
安全 应用服务中间件 Go
PHP2Shell 漏洞拆解:WordPress 与 nginx 为何中招
PHP2Shell 双 RCE 已遭在野利用:WordPress、Drupal 全在射程内,nginx 其实另有洞。拆成因与修复顺序
PHP2Shell 漏洞拆解:WordPress 与 nginx 为何中招
|
8天前
|
开发者 索引
DeepSeekHarness大肥鱼自带插件市场了?加个地址就能用
Open Plugin Market 是一个开放插件索引平台,收录800+优质DSH插件,支持分类浏览、智能推荐与随机发现。无需安装市场,粘贴索引地址即可一键接入,网页版直访 dshopen.org,助力小开发者被看见。(239字)
1803 1
DeepSeekHarness大肥鱼自带插件市场了?加个地址就能用
|
6天前
|
人工智能 Linux API
Magpie, 轻量本地AI网关!免费Token用不完!
Magpie 是开源AI编程模型调度网关,上线一月获1.8万Star。它通过本地高性能网关统一托管多平台API密钥、账号与免费额度,实现跨Agent的模型秒级切换、静默额度轮换与资源复用,显著降低碎片化管理成本。(239字)
Magpie, 轻量本地AI网关!免费Token用不完!
|
6天前
|
安全 程序员 应用服务中间件
PHP 被曝两大致命漏洞,请所有程序员抓紧做这件事!
PHP 官方发布了紧急安全更新,一口气修复了两个严重漏洞。如果网站和服务器用了 PHP 应该怎么处理?漏洞的原理是什么?本文给你讲清楚
716 0

热门文章

最新文章