-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathalign
executable file
·69 lines (51 loc) · 1.93 KB
/
align
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#!/usr/bin/env python
import itertools
import numpy as np
from scipy.ndimage import center_of_mass
def shift(vertical_shift, horizontal_shift):
s = np.array([[1., 0., vertical_shift],
[0., 1., horizontal_shift],
[0., 0., 1.]])
return s
def scale(vertical_scale, horizontal_scale):
s = np.diag([vertical_scale, horizontal_scale, 1.])
return s
class scan:
def __init__(self, start, end, ):
self.start = start
self.end = end
self.pixels = pixels
self.extent = end - start
self.center = start + self.extent/2.
self.shape = pixels.shape
def get_grid_and_points(self):
vertical = np.linspace(0, 1, self.rows)
horizontal = np.linspace(0, 1, self.columns)
positions = itertools.product(vertical, horizontal)
points = np.array([np.array(position) for position in positions])
points = np.hstack([points, np.ones((points.shape[0], 1))])
points = np.dot(shift(-0.5, -0.5), points.T).T
points = np.dot(scale(*self.extent), points.T).T
points = np.dot(shift(*self.center), points.T).T
points[:, 2] += np.arange(points.shape[0])
indexes = map(int, points[:, 2])
points = dict(zip(indexes, points[:, :2]))
grid = np.reshape(indexes, (self.rows, self.columns))
return grid, points
def horizontal_raster(self, grid, start=1):
grid[start::2, ::] = grid[start::2, ::-1]
return grid
def vertical_raster(self, grid, start=1):
grid[::, start::2] = grid[::-1, start::2]
return grid
def test():
a = area_scan(2, 3, 5)
print a.get_grid_and_points()
def main():
import sys
if len(sys.argv) > 0:
what = sys.argv[1]
else:
print 'Please specify what should I aling'
if __name__ == '__main__':
test()