图像的表示和可视化
图像的表示读取skimageopencv
颜色通道操作编写一个数字图像读入,显示,区域裁剪的程序,并分别显示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
()
后续
如果想了解更多物联网、智能家居项目知识,可以关注我的项目实战专栏。 或者关注公众号。
编写不易,感谢支持。