python基础学习之-----------推荐一款超方便的python 图片IO脚本

在处理Scene Flow数据集的Ground Truth图片时,遇到pfm格式的挑战。文章分享了一款由Scene Flow团队开发的Python图片IO脚本,该脚本在读写pfm格式上表现出色,极大地方便了工作。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

前几天使用Scene Flow这个数据集做密集匹配,但是它的Ground Truth图片格式是pfm,在网上找了很多都没有非常好的pfm读写方法,最后发现了一个由Scene Flow数据集的团队做出来的一个IO脚本,试了一下,非常好用。

#!/usr/bin/env python3.4

import os
import re
import numpy as np
import uuid
from scipy import misc
import numpy as np
from PIL import Image
import sys
import matplotlib.pyplot as plt


def read(file):
    if file.endswith('.float3'): return readFloat(file)
    elif file.endswith('.flo'): return readFlow(file)
    elif file.endswith('.ppm'): return readImage(file)
    elif file.endswith('.pgm'): return readImage(file)
    elif file.endswith('.png'): return readImage(file)
    elif file.endswith('.jpg'): return readImage(file)
    elif file.endswith('.pfm'): return readPFM(file)[0]
    else: raise Exception('don\'t know how to read %s' % file)

def write(file, data):
    if file.endswith('.float3'): return writeFloat(file, data)
    elif file.endswith('.flo'): return writeFlow(file, data)
    elif file.endswith('.ppm'): return writeImage(file, data)
    elif file.endswith('.pgm'): return writeImage(file, data)
    elif file.endswith('.png'): return writeImage(file, data)
    elif file.endswith('.jpg'): 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值