解析hdr图像文件的python实现
来源:互联网 发布:丸子网络 编辑:程序博客网 时间:2024/05/29 19:28
如题
import cv2import numpy as npdef 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 = [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)
0 0
- 解析hdr图像文件的python实现
- HDR渲染器的实现(基于OpenGL)
- HDR渲染器的实现(基于OpenGL)
- Python PIL支持的图像文件格式
- 名词解析之HDR
- BMP图像文件解析
- PNG图像文件结构解析
- HDR技术以及如何实现HDR效果
- HDR技术以及如何实现HDR效果
- GLSL实现HDR Rendering
- GLSL实现HDR Rendering
- GLSL实现HDR Rendering
- GLSL实现HDR Rendering
- 快速8-bit通道的伪HDR的实现
- 快速8-bit通道的伪HDR的实现
- HDR 拍照模式的原理,实现及应用
- HDR 拍照模式的原理,实现及应用
- HDR 拍照模式的原理,实现及应用
- 04-树5 Root of AVL Tree
- android从一个应用跳转到另一个应用
- Retinex图像增强和暗通道去雾的关系及其在hdr色调恢复上的应用
- maven---10使用Jenkins进行持续集成
- 使用python自动备份数据库并上传到七牛服务器(定期清除)
- 解析hdr图像文件的python实现
- 设置Eclipse的workspace路径
- SAP价值串
- banana pi m1 编译jpeglib
- awk 常用命令详解
- JAVA循环冗余校验(CRC32)
- 每一朵花儿,都有绽放的权利
- cocos2d-x3.-Node、scheduler
- R绘制Nomogram图的学习笔记