Python使用scipy保存图片的一些注意点

作者:秋秋秋天 时间:2023-12-01 06:06:58 

首先我们载入一张灰度图片,一般灰度图片像素为0-255.

Python使用scipy保存图片的一些注意点

Python使用scipy保存图片的一些注意点

可以发现该图片的最大像素为254,最小像素为2。一般处理图片时会转化为double类型。

Python使用scipy保存图片的一些注意点

我们将图片使用scipy保存为pgm格式。

然后我们重新读取该图片信息。

Python使用scipy保存图片的一些注意点

Python使用scipy保存图片的一些注意点

其像素值发生了变化,自动标准化到了0-255范围,最小值变为0,最大值变为255.

Python使用scipy保存图片的一些注意点

所以,使用scipy保存图像时,加上2个参数,cmin和cmax。就可以了

重新读取图片。结果正确

Python使用scipy保存图片的一些注意点

补充:from scipy import misc 读取和保存图片

from scipy import misc


def imread(name, flatten=False, mode=None)
   pass
"""
读取一张图片返回array,uint8,"""
def imsave(name, arr, format=None):
   pass
"""
Save an array as an image. 自动的调用将图片转成0-255范围内的
arr : ndarray, MxN or MxNx3 or MxNx4
       Array containing image values.  If the shape is ``MxN``, the array
       represents a grey-level image.  Shape ``MxNx3`` stores the red, green
       and blue bands along the last dimension.  An alpha layer may be
       included, specified as the last colour band of an ``MxNx4`` array.
"""

注意上面对图片读取和保存的函数会被弃用,使用如下代替:


import imageio
imageio.imread()
imageio.imwrite()

来源:https://blog.csdn.net/wuhaibin12/article/details/90734008

标签:Python,scipy,图片
0
投稿

猜你喜欢

  • pytorch 数据加载性能对比分析

    2022-04-17 04:22:22
  • 聊一聊JS中的prototype

    2024-05-02 16:20:18
  • Python基于datetime或time模块分别获取当前时间戳的方法实例

    2021-01-19 22:53:18
  • python正则表达式实现自动化编程

    2022-01-08 12:24:33
  • Python人工智能学习PyTorch实现WGAN示例详解

    2022-10-20 18:49:32
  • Python通过tkinter实现百度搜索的示例代码

    2022-06-28 01:28:46
  • [Oracle] RAC 之 - 负载均衡深入解析

    2024-01-27 19:05:17
  • 小程序中英文混合排序问题解决

    2024-04-28 09:41:17
  • 详解Python NumPy中矩阵和通用函数的使用

    2023-05-29 15:57:18
  • matplotlib更改窗口图标的方法示例

    2023-01-15 17:55:30
  • Python tkinter之ComboBox(下拉框)的使用简介

    2021-11-10 02:40:29
  • 用selenium解决滑块验证码的实现步骤

    2021-06-02 01:44:39
  • python通过get,post方式发送http请求和接收http响应的方法

    2022-04-09 04:37:54
  • python使用pyaudio录音和格式转化方式

    2023-11-07 19:30:03
  • 浅谈Python面向对象编程oop思想心得

    2021-10-25 16:45:29
  • asp三天学好ADO对象之第三天

    2008-10-09 12:53:00
  • 在 Python 应用中使用 MongoDB的方法

    2023-09-13 21:53:11
  • 浅谈sklearn中predict与predict_proba区别

    2023-11-08 03:53:45
  • php在windows环境下获得cpu内存实时使用率(推荐)

    2023-11-15 04:44:23
  • js 分页全选或反选标识实现代码

    2024-04-22 22:44:07
  • asp之家 网络编程 m.aspxhome.com