94 |
94 |
95 ############## |
95 ############## |
96 # Translation |
96 # Translation |
97 ############## |
97 ############## |
98 |
98 |
99 @polly function translate_image!(x, z, u::DisplacementFull) |
99 function translate_image!(x, z, u::DisplacementFull) |
100 @assert(size(u, 1)==2 && size(x)==size(u)[2:end] && size(x)==size(z)) |
100 @assert(size(u, 1)==2 && size(x)==size(u)[2:end] && size(x)==size(z)) |
101 |
101 |
102 @inbounds @simd for i=1:size(x, 1) |
102 @inbounds Threads.@threads for i=1:size(x, 1) |
103 @simd for j=1:size(x, 2) |
103 @simd for j=1:size(x, 2) |
104 pt = (i - u[1, i, j], j - u[2, i, j]) |
104 pt = (i - u[1, i, j], j - u[2, i, j]) |
105 x[i, j] = interpolate2d_quadrants(z, pt) |
105 x[i, j] = interpolate2d_quadrants(z, pt) |
106 end |
106 end |
107 end |
107 end |
108 end |
108 end |
109 |
109 |
110 @polly function translate_image!(x, z, u::DisplacementConstant) |
110 function translate_image!(x, z, u::DisplacementConstant) |
111 @assert(size(u)==(2,) && size(x)==size(z)) |
111 @assert(size(u)==(2,) && size(x)==size(z)) |
112 |
112 |
113 @inbounds @simd for i=1:size(x, 1) |
113 @inbounds Threads.@threads for i=1:size(x, 1) |
114 @simd for j=1:size(x, 2) |
114 @simd for j=1:size(x, 2) |
115 pt = (i - u[1], j - u[2]) |
115 pt = (i - u[1], j - u[2]) |
116 x[i, j] = interpolate2d_quadrants(z, pt) |
116 x[i, j] = interpolate2d_quadrants(z, pt) |
117 end |
117 end |
118 end |
118 end |
120 |
120 |
121 ###################### |
121 ###################### |
122 # Subimage extraction |
122 # Subimage extraction |
123 ###################### |
123 ###################### |
124 |
124 |
125 @polly function extract_subimage!(b, im, v::DisplacementConstant) |
125 function extract_subimage!(b, im, v::DisplacementConstant) |
126 (imx, imy) = size(im) |
126 (imx, imy) = size(im) |
127 (bx, by) = size(b) |
127 (bx, by) = size(b) |
128 |
128 |
129 # Translation from target to source coordinates |
129 # Translation from target to source coordinates |
130 vxʹ = (imx-bx)/2 - v[1] |
130 vxʹ = (imx-bx)/2 - v[1] |
136 qx = floor(Int, min(imx, vxʹ + bx) - vxʹ) |
136 qx = floor(Int, min(imx, vxʹ + bx) - vxʹ) |
137 qy = floor(Int, min(imy, vyʹ + by) - vyʹ) |
137 qy = floor(Int, min(imy, vyʹ + by) - vyʹ) |
138 |
138 |
139 b .= 0 |
139 b .= 0 |
140 |
140 |
141 @inbounds @simd for i=px:qx |
141 @inbounds Threads.@threads for i=px:qx |
142 for j=py:qy |
142 @simd for j=py:qy |
143 b[i, j] = interpolate2d_quadrants(im, (i+vxʹ, j+vyʹ)) |
143 b[i, j] = interpolate2d_quadrants(im, (i+vxʹ, j+vyʹ)) |
144 end |
144 end |
145 end |
145 end |
146 end |
146 end |
147 |
147 |