基于python----图像的表示和可视化
2021/6/7 20:55:16
本文主要是介绍基于python----图像的表示和可视化,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
图像的表示和可视化
- 图像的表示
- 读取
- skimage
- opencv
- 颜色通道操作
- 编写一个数字图像读入,显示,区域裁剪的程序,并分别显示R,G,B三个通道的图像
- 后续
经过采样和量化之后,图像I已经称为空间位置和响应值均离散的数字图像。图像上的每个位置(x,y)以及其对应量化响应值称为一个像素。 图像的表示
二维矩阵是表示数字图像的重要数字形式。一幅M*N的图像可以表示为矩阵,矩阵中的每个元素称为图像的像素。每个像素都有它自己的空间位置和值,值是这一位置像素的颜色或者强度。
与图像相关的重要指标是图像分辨率。图像分辨率是指组成一幅图像的像素密度。对同样大小的一幅图,组成该图的图像像素数目越多,说明图像的分辨率越高,看起来越来越逼真。相反,像素越少,图像越粗糙。图像分辨率包括空间分辨率和灰度级(响应幅度)分辨率。空间分辨率是图像中可辩别的最小空间细节,取样值多少是决定图像空间分辨率的主要参数。
读取
skimage
from skimage import io,data,color from matplotlib import pyplot as plt img=io.imread('123.jpg') img1=data.astronaut() print(img.shape) img0=io.imread('123.jpg',as_gray=True) print("图像类型:",type(img))#显示类型 print("图像大小:",img.shape)#显示类型 print(img.shape[0]) print(img.shape[1]) print(img.shape[2]) print(img.size) print(img.max()) print(img.min()) print(img.mean()) print(img[0][0]) plt.subplot(211),io.imshow(img) plt.title('Input Image'),plt.xticks([]),plt.yticks([]) plt.subplot(212),io.imshow(img0) plt.show()
opencv
import cv2 as cv img=cv.imread('123.jpg') print("图像类型:",type(img))#显示类型 print("图像大小:",img.shape)#显示类型 print(img.shape[0]) print(img.shape[1]) print(img.shape[2]) print(img.size) print(img.max()) print(img.min()) print(img.mean()) print(img[0][0]) img1=cv.imread('123.jpg',0) cv.imshow('Color',img) cv.imshow('gray',img1) cv.waitKey(0) cv.destroyAllWindows()
颜色通道操作
from skimage import io,data,color from matplotlib import pyplot as plt image=io.imread('123.jpg') image_r=image[:,:,0] image_g=image[:,:,1] image_b=image[:,:,2] plt.subplot(2,2,1) io.imshow(image) plt.subplot(2,2,2) io.imshow(image_r) plt.subplot(2,2,3) io.imshow(image_g) plt.subplot(2,2,4) io.imshow(image_b) plt.show()
编写一个数字图像读入,显示,区域裁剪的程序,并分别显示R,G,B三个通道的图像
from PIL import Image import matplotlib.pyplot as plt from skimage import io img2 = io.imread('456.jpg') img = Image.open('456.jpg') # 打开图像. gray = img.convert('L') # 转换成灰度 r, g, b = img.split() # 分离三通道 pic = Image.merge('RGB', (r, g, b)) # 合并三通道 plt.figure("beauty") plt.subplot(3, 3, 1), plt.title('origin') plt.imshow(img), plt.axis('off') # 图像裁剪 img3 = img2[20:400, 50:1000] plt.figure("beauty") plt.subplot(3, 3, 7), plt.title('caijian') plt.imshow(img3), plt.axis('off') plt.subplot(3, 3, 4), plt.title('r') plt.imshow(r, cmap='gray'), plt.axis('off') plt.subplot(3, 3, 5), plt.title('g') plt.imshow(g, cmap='gray'), plt.axis('off') plt.subplot(3, 3, 6), plt.title('b') plt.imshow(b, cmap='gray'), plt.axis('off') plt.show()后续
如果想了解更多物联网、智能家居项目知识,可以关注我的项目实战专栏。
或者关注公众号。
编写不易,感谢支持。
这篇关于基于python----图像的表示和可视化的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-05-08有遇到过吗?同样的规则 Excel 中 比Python 结果大
- 2024-03-30开始python成长之路
- 2024-03-29python optparse
- 2024-03-29python map 函数
- 2024-03-20invalid format specifier python
- 2024-03-18pool.map python
- 2024-03-18threads in python
- 2024-03-14python Ai 应用开发基础训练,字符串,字典,文件
- 2024-03-13id3 algorithm python
- 2024-03-13sum array elements python