@@ -167,16 +167,27 @@ function upsample2_abs2(mat::AbstractArray{T, N}; dims=1:N) where {T,N}
167167end
168168
169169"""
170- resample_czt(arr, rel_zoom; shear=nothing, shear_dim=nothing, fix_nyquist=false, new_size = size(arr), rel_pad=0.2)
170+ resample_czt(arr, rel_zoom; shear=nothing, shear_dim=nothing, fix_nyquist=false, new_size = size(arr), do_damp=false, rel_pad=0.2, kill_wrap=true )
171171
172172resamples the image with fixed factors or a list of separable functions using the chirp z transform algorithm.
173173The data is first padded by a relative amount `rel_pad` which is needed to avoid wrap-around problems.
174174As opposed to `resample()`, this routine allows for arbitrary non-integer zoom factors.
175- It is reasonably fast but only allows a stretch (via `rel_zoom`) and a shift (via `shear` in pixels) per line or column
175+ It is reasonably fast but only allows a stretch (via `rel_zoom`) and a shift (via `shear` in pixels) per line or column.
176176
177177Note that each entry of the tuple in `rel_zoom` or `shear` describes the zoom or shear to apply to all other dimensions individually
178178per entry along this dimension number.
179179
180+ # Arguments:
181+ + `arr`: array to resample
182+ + `rel_zoom`: factors to zoom as a tuple or a tuple of functions defining the zooms
183+ + `shear`: a tuple of shears or a tuple of shear functions defining the shears
184+ + `shear_dim`: which dimension to shear
185+ + `fix_nyquist`: defines whether to apply `fix_nyquist` when using the apply_shift_strength! function.
186+ + `do_damp`: applies a padding and damping outside the region to zoom, to avoid artefacts
187+ + `rel_pad`: amount of padding to apply, if `do_damp` is true
188+ + `kill_wrap`: removes the wrap-around when zooming out.
189+ + `new_size`: size of the result array. If not provided the same as the input size will be used.
190+
180191# Examples
181192```jdoctest
182193julia> using TestImages, NDTools, View5D
@@ -192,21 +203,28 @@ julia> d = resample_czt(a, (x->1.0,x->1.0), shear=(x->50*x^2,0.0)); # a more com
192203julia> @ve a,b,c,d # visualize distortions
193204```
194205"""
195- function resample_czt (arr:: AbstractArray{T,N} , rel_zoom; shear= nothing , shear_dim= nothing , fix_nyquist= false , new_size = size (arr), rel_pad= 0.2 , do_damp= false , center= CtrMid) where {T,N}
206+ function resample_czt (arr:: AbstractArray{T,N} , rel_zoom; shear= nothing , shear_dim= nothing , fix_nyquist= false , new_size = size (arr), rel_pad= 0.2 , do_damp= false , center= CtrMid, kill_wrap = true , pad_value = zero ( eltype (arr)) ) where {T,N}
196207 RT = real (T)
197208 orig_size = size (arr)
198209 if do_damp
199210 arr = damp_edge_outside (arr, rel_pad)
200211 else
201212 arr = copy (arr)
202213 end
203- for d in 1 : length (rel_zoom)
214+ for d in eachindex (rel_zoom)
204215 sd = mod (d,ndims (arr))+ 1
205216 if ! isnothing (shear_dim)
206217 sd = shear_dim[d]
207218 end
208219 my_zoom = 1.0
209- # case of a list of zoom numbers
220+ # resize the array before zooming, in case the result array is larger
221+ # This may be a bit wasteful depending on the zoom factors, but this case also
222+ # covers the zoomed shearing case
223+ if (new_size[d] > size (arr,d))
224+ nz = Tuple (d == nd ? new_size[nd] : size (arr,nd) for nd= 1 : ndims (arr))
225+ arr = collect (select_region (arr, new_size= nz))
226+ end
227+ # case of a list (or tuple) of zoom numbers
210228 if (isa (rel_zoom, Tuple) && isa (rel_zoom[1 ], Number)) || isa (rel_zoom, Number)
211229 my_zoom = rel_zoom[d]
212230 f_res = ift (arr, d)
@@ -219,9 +237,9 @@ function resample_czt(arr::AbstractArray{T,N}, rel_zoom; shear=nothing, shear_di
219237 FourierTools. apply_shift_strength! (f_res, f_res, shifts, d, sd, - myshear, fix_nyquist)
220238 end
221239 if T<: Real
222- f_res = real (FourierTools. czt_1d (f_res, my_zoom, d))
240+ f_res = real (FourierTools. czt_1d (f_res, my_zoom, d; kill_wrap = kill_wrap, pad_value = pad_value ))
223241 else
224- f_res = T .(FourierTools. czt_1d (f_res, my_zoom, d))
242+ f_res = T .(FourierTools. czt_1d (f_res, my_zoom, d; kill_wrap = kill_wrap, pad_value = pad_value ))
225243 end
226244 select_region! (f_res, arr)
227245 # case of position dependent zoom functions
@@ -251,9 +269,9 @@ function resample_czt(arr::AbstractArray{T,N}, rel_zoom; shear=nothing, shear_di
251269 end
252270 f_res = let
253271 if T<: Real
254- real (FourierTools. czt_1d (f_res, my_zoom, 1 ))
272+ real (FourierTools. czt_1d (f_res, my_zoom, 1 ; kill_wrap = kill_wrap, pad_value = pad_value ))
255273 else
256- FourierTools. czt_1d (f_res, my_zoom, 1 )
274+ FourierTools. czt_1d (f_res, my_zoom, 1 ; kill_wrap = kill_wrap, pad_value = pad_value )
257275 end
258276 end
259277 select_region! (f_res, slice)
0 commit comments