summaryrefslogtreecommitdiff
path: root/tools/3D-Reconstruction/MotionEST/Util.py
diff options
context:
space:
mode:
Diffstat (limited to 'tools/3D-Reconstruction/MotionEST/Util.py')
-rw-r--r--tools/3D-Reconstruction/MotionEST/Util.py37
1 files changed, 37 insertions, 0 deletions
diff --git a/tools/3D-Reconstruction/MotionEST/Util.py b/tools/3D-Reconstruction/MotionEST/Util.py
new file mode 100644
index 000000000..f1a0cd42f
--- /dev/null
+++ b/tools/3D-Reconstruction/MotionEST/Util.py
@@ -0,0 +1,37 @@
+#!/usr/bin/env python
+# coding: utf-8
+import numpy as np
+import numpy.linalg as LA
+import matplotlib.pyplot as plt
+from scipy.ndimage import filters
+from PIL import Image, ImageDraw
+
+
+def MSE(blk1, blk2):
+ return np.mean(
+ LA.norm(
+ np.array(blk1, dtype=np.int) - np.array(blk2, dtype=np.int), axis=2))
+
+
+def drawMF(img, blk_sz, mf):
+ img_rgba = img.convert('RGBA')
+ mf_layer = Image.new(mode='RGBA', size=img_rgba.size, color=(0, 0, 0, 0))
+ draw = ImageDraw.Draw(mf_layer)
+ width = img_rgba.size[0]
+ height = img_rgba.size[1]
+ num_row = height // blk_sz
+ num_col = width // blk_sz
+ for i in xrange(num_row):
+ left = (0, i * blk_sz)
+ right = (width, i * blk_sz)
+ draw.line([left, right], fill=(0, 0, 255, 255))
+ for j in xrange(num_col):
+ up = (j * blk_sz, 0)
+ down = (j * blk_sz, height)
+ draw.line([up, down], fill=(0, 0, 255, 255))
+ for i in xrange(num_row):
+ for j in xrange(num_col):
+ center = (j * blk_sz + 0.5 * blk_sz, i * blk_sz + 0.5 * blk_sz)
+ head = (center[0] + mf[i, j][1], center[1] + mf[i, j][0])
+ draw.line([center, head], fill=(255, 0, 0, 255))
+ return Image.alpha_composite(img_rgba, mf_layer)