def test_no_points(self): try: t = TPS() t.transform(0, 0) except TPSError: pass else: assert False
def build_model(input_dim, classes_per_level): model = torch.nn.Sequential(torch.nn.Linear(input_dim, 20, bias=True), torch.nn.ReLU(), torch.nn.Linear(20, 20, bias=True), torch.nn.ReLU(), torch.nn.Linear(20, 20, bias=True), torch.nn.ReLU(), torch.nn.Linear(20, 20, bias=True), torch.nn.ReLU(), TPS(20, classes_per_level)) return model
def tps_warp(width, height, ctlpts, stdev): npts = len(ctlpts['_x'][0]) tps_pts = [] for i in range(npts): for j in range(npts): _varx = int(random.random() * width * stdev) _vary = int(random.random() * height * stdev) tps_pts.append( (ctlpts['_x'][i][j], ctlpts['_y'][i][j], _varx, _vary)) t = TPS(tps_pts) _wfx = np.zeros((width, height), dtype='float32') _wfy = np.zeros((width, height), dtype='float32') for w in range(width): for h in range(height): _wfx[w][h] = t.transform(w, h)[0] _wfy[w][h] = t.transform(w, h)[1] warpfield = {'_wfx': _wfx, '_wfy': _wfy} return warpfield
def test_init_from_list(self): t = TPS([(0, 0, 50, 50), (10, 10, 100, 100)]) self.assertEquals(t.transform(4, 5), (72.5, 72.5)) t.add(0, 10, 70, 100) self.assertEquals(t.transform(4, 5), (72.0, 75.0))
def tps(firefox, firefox_log, monkeypatch, pytestconfig, tps_log, tps_profile): yield TPS(firefox, firefox_log, tps_log, tps_profile)
# Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at # http://www.apache.org/licenses/LICENSE-2.0 # Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. import numpy from scipy.misc import imsave from tps import TPS # Quick test that the thin splate spline class works... # Build a model - extrema of a sine curve... x = numpy.array([0.0, 31.0, 63.0, 95.0, 127.0]) y = numpy.array([16.0, 48.0, 16.0, 48.0, 16.0]) model = TPS(1) model.learn(x[:, None], y) # Sample and create an image... sx = numpy.arange(127) sy = model(sx[:, None]).astype(numpy.int32) image = numpy.zeros((64, 128), dtype=numpy.float32) image[sy, sx] = 1.0 image[y.astype(numpy.int32), x.astype(numpy.int32)] = 2.0 # Save image out... imsave('test_tps.png', image)
def inv_gcp_transformer(self): if self._inv_gcp_transformer is None: points = [gcp['ground'] + gcp['pixel'] for gcp in self.gcps] self._inv_gcp_transformer = TPS(points) return self._inv_gcp_transformer
import numpy from scipy.misc import imsave from tps import TPS # Quick test that the thin splate spline class works... # Build a model - extrema of a sine curve... x = numpy.array([0.0, 31.0, 63.0, 95.0, 127.0]) y = numpy.array([16.0, 48.0, 16.0, 48.0, 16.0]) model = TPS(1) model.learn(x[:,None], y) # Sample and create an image... sx = numpy.arange(127) sy = model(sx[:,None]).astype(numpy.int32) image = numpy.zeros((64, 128), dtype=numpy.float32) image[sy,sx] = 1.0 image[y.astype(numpy.int32), x.astype(numpy.int32)] = 2.0 # Save image out...
def test_simple(self): t = TPS() t.add(0, 0, 50, 50) t.add(10, 10, 100, 100) self.assertEquals(t.transform(4, 5), (72.5, 72.5)) t.add(0, 10, 70, 100) self.assertEquals(t.transform(4, 5), (72.0, 75.0))