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


目录
相关文章
|
9天前
|
存储 弹性计算 缓存
阿里云服务器租赁费用:新版租赁收费标准及活动报价参考
本文更新了2026年阿里云全系列云服务器租赁活动报价,所有特惠资源均可前往阿里云活动中心选购,整体覆盖从个人入门到企业级高性能场景的全梯度需求。其中轻量应用服务器主打极致性价比,2核2G峰值200M带宽配置每日10点、15点限时抢购价仅38元/年,2核4G配置379元/年起;高性价比的经济型e实例、通用算力型u2i实例覆盖2核4G至4核32G全档位,适配开发测试与中小型企业业务;搭载英特尔至强6处理器的第九代c9i企业级实例算力较上代提升20%,支撑高并发生产环境,不同实例规格价差清晰,用户可根据自身业务负载与预算灵活选型。
1877 119
阿里云服务器租赁费用:新版租赁收费标准及活动报价参考
|
10天前
|
人工智能 程序员 API
Codex 接入 DeepSeek-V4-Flash:还能补上识图,提供两套方案
Codex 接入 DeepSeek-V4-Flash 怎么配?本文覆盖 CLI 与桌面端,再用 qwen3-vl-flash 补识图,两套方案可直接照做
1436 13
|
16天前
|
云安全 人工智能 运维
阿里云联动百位企业安全专家,共识Agent防御最佳实践
当Agent成为新员工,你的安全边界在哪里?
1965 10
阿里云联动百位企业安全专家,共识Agent防御最佳实践
|
7天前
|
编解码 弹性计算 云计算
MiniMax-H3 视频生成模型 — 一键部署与使用指南
MiniMax-H3是MiniMax开源的33B全模态视频生成模型,支持文生视频、图生视频、参考生视频三种模式,原生输出2K/15秒带立体声音频视频,已原生适配ComfyUI,并可通过阿里云计算巢一键部署。(239字)
|
10天前
|
人工智能 JSON Shell
2026AI漫剧本地全开源方案(附各个软件模型链接),8G显卡也能流畅运行
这是一套完全本地化部署的AI漫剧生成技术链路:涵盖LLM剧本分镜生成、FLUX文生图(IP-Adapter人脸锁定)、StoryDiffusion时序连贯控制、LTX-2.3唇形同步视频生成,及ComfyUI全流程调度。零云端费用,仅耗硬件算力,单集2–4小时可产出竖屏短视频,适配抖音/B站分发。
|
8天前
|
人工智能 API 开发工具
2026 零基础本地 AI 漫剧完整实操教程(8G 笔记本显卡可用|附可直接复制命令与代码)
本方案提供完全离线、本地运行的漫剧全自动制作流程:RTX3060/4050 8G显卡即可驱动,涵盖Qwen写分镜→ComfyUI统一角色绘图→LTX2.3图生微动画→Qwen3-TTS本地配音→FFmpeg自动合成,全程无水印、免API、不限次。专为低显存优化,解决变脸、闪烁、爆内存三大痛点。(239字)
|
22天前
|
人工智能 前端开发 Linux
Codex 桌面版安装 + CC Switch 接入第三方 API 完整教程(2026 最新)
2026最新教程:手把手教你安装Codex桌面版,通过CC Switch v3.17.0一键接入Fenno等国产API(兼容OpenAI Responses格式),跳过账号登录,完整启用代码审查、多步任务与上下文感知功能。零基础友好,全程图文实操。(239字)
3383 5
|
9天前
|
编解码 人工智能 安全
2核4G/4核8G/8核16G阿里云服务器如何选择实例?经济型e、通用算力型u2i与计算型c9i选哪个?
本文介绍了阿里云2核4G、4核8G、8核16G三档主流配置下经济型e、通用算力型u2i和计算型c9i三种实例的最新活动价格与适用场景。同配置下三者价差显著,以2核4G为例,经济型e低至599.93元/年,计算型c9i则高达1742.08元/年。文章详细解析了各实例的性能定位:经济型e适合轻负载入门场景,u2i兼顾稳定算力与性价比,c9i凭借第9代至强处理器与芯片级安全能力支撑高性能业务。同时提示用户可叠加满减优惠券享受折上折,建议根据业务负载与预算综合决策。
555 113