計算機視覺必知 - 用Python將任一圖片轉換為向量矩陣 image2vector
需求:將我本地任意張圖片轉換為向量形式
girl.jpg
import numpy as np
from PIL import Image
img = Image.open('girl.jpg').convert('RGBA')
arr = np.array(img)
# record the original shape
shape = arr.shape
# make a 1-dimensional view of arr
flat_arr = arr.ravel()
# convert it to a matrix
vector = np.matrix(flat_arr)
# do something to the vector
vector[:,::10] = 128
# reform a numpy array of the original shape
arr2 = np.asarray(vector).reshape(shape) # 把圖片轉換為向量形式
# make a PIL image
img2 = Image.fromarray(arr2, 'RGBA')
# img2 = Image.fromarray(arr2 * 3, 'RGBA')
# print(246 * 3 - 256 * 2) # 超過255會自動減去256
img2.show()
img2.save('out.png') # 儲存圖片
arr2
arr2為圖片的向量形式
array([[[128, 182, 175, 255],
[167, 182, 175, 255],
[167, 182, 128, 255],
...,
[166, 183, 128, 255],
[166, 183, 177, 255],
[166, 183, 177, 255]],
[[128, 182, 175, 255],
[167, 182, 175, 255],
[167, 182, 128, 255],
...,
[166, 183, 128, 255],
[166, 183, 177, 255],
[166, 183, 177, 255]],
[[128, 181, 174, 255],
[166, 181, 176, 255],
[166, 181, 128, 255],
...,
[166, 183, 128, 255],
[166, 183, 177, 255],
[166, 183, 177, 255]],
...,
[[128, 73, 80, 255],
[ 96, 75, 82, 255],
[ 98, 77, 128, 255],
...,
[ 67, 77, 128, 255],
[ 64, 77, 86, 255],
[ 64, 77, 86, 255]],
[[128, 59, 66, 255],
[ 83, 62, 69, 255],
[ 85, 64, 128, 255],
...,
[ 66, 76, 128, 255],
[ 64, 77, 86, 255],
[ 64, 77, 86, 255]],
[[128, 53, 60, 255],
[ 76, 55, 62, 255],
[ 78, 57, 128, 255],
...,
[ 65, 75, 128, 255],
[ 64, 77, 86, 255],
[ 64, 77, 86, 255]]], dtype=uint8)
out.jpg
相關文章
- 計算機視覺—圖片幾何變換(2)計算機視覺
- 計算機圖形學之矩陣變換計算機矩陣
- 加入視覺:將計算機改造為機器人視覺計算機機器人
- 怎樣用python計算矩陣乘法?Python矩陣
- 如何將PPT幻燈片轉換為圖片
- 輕鬆將點陣圖轉換為向量圖,享受高品質影像——Vector Magic for Mac/winMac
- Vector Magic for mac(向量圖片轉換工具)1.2.0啟用版Mac
- Java將地圖轉換為陣列[Snippet]Java地圖陣列
- 計算機影象與視覺入門必備計算機視覺
- MATLAB(6)矩陣和向量運算Matlab矩陣
- OpenGL 學習 07 向量 矩陣變換 投影矩陣
- Vector Magic for mac 1.2.0免啟用版 向量圖片轉換工具Mac
- Pytorch視覺化(顯示圖片)及格式轉換PyTorch視覺化
- Python計算機視覺-第2章Python計算機視覺
- “視聯網”或將成為計算機視覺的下一個藍海計算機視覺
- 3D數學基礎-向量運算基礎和矩陣變換3D矩陣
- python numpy基礎 陣列和向量計算Python陣列
- 如何將圖片轉換成影片?
- 第四個OpenGL程式,vector 向量 (矩陣變換之 旋轉,縮放)矩陣
- JavaScript將陣列轉換為字串JavaScript陣列字串
- 計算機演算法:Strassen矩陣乘法計算機演算法矩陣
- 三維重建學習(1):基礎知識:旋轉矩陣與旋轉向量矩陣
- python生成驗證碼,文字轉換為圖片Python
- 將img圖片轉換為base64位編碼
- 計算機視覺論文集計算機視覺
- iOS計算機視覺—ARKitiOS計算機視覺
- 計算機視覺隨談計算機視覺
- spark向量、矩陣型別Spark矩陣型別
- Activity轉換為View和把圖片轉換為ViewView
- 【Python】Python中的圖的鄰接矩陣轉化為字典格式Python矩陣
- Eigen教程(3)之矩陣和向量的運算矩陣
- 向量化實現矩陣運算最佳化(一)矩陣
- Python計算機視覺——Harris角點檢測Python計算機視覺
- Python 計算機視覺(十五)—— 影像特效處理Python計算機視覺特效
- Python將base64轉為文件或者圖片Python
- 如何利用散點圖矩陣進行資料視覺化矩陣視覺化
- jQuery將類陣列物件轉換為陣列jQuery陣列物件
- Vector Magic for mac(向量圖片轉換軟體) 1.2.0中文啟用版Mac