(file, image, scale=1)
| 174 | |
| 175 | |
| 176 | def 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 | |
| 206 | def readFlow(name): |
no test coverage detected