首页 技术 正文
技术 2022年11月21日
0 收藏 653 点赞 4,725 浏览 1558 个字

如题

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 resdef 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 = [ord(d) for d in fd.read()]
height, width = fileinfo['height'], fileinfo['width']
if width<8 or width>32767:
data.resize((height, width, 4))
return rgbe2float(data) img = np.zeros((height, width, 4))
dp = 0
for h in range(height):
if data[dp] !=2 or data[dp+1]!=2:
print 'this file is not run length encoded'
print data[dp:dp+4]
return
if data[dp+2]*256+ data[dp+3] != width:
print 'wrong scanline width'
return
dp += 4
for i in range(4):
ptr = 0
while(ptr < width):
if data[dp]>128:
count = data[dp]-128
if count==0 or count>width-ptr:
print 'bad scanline data'
img[h, ptr:ptr+count,i] = data[dp+1]
ptr += count
dp += 2
else:
count = data[dp]
dp += 1
if count==0 or count>width-ptr:
print 'bad scanline data'
img[h, ptr:ptr+count,i] = data[dp: dp+count]
ptr += count
dp +=count
return rgbe2float(img)
if __name__ == '__main__':
m = readHdr()
m1,m2 = m.max(), m.min()
img = (m-m2)/(m1-m2)
m1 = m[:,:,0].copy(); m[:,:,0] = m[:,:,2]; m[:,:,2]=m1
cv2.imwrite('tmp.jpg', img*255)

  

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,020
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,513
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,359
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,142
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,772
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,850