MCPcopy
hub / github.com/hpcaitech/Open-Sora / writePFM

Function writePFM

tools/frame_interpolation/utils/utils.py:176–203  ·  view source on GitHub ↗
(file, image, scale=1)

Source from the content-addressed store, hash-verified

174
175
176def writePFM(file, image, scale=1):
177 file = open(file, "wb")
178
179 color = None
180
181 if image.dtype.name != "float32":
182 raise Exception("Image dtype must be float32.")
183
184 image = np.flipud(image)
185
186 if len(image.shape) == 3 and image.shape[2] == 3:
187 color = True
188 elif len(image.shape) == 2 or len(image.shape) == 3 and image.shape[2] == 1:
189 color = False
190 else:
191 raise Exception("Image must have H x W x 3, H x W x 1 or H x W dimensions.")
192
193 file.write("PF\n" if color else "Pf\n".encode())
194 file.write("%d %d\n".encode() % (image.shape[1], image.shape[0]))
195
196 endian = image.dtype.byteorder
197
198 if endian == "<" or endian == "=" and sys.byteorder == "little":
199 scale = -scale
200
201 file.write("%f\n".encode() % scale)
202
203 image.tofile(file)
204
205
206def readFlow(name):

Callers 2

writeFunction · 0.85
writeImageFunction · 0.85

Calls 1

encodeMethod · 0.45

Tested by

no test coverage detected