forked from JuliaImageRecon/Sinograms.jl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
helix.jl
115 lines (95 loc) · 3.38 KB
/
helix.jl
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
function rebin_helix(cg, ig, proj, varargin)
return sino, orbits, used
end
function rebin_helix_do(proj, mask2, zslice, dz, dx, nx,
ny, nz::Int64, na::Int64, ns, ds, ss,
nt, dt, ## tpoints,
dsd, dso, dod, dfs, offset_s, wt,
orbit, orbit_start, pitch, rmax,
source_zs, gamma,
type, short, chat)
if dfs != 0 && dfs != Inf
return "only arc and flat done" ## Fail?
end
na1 = na/(orbit*360);
if abs(floor(int, na1) - na1) > 1e-4
return "bad na/orbit"
end
orbits = zeros(nz,2)
if short
orbit_short_ideal = 180 + 2 * rad2deg(max(abs(gamma)))
na1 = 2 * ceil(orbit_short_ideal / (orbit / na) / 2) ## The ceil() is an inbuilt function in julia
orbit_short = na1 * (orbit / na)
na1_half = na1 / 2; ## because even
orbits[:,1] = orbit_short
else
orbits[:,1] = 360;
na1_half = ceil(na1 / 2)
end
sino = zeros(ns, na1, nz)
used = zeros(nt, na)
for iz = 1:nz
## ticker(mfilename, iz, nz)
zmid = zslice(iz); ## z coordinate of center of this slice
ia1_middle = imin(abs(zmid - source_zs)); ## "1" because julia indexing
ia1_list = ia1_middle - na1_half + [0:na1-1];
if ia1_list[1] < 1
ia1_list = 1:na1
elseif ia1_list[length(ia1_list)] > na ##started editing here
ia1_list = collect(1:na1) - na1 + na; ## Subtracting the two arrays and then adding na or vice versa
end
orbits[iz,2] = orbit_start + [ia1_list[1]-1] / na * orbit
for i1=1:na1
ia1 = ia1_list[i1]
zdiff = zmid - source_zs[ia1]
if dfs == Inf
tt = zdiff * (dsd^2 + ss.^2) / (dsd * dso)
elseif dfs == 0
tt = zdiff * (dsd / dso) ./ cos(gamma)
else
return "bug"
end
itr = tt/dt + wt
itr = max(itr, 0)
itr = min(itr, nt-1)
if type == round(ns,1)
itn = round(itr)
it1 = 1 + itn
it1 = max(it1, 1)
it1 = min(it1, nt)
tt = ((it1-1) - wt) * dt
scale = rebin_helix_scale(dfs, dsd, ss, tt)
tmp = collect(1:ns) + (it1-1)*ns + (ia1-1)*ns*nt
view = proj(tmp)
## view = proj(:, it1, ia1)
used(it1, ia1) = 1
elseif type == Float64
tt = (itr - wt) * dt
it0 = floor(itr)
it0 = min(it0, nt-2)
frac = itr - it0
scale = rebin_helix_scale(dfs, dsd, ss, tt);
tmp = [1:ns]' + it0*ns + (ia1-1)*ns*nt
tmp0 = proj(tmp)
tmp1 = proj(tmp + ns)
## view = (1 - frac) .* tmp0 + frac .* tmp1
view = tmp0 + frac .* (tmp1 - tmp0)
## used([it0+1; it0+2], ia1) = 1
else
return "bad type"
end
sino[:, i1, iz] = scale .* view
end
end
return sino, orbits, used
end
function rebin_helix_scale(dfs, dsd, ss, tt)
if dfs == Inf
scale = sqrt(ss.^2 + tt.^2 + dsd^2) ./ sqrt(tt.^2 + dsd^2)
elseif dfs == 0
scale = dsd ./ sqrt(tt.^2 + dsd^2);
else
return "bad dfs"
end
return scale
end