-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.py
101 lines (97 loc) · 3.57 KB
/
main.py
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
import numpy as np
import os
import stitch.glb as glb
import stitch.Rigid as st
import stitch.Wobbly as stw
import sys
me = "main.py"
verbose = False
dtype = np.dtype("<u2")
processes = 4
sys.stderr.write("%s: processes = %s\n" % (me, processes))
tx, ty = 2, 2
nx, ny, nz = 200, 200, 200
sx = sy = sz = 1
path = (
'200x200x200le.00.00.raw',
'200x200x200le.00.01.raw',
'200x200x200le.01.00.raw',
'200x200x200le.01.01.raw',
)
glb.SRC[:] = (np.memmap(e, dtype, 'r', 0, (nx, ny, nz),
order='F')[::sx, ::sy, ::sz] for e in path)
kx, ky, kz = glb.SRC[0].shape
ox = 15 // sx
oy = 15 // sy
positions = []
pairs = []
tile_positions = []
for x in range(tx):
for y in range(ty):
tile_positions.append((x, y))
positions.append((x * (kx - ox), y * (ky - oy), 0))
i = x * ty + y
if x + 1 < tx:
pairs.append((i, (x + 1) * ty + y))
if y + 1 < ty:
pairs.append((i, x * ty + y + 1))
shifts, qualities = st.align((kx, ky, kz),
pairs,
positions,
tile_positions,
depth=(20 // sx, 20 // sy, None),
max_shifts=[(-20 // sx, 20 // sx),
(-20 // sy, 20 // sy),
(-20 // sz, 20 // sz)],
clip=np.iinfo(dtype).max,
processes=processes,
verbose=verbose)
positions = st.place(pairs, positions, shifts)
for name, pos in zip(path, positions):
sys.stderr.write(f"main.py: {name}: {pos}\n")
displacements, qualities, status = stw.align(
(kx, ky, kz),
pairs,
positions,
max_shifts=((-20 // sx, 20 // sx), (-20 // sy, 20 // sy)),
prepare=True,
find_shifts=dict(cutoff=3 * np.sqrt(2) / sx),
processes=processes,
verbose=verbose)
positions_new, components = stw.place0((kx, ky, kz),
pairs,
positions,
displacements,
qualities,
status,
smooth=dict(method='window',
window='hamming',
window_length=100 // sx,
binary=None),
min_quality=-np.inf,
processes=processes,
verbose=verbose)
wobble, status = stw.place1((kx, ky, kz),
positions,
positions_new,
components,
smooth=dict(method='window',
window='bartlett',
window_length=20 // sx,
binary=10),
processes=processes,
verbose=verbose)
ux, uy, uz = stw.shape_wobbly(glb.SRC[0].shape, positions, wobble)
output = "%dx%dx%dle.raw" % (ux, uy, uz)
sink = np.memmap(output, dtype, 'w+', 0, (ux, uy, uz), order='F')
glb.SINK[:] = [sink]
stw.stitch(glb.SRC[0].shape,
positions,
wobble,
status,
processes,
verbose=verbose)
import poc.pgm
path = "%dx%d.pgm" % (ux, uy)
poc.pgm.pgm(path, sink[:, :, uz // 2])
sys.stderr.write("%s\n%s\n" % (output, path))