人看到的图片和计算机看到的图片

2020-12-23  本文已影响0人  LabVIEW_Python

人看到的图片,反映到大脑,是光影彩色的组合

计算机看到的图片,却是RGB亮度矩阵 人眼中的图片 VS 计算机眼中的图片
所以,计算机图像处理,实质上是在计算机中,通过编程,计算图像的RGB亮度矩阵。那么,矩阵计算的算子、算法就非常重要了。

范例

import cv2
import matplotlib.pyplot as plt
import numpy as np
img = cv2.imread("data/images/bus.jpg")
img = cv2.resize(img, (5,4)) #(x, y) -> (W, H)
print(img.shape) # (H,W,C)
plt.figure()
plt.imshow(img)
plt.show()
line1 = img[1,...]
line1 = np.expand_dims(line1, axis=0)
print(line1.shape)
plt.figure()
plt.imshow(line1)
plt.show()

运行结果:

图像矩阵形状:HWC = (4, 5, 3) 人眼看到的图像

内存中的数据:

[[[133 171 192]
[131 164 184]
[135 137 146]
[116 117 125]
[144 163 178]]

[[ 49 61 60]
[ 38 23 20]
[ 65 48 39]
[ 66 54 50]
[131 143 119]]

[[127 149 174]
[ 14 2 2]
[108 115 118]
[ 25 1 1]
[ 70 63 73]]

[[126 129 136]
[111 106 107]
[113 103 103]
[145 141 146]
[ 91 85 86]]]

上一篇 下一篇

猜你喜欢

热点阅读