-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNPoly.jl
156 lines (123 loc) · 4.31 KB
/
NPoly.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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
####################################################################################################
# ENVIRONMENT SETUP
using Pkg
Pkg.activate(".")
using PyPlot
using DelimitedFiles
include("NRot.jl")
####################################################################################################
# PREAMBLE ADQUISITIONS
@info "Retrieving the two-dimensional field"
pathfile = joinpath(abspath(""), "data/img_origin/bw9x9.png")
img = imgload(pathfile)
@info "Splitting the carriers"
img_r = chsplit(img, 1)
img_g = chsplit(img, 2)
img_b = chsplit(img, 3)
####################################################################################################
# PARAMETERS
const j = Integer((size(img_r)[1] - 1)/2)
const ang = pi/4
@info "The 'spin' parameter of the field is j = $j"
@info "The rotation angle is $ang"
####################################################################################################
# TARGET MATRICES
mr_1 = zeros((2 * j + 1, 2 * j + 1))
mg_1 = zeros((2 * j + 1, 2 * j + 1))
mb_1 = zeros((2 * j + 1, 2 * j + 1))
mr_2 = zeros((2 * j + 1, 2 * j + 1))
mg_2 = zeros((2 * j + 1, 2 * j + 1))
mb_2 = zeros((2 * j + 1, 2 * j + 1))
mr_3 = zeros((2 * j + 1, 2 * j + 1))
mg_3 = zeros((2 * j + 1, 2 * j + 1))
mb_3 = zeros((2 * j + 1, 2 * j + 1))
####################################################################################################
# LOWER AND UPPER MODE MATRIx
@info "Calculating lower modes matrix"
mdown = RdM(ang, j)
@info "Calculating upper modes matrix"
mup = RuM(ang, j)
mmodes = mdown + mup
####################################################################################################
# CALCULATIONS
@info "Performing first rotation"
for x in 1:(2*j+1)
for y in 1:(2*j+1)
mr_1[x, y] = sum([mmodes[x,y,l,m] * img_r[l,m] for l in 1:(2*j+1) for m in 1:(2*j+1)])
end
end
for x in 1:(2*j+1)
for y in 1:(2*j+1)
mg_1[x, y] = sum([mmodes[x,y,l,m] * img_g[l,m] for l in 1:(2*j+1) for m in 1:(2*j+1)])
end
end
for x in 1:(2*j+1)
for y in 1:(2*j+1)
mb_1[x, y] = sum([mmodes[x,y,l,m] * img_b[l,m] for l in 1:(2*j+1) for m in 1:(2*j+1)])
end
end
@info "Performing second rotation"
for x in 1:(2*j+1)
for y in 1:(2*j+1)
mr_2[x, y] = sum([mmodes[x,y,l,m] * mr_1[l,m] for l in 1:(2*j+1) for m in 1:(2*j+1)])
end
end
for x in 1:(2*j+1)
for y in 1:(2*j+1)
mg_2[x, y] = sum([mmodes[x,y,l,m] * mg_1[l,m] for l in 1:(2*j+1) for m in 1:(2*j+1)])
end
end
for x in 1:(2*j+1)
for y in 1:(2*j+1)
mb_2[x, y] = sum([mmodes[x,y,l,m] * mg_1[l,m] for l in 1:(2*j+1) for m in 1:(2*j+1)])
end
end
@info "Performing third rotation"
for x in 1:(2*j+1)
for y in 1:(2*j+1)
mr_3[x, y] = sum([mmodes[x,y,l,m] * mr_2[l,m] for l in 1:(2*j+1) for m in 1:(2*j+1)])
end
end
for x in 1:(2*j+1)
for y in 1:(2*j+1)
mg_3[x, y] = sum([mmodes[x,y,l,m] * mg_2[l,m] for l in 1:(2*j+1) for m in 1:(2*j+1)])
end
end
for x in 1:(2*j+1)
for y in 1:(2*j+1)
mb_3[x, y] = sum([mmodes[x,y,l,m] * mg_2[l,m] for l in 1:(2*j+1) for m in 1:(2*j+1)])
end
end
@info "Assembling the polychromatic representation"
repd_1 = PixelsGT.imgrep(mr_1, mg_1, mr_1)
repd_2 = PixelsGT.imgrep(mr_2, mg_2, mr_2)
repd_3 = PixelsGT.imgrep(mr_3, mg_3, mr_3)
@info "Writting the results"
writedlm(joinpath(abspath(""), "data/data_target/bw9x9_r1.dat"), mr_1)
writedlm(joinpath(abspath(""), "data/data_target/bw9x9_g1.dat"), mg_1)
writedlm(joinpath(abspath(""), "data/data_target/bw9x9_b1.dat"), mb_1)
writedlm(joinpath(abspath(""), "data/data_target/bw9x9_r2.dat"), mr_2)
writedlm(joinpath(abspath(""), "data/data_target/bw9x9_g2.dat"), mg_2)
writedlm(joinpath(abspath(""), "data/data_target/bw9x9_b2.dat"), mb_2)
writedlm(joinpath(abspath(""), "data/data_target/bw9x9_r3.dat"), mr_3)
writedlm(joinpath(abspath(""), "data/data_target/bw9x9_g3.dat"), mg_3)
writedlm(joinpath(abspath(""), "data/data_target/bw9x9_b3.dat"), mb_3)
@info "Showing the transformed two-dimensional field"
begin
imshow(repd_1)
box(false)
axis("off")
savefig(joinpath(abspath(""), "data/img_target/bw9x9_rot1.png"))
end
begin
imshow(repd_2)
box(false)
axis("off")
savefig(joinpath(abspath(""), "data/img_target/bw9x9_rot2.png"))
end
begin
imshow(repd_3)
box(false)
axis("off")
savefig(joinpath(abspath(""), "data/img_target/bw9x9_rot3.png"))
end