def on_receive(self, message): """ :param message: :return: """ image_path = message['image_path'] rect = message['rect'] import numpy as np from scipy import misc from sympy.abc import x, y from engine.interpolate import splint2 image = misc.imread(image_path) image = image.astype(dtype=np.float) grey = np.add.reduce(image, 2)/3.0 grey = np.fliplr(np.swapaxes(grey, 1, 0)) (m, n) = grey.shape (base_x, base_y, extent_x, extent_y) = rect xs = np.linspace(base_x, base_x + extent_x, num=m) ys = np.linspace(base_y, base_y + extent_y, num=n) zs = grey return splint2(xs, ys, zs, x, y)
def test_splint2(): from sympy import lambdify from sympy.abc import x, y import numpy as np from engine.interpolate import splint2 from math import fabs m = 5 n = 4 xs = np.array([2.0, 3.0, 6.0, 8.0, 9.0], dtype=np.float) ys = np.array([1.0, 2.0, 4.0, 8.0], dtype=np.float) zs = np.random.rand(5, 4) tolerance = 1e-6 spline_expression = splint2(xs, ys, zs, x, y) f = lambdify((x, y), spline_expression, "math") for i in xrange(m): for j in xrange(n): assert fabs(f(xs[i], ys[j]) - zs[i, j]) < tolerance, "Incorrect value in control point"
import numpy as np from engine.interpolate import splint2 from sympy.plotting import plot3d from sympy.abc import x, y from scipy import misc image = misc.imread('bitmap_force_input.jpg') image = image.astype(dtype=np.float) grey = np.add.reduce(image, 2)/3.0 grey = np.fliplr(np.swapaxes(grey, 1, 0)) (m, n) = grey.shape xs = np.linspace(0.0, m, num=m) ys = np.linspace(0.0, n, num=n) zs = grey tolerance = 1e-6 print "starting build a spline" spline_expression = splint2(xs, ys, zs, x, y) print "end building a spline" plot3d(spline_expression, (x, 0.0, m), (y, 0.0, n))