opencv的像素值在[0,1][0,1],show的时候转换到[0,255]

import cv2
img = cv2.imread("imgfile")
cv2.imshow("img_win_name", img)
cv2.waitKey(0)  # 无限期等待输入cv2.imwrite("write_file_name", img)
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

注意,opencv打开图片的格式为:

height×width×channelsheight×width×channels


分离方法为:

b, g, r = cv2.split(img)
  • 1

2. scikit-image包

scikit-image的像素值在[−1,1][−1,1],show的时候转换到[0,255]

import skimage.io as io
import matplotlib.pyplot as pltimg = io.imread("a.jpg")
io.imshow(img)
plt.show()
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

注意skimage读取图片也是height×width×channelsheight×width×channels

3. matplotlib包

matplotlib的像素值在[-1,1]之间,存储的时候转换到[0,255][0,255],show的时候转换到[0,255]

import matplotlib.pyplot as pltimg = plt.imread("img_name")
plt.imshow(img)
  • 1
  • 2
  • 3
  • 4

matplotlib读取图片也是height×widht×channelsheight×widht×channels

4. tifffile包

import tifffile as tiff# 将图片的像素值放缩到[0,1]之间
def scale_percentile(matrix):w, h, d = matrix.shapematrix = np.reshape(matrix, [w * h, d]).astype(np.float64)# Get 2nd and 98th percentilemins = np.percentile(matrix, 1, axis=0)maxs = np.percentile(matrix, 99, axis=0) - minsmatrix = (matrix - mins[None, :]) / maxs[None, :]matrix = np.reshape(matrix, [w, h, d])matrix = matrix.clip(0, 1)return matriximg = tiff.imread("file_name")
tiff.imshow(scale_percentile(img))
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16

注意tifffile的图片的读取顺序height×width×channelsheight×width×channels按照波段来获取。

python读取图片的几种方式相关推荐

  1. 图像处理五:python读取图片的几种方式

    一.读取图片方式 PIL.opencv.scikit-image: (1)PIL和Pillow只提供最基础的数字图像处理,功能有限: (2)opencv实际上是一个c++库,只是提供了python接口 ...

  2. python读取图片的几种方式以及图像宽和高的存储顺序

    1.opencv 2.imageio 3.matplotlib 4.scipy # coding:utf-8import cv2 import imageio from scipy import mi ...

  3. python读取多张图片_python读取图片的几种方式及图像宽和高的存储顺序

    python读取图片的几种方式及图像宽和高的存储顺序 1.opencv 2.imageio 3.matplotlib 4.scipy # coding:utf-8 import cv2 import ...

  4. Python读取/保存图片的3种方式(PIL、matplotlib、cv2)

    文章目录 Python读取/保存图片的3种方式 PIL方式 matplotlib方式 OpenCV方式 总结: Python读取/保存图片的3种方式 PIL方式 from PIL import Ima ...

  5. python读取图像的几种方式

    python读取图像的几种方式 本文介绍几种基于python的图像读取方式: 基于PIL库的图像读取.保存和显示 基于opencv-python的图像读取.保存和显示 基于matplotlib的图像读 ...

  6. python读入图片的四种方式

    title: python读入图片的四种方式 date: 2022-07-02 15:11:58 tags: image process python读入图片的四种方式 ''' 多种读入图片并显示,保 ...

  7. python导入图片数据_Python中读取图片的6种方式

    Python进行图片处理,第一步就是读取图片,这里给大家整理了6种图片的读取方式,并将读取的图片装换成numpy.ndarray()格式.首先需要准备一张照片,假如你有女朋友的话,可以用女朋友的,没有 ...

  8. 【Python基础】Python中读取图片的6种方式

    Python进行图片处理,第一步就是读取图片,这里给大家整理了6种图片的读取方式,并将读取的图片装换成numpy.ndarray()格式.首先需要准备一张照片,假如你有女朋友的话,可以用女朋友的,没有 ...

  9. python中读取图片的6种方式

    作者:小伍哥 来源:AI入门学习 python进行图片处理,第一步就是读取图片,这里给大家整理了6种图片的读取方式,并将读取的图片装换成numpy.ndarray()格式. 首先需要准备一张照片,假如 ...

最新文章

  1. 百度android 测试平台,集成百度活体检测(Android、iOS)
  2. 英特尔公布新技术路线图,将为 AWS、高通代工芯片
  3. 组件 -——SUl Mobile
  4. 解决ubuntu(16.04版本)和windows电脑之间无法复制粘贴问题
  5. Git常见报错及解决方法
  6. 如何通过组件化提高开发效率?
  7. java 继承 冒号_java继承(extends)简单介绍
  8. 使用Emit的时候类型XXX尚未完成
  9. MySQL5.7 服务 crash 后无法启动
  10. 用for循环打印出大写字母的ASCII码对照表
  11. [Lync]lync同步通讯簿
  12. 交通大数据干货总结(1)
  13. ASP.NET类计算机专业毕业设计题目选题课题
  14. 软件系统部署手册模版
  15. 微信JSAPI支付 跟 所遇到的那些坑
  16. semantic_slam环境配置
  17. 深剖VR,AR和MR三者之间关系
  18. 迅捷在线压缩有什么办法可以压缩视频
  19. python生成一个20万数据_用Python分析了20万场吃鸡数据,有不少有趣的发现
  20. JS --引用数据类型

热门文章

  1. phpize使用方法
  2. 【机试】2011-2020年复旦大学考研复试机试真题
  3. 创业公司如何划分股份
  4. java后端研发经典面试题总结,为公司招兵买马
  5. 做了8年前端,感谢那些优秀的后端,陪伴我工作,教会我成长
  6. 京东数科前端岗位面历
  7. 基于CentOs下的Hadoop完全分布式集群环境搭建
  8. display:weston:weston-simple-egl
  9. C语言计算程序运行时间简单实例
  10. 大数据时代,为什么很多JAVA程序员会转型做JAVA大数据