python读取图片的几种方式
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打开图片的格式为:
。
分离方法为:
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读取图片的几种方式相关推荐
- 图像处理五:python读取图片的几种方式
一.读取图片方式 PIL.opencv.scikit-image: (1)PIL和Pillow只提供最基础的数字图像处理,功能有限: (2)opencv实际上是一个c++库,只是提供了python接口 ...
- python读取图片的几种方式以及图像宽和高的存储顺序
1.opencv 2.imageio 3.matplotlib 4.scipy # coding:utf-8import cv2 import imageio from scipy import mi ...
- python读取多张图片_python读取图片的几种方式及图像宽和高的存储顺序
python读取图片的几种方式及图像宽和高的存储顺序 1.opencv 2.imageio 3.matplotlib 4.scipy # coding:utf-8 import cv2 import ...
- Python读取/保存图片的3种方式(PIL、matplotlib、cv2)
文章目录 Python读取/保存图片的3种方式 PIL方式 matplotlib方式 OpenCV方式 总结: Python读取/保存图片的3种方式 PIL方式 from PIL import Ima ...
- python读取图像的几种方式
python读取图像的几种方式 本文介绍几种基于python的图像读取方式: 基于PIL库的图像读取.保存和显示 基于opencv-python的图像读取.保存和显示 基于matplotlib的图像读 ...
- python读入图片的四种方式
title: python读入图片的四种方式 date: 2022-07-02 15:11:58 tags: image process python读入图片的四种方式 ''' 多种读入图片并显示,保 ...
- python导入图片数据_Python中读取图片的6种方式
Python进行图片处理,第一步就是读取图片,这里给大家整理了6种图片的读取方式,并将读取的图片装换成numpy.ndarray()格式.首先需要准备一张照片,假如你有女朋友的话,可以用女朋友的,没有 ...
- 【Python基础】Python中读取图片的6种方式
Python进行图片处理,第一步就是读取图片,这里给大家整理了6种图片的读取方式,并将读取的图片装换成numpy.ndarray()格式.首先需要准备一张照片,假如你有女朋友的话,可以用女朋友的,没有 ...
- python中读取图片的6种方式
作者:小伍哥 来源:AI入门学习 python进行图片处理,第一步就是读取图片,这里给大家整理了6种图片的读取方式,并将读取的图片装换成numpy.ndarray()格式. 首先需要准备一张照片,假如 ...
最新文章
- 百度android 测试平台,集成百度活体检测(Android、iOS)
- 英特尔公布新技术路线图,将为 AWS、高通代工芯片
- 组件 -——SUl Mobile
- 解决ubuntu(16.04版本)和windows电脑之间无法复制粘贴问题
- Git常见报错及解决方法
- 如何通过组件化提高开发效率?
- java 继承 冒号_java继承(extends)简单介绍
- 使用Emit的时候类型XXX尚未完成
- MySQL5.7 服务 crash 后无法启动
- 用for循环打印出大写字母的ASCII码对照表
- [Lync]lync同步通讯簿
- 交通大数据干货总结(1)
- ASP.NET类计算机专业毕业设计题目选题课题
- 软件系统部署手册模版
- 微信JSAPI支付 跟 所遇到的那些坑
- semantic_slam环境配置
- 深剖VR,AR和MR三者之间关系
- 迅捷在线压缩有什么办法可以压缩视频
- python生成一个20万数据_用Python分析了20万场吃鸡数据,有不少有趣的发现
- JS --引用数据类型