Python OpenCv读取.dat类型图片数据并显示
代码见下:
import cv2
import numpy as np
import matplotlib.pyplot as plt#加载nuc数据
col = 256 #列
row = 192 #行path = "Image/DatFile/0001.dat"
img = np.fromfile(path,dtype=np.uint16)img1 = img.reshape(row,col)plt.rcParams['font.sans-serif'] = ['SimHei'] # 坐标图像中显示中文
plt.rcParams['axes.unicode_minus'] = Falseplt.figure("显示图像",figsize=(10,20)) #构建窗口plt.subplot(1,1,1),plt.title("原始图像"),plt.imshow(img1,cmap='gray')
plt.tight_layout() #自动调整子绘图参数,以提供指定的填充plt.show()
显示结果如下: