summaryrefslogtreecommitdiff
path: root/flowFileLoader.lua
diff options
context:
space:
mode:
authorRyan Baumann <ryan.baumann@gmail.com>2016-07-29 15:30:50 -0400
committerRyan Baumann <ryan.baumann@gmail.com>2016-07-29 15:30:50 -0400
commitc580b52b55b4473deb278f85433dcf347ed79e24 (patch)
tree6a4ed56ad152a79ab1483cd95c66bbe2609e2cef /flowFileLoader.lua
Initial commit
Diffstat (limited to 'flowFileLoader.lua')
-rw-r--r--flowFileLoader.lua34
1 files changed, 34 insertions, 0 deletions
diff --git a/flowFileLoader.lua b/flowFileLoader.lua
new file mode 100644
index 0000000..f185c3c
--- /dev/null
+++ b/flowFileLoader.lua
@@ -0,0 +1,34 @@
+require 'torch'
+require 'image'
+
+--[[
+ Reads a flow field from a binary flow file.
+
+ bytes contents
+ 0-3 tag: "PIEH" in ASCII, which in little endian happens to be the float 202021.25
+ (just a sanity check that floats are represented correctly)
+ 4-7 width as an integer
+ 8-11 height as an integer
+ 12-end data (width*height*2*4 bytes total)
+--]]
+local function flowFileLoader_load(fileName, scale)
+ local flowFile = torch.DiskFile(fileName, 'r')
+ flowFile:binary()
+ flowFile:readFloat()
+ local W = flowFile:readInt()
+ local H = flowFile:readInt()
+ -- image.warp needs 2xHxW, and also expects (y, x) for some reason...
+ local flow = torch.Tensor(2, H, W)
+ for y=1, H do
+ for x=1, W do
+ flow[2][y][x] = flowFile:readFloat() * scale
+ flow[1][y][x] = flowFile:readFloat() * scale
+ end
+ end
+ flowFile:close()
+ return flow
+end
+
+return {
+ load = flowFileLoader_load
+}