@staticmethod
def read_pfm(file):
    ' Read a pfm file '
    file = open(file, 'rb')
    color = None
    width = None
    height = None
    scale = None
    endian = None
    header = file.readline().rstrip()
    header = str(bytes.decode(header, encoding='utf-8'))
    if (header == 'PF'):
        color = True
    elif (header == 'Pf'):
        color = False
    else:
        raise Exception('Not a PFM file.')
    temp_str = str(bytes.decode(file.readline(), encoding='utf-8'))
    dim_match = re.match('^(\\d+)\\s(\\d+)\\s$', temp_str)
    if dim_match:
        (width, height) = map(int, dim_match.groups())
    else:
        raise Exception('Malformed PFM header.')
    scale = float(file.readline().rstrip())
    if (scale < 0):
        endian = '<'
        scale = (- scale)
    else:
        endian = '>'
    data = np.fromfile(file, (endian + 'f'))
    shape = ((height, width, 3) if color else (height, width))
    data = np.reshape(data, shape)
    file.close()
    return (data, scale)
Read a pfm file
@staticmethod
def read_pfm(file):
    '  '
    file = open(file, 'rb')
    color = None
    width = None
    height = None
    scale = None
    endian = None
    header = file.readline().rstrip()
    header = str(bytes.decode(header, encoding='utf-8'))
    if (header == 'PF'):
        color = True
    elif (header == 'Pf'):
        color = False
    else:
        raise Exception('Not a PFM file.')
    temp_str = str(bytes.decode(file.readline(), encoding='utf-8'))
    dim_match = re.match('^(\\d+)\\s(\\d+)\\s$', temp_str)
    if dim_match:
        (width, height) = map(int, dim_match.groups())
    else:
        raise Exception('Malformed PFM header.')
    scale = float(file.readline().rstrip())
    if (scale < 0):
        endian = '<'
        scale = (- scale)
    else:
        endian = '>'
    data = np.fromfile(file, (endian + 'f'))
    shape = ((height, width, 3) if color else (height, width))
    data = np.reshape(data, shape)
    file.close()
    return (data, scale)