首页 > 代码库 > python解析hdr图像文件的python实现
python解析hdr图像文件的python实现
如题
import cv2 import numpy as np def rgbe2float(rgbe): res = np.zeros((rgbe.shape[0],rgbe.shape[1],3)) p = rgbe[:,:,3]>0 m = 2.0**(rgbe[:,:,3][p]-136.0) res[:,:,0][p] = rgbe[:,:,0][p] * m res[:,:,1][p] = rgbe[:,:,1][p] * m res[:,:,2][p] = rgbe[:,:,2][p] * m return res def readHdr(fileName = ‘belgium.hdr‘): fileinfo = {} with open(fileName, ‘rb‘) as fd: tline = fd.readline().strip() if len(tline)<3 or tline[:2] != ‘#?‘: print ‘invalid header‘ return fileinfo[‘identifier‘] = tline[2:] tline = fd.readline().strip() while tline: n = tline.find(‘=‘) if n>0: fileinfo[tline[:n].strip()] = tline[n+1:].strip() tline = fd.readline().strip() tline = fd.readline().strip().split(‘ ‘) fileinfo[‘Ysign‘] = tline[0][0] fileinfo[‘height‘] = int(tline[1]) fileinfo[‘Xsign‘] = tline[2][0] fileinfo[‘width‘] = int(tline[3]) data = http://www.mamicode.com/[ord(d) for d in fd.read()]>
python解析hdr图像文件的python实现
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。