python 利用 PIL 將陣列值轉成圖片
安裝 PIL 包
pip install pillow
將二維資料轉換成單通道圖片
from PIL import Image
arr=numpy.asarray([[1,2,3,4,5],[2,3,4,5,6],[7,8,9,0,12]])
image = Image.fromarray(arr).convert("L")# L為模式
image.save("out.jpg")#輸出圖片格式可以自己選擇
1 -> 1位像素,黑和白,存成8位的像素
L -> 8位像素,黑白
P -> 8位像素,使用調色板映射到任何其他模式
RGB -> 3×8位像素,真彩
RGBA -> 4×8位像素,真彩+透明通道
CMYK -> 4×8位像素,顏色隔離
YCbCr -> 3×8位像素,彩色視頻格式
I -> 32位整型像素
F -> 32位浮點型像素
將三維資料轉換成RGB圖片
from PIL import Image
a=numpy.asarray([[1,2,3,4,5],[2,3,4,5,6],[7,8,9,0,12]])
b=numpy.asarray([[1,2,3,4,5],[2,3,4,5,6],[7,8,9,0,12]])
c=numpy.asarray([[1,2,3,4,5],[2,3,4,5,6],[7,8,9,0,12]])
r = Image.fromarray(a).convert('L')
g = Image.fromarray(b).convert('L')
b = Image.fromarray(c).convert('L')
image = Image.merge('RGB',(r,g,b))
image.save("out.jpg")
讀取h5資料
h5py安裝
conda install h5py
資料讀取
示例檔案:


import h5py
openFileName = h5py.File(fileName)
EASE_column_index_1km=openFileName['Soil_Moisture_Retrieval_Data_1km'['EASE_column_index_1km'][:]#得到Dataset的資料
b=openFileName['a']['rangeEndingDateTime'].value#得到rangeEndingDateTime里面的文本值
讀取hdf資料
pyhdf 安裝
conda install -c conda-forge pyhdf
資料讀取
示例檔案:

from pyhdf.SD import SD, SDC
openFileName = SD(filename, SDC.READ)
a = j.select('Night_view_angl')[:]#獲得Night_view_angl Dataset的值
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/274737.html
標籤:python
下一篇:抓取淘寶網商品資訊
