首先,我们需要用到2个库,分别是numpy和cv2.
import numpy as np import cv2
接着导入文件并进行最大最小值剪裁
cby = np.load('cby.npy') # load cby.npy MIN_DEPTH = 0 # minimum depth MAX_DEPTH = min(300, np.percentile(cby, 99)) # maximum depth cby = np.clip(cby, MIN_DEPTH, MAX_DEPTH) # clip MIN_DEPTH = np.min(cby) # min depth MAX_DEPTH = np.max(cby) # max depth cby = (cby - MIN_DEPTH) / (MAX_DEPTH - MIN_DEPTH) # 归一化
接着转化为8bit整数型,利用cv2.cvtColor进行转化后保存
cby *= 255 # 转化成8bit整数格式 cby_gray = cby.astype(np.uint8) # gray cby_bgr = cv2.cvtColor(cby_gray, cv2.COLOR_GRAY2BGR) # gray color cv2.imwrite('cby.png', cby_bgr) # save gray # cv2.imshow('cby', cby_gray) # cv2.waitKey(0)
读取时仅需要按照rgb图片读取,而后随便取其中一个通道即可
标签:文件,gray,MIN,cv2,DEPTH,npy,np,cby,png From: https://www.cnblogs.com/alexlord/p/16835184.html