Skip to content

Commit

Permalink
bug fix and fix in documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
RainerHeintzmann committed Dec 21, 2023
1 parent 1acfb48 commit 4fbe45e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/selection_tools.jl
Original file line number Diff line number Diff line change
Expand Up @@ -255,9 +255,9 @@ end


"""
select_region!(srcsrc::AbstractArray{T, N}, dst=nothing;
select_region!(src::AbstractArray{T, N}, dst=nothing;
center=size(src).÷2 .+1, dst_center=nothing,
new_size==2 .*abs.(dst_center.-(size(dst).÷ 2 .+1)) .+ size(dst),
new_size=2 .*(1 .+ abs.(dst_center.-(size(src).÷ 2 .+ 1))) .+ size(src),
pad_value=zero(eltype(mat), operator!=assign_to!)) where {T,N}
selects (extracts, pads, shifts) a region of interest (ROI), defined by `new_size` and centered with the destination center aligned at
Expand All @@ -274,6 +274,7 @@ Arguments:
+ `dst`. The destination array to write into, if provided. By default `dst=nothing` a new array is created. The `dst`array (or new array) is returned.
+ `new_size`. The size of the array view after the operation finished. By default a maximally large destination size is chosen, which means that any overlap is copied.
If you specify `new_size`, be aware that the `center` and `dst_center` specifications below really have to refer to centers to be copied!
If `new_size` is not specified, a size to fully encompass the (potentially displaced) source array is automatically chosen.
+ `center`. Specifies the center of the new view in coordinates of the old view. By default an alignment of the Fourier-center (right center) is assumed.
+ `dst_center`. defines the center coordinate in the destination array which should align with the above source center. If nothing is provided, the right center pixel of the `dst` array or new array is used.
+ `pad_value`. specifies the value which is inserted in case the ROI extends to outside the source area. This is only used, if no `dst` array is provided.
Expand Down Expand Up @@ -319,7 +320,9 @@ julia> dst=select_region(a,new_size=(10,10), dst_center=(1,1)) # pad a with zero
```
"""
function select_region!(src::AbstractArray{T, N}, dst;
center=size(src)2 .+1, dst_center=size(dst) 2 .+1, new_size=2 .*abs.(dst_center.-(size(dst) 2 .+1)) .+ size(dst), operator! =assign_to!) where {T,N}
center=size(src)2 .+1, dst_center=size(dst) 2 .+1,
new_size=2 .*(1 .+ abs.(dst_center.-(size(src) 2 .+ 1))) .+ size(src),
operator! =assign_to!) where {T,N}
new_size = Tuple(expand_size(new_size, size(dst)))
center = Tuple(expand_size(center, size(src)2 .+1))
dst_center = Tuple(expand_size(dst_center, size(dst) 2 .+1))
Expand Down
8 changes: 8 additions & 0 deletions test/selection_tools.jl
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,14 @@
@test all(select_region!(2 .*a, a, operator! = f) .== 2) # let the operator add one to destination
@test select_region(collect(1:10), new_size=(5,), center=(1,), dst_center=(1,)) == collect(1:5)
@test select_region_view(collect(1:10), new_size=(5,), center=(1,), dst_center=(1,)) == collect(1:5)
a = ones(10,10)
select_region!(2 .*a, a, dst_center=(10,10));
@test all(a[5:end,5:end] .== 2) # check the overwritten part
@test all(a[1:4,1:4] .== 1) # check part of the non-overwritten part
a = ones(10,10)
b = 4*ones(70,70)
select_region!(b, a, dst_center=(-20,20));
@test all(a .== 4) # check the automatic selection of a large enough new_size
end

@testset "Test Magnificiation" begin
Expand Down

0 comments on commit 4fbe45e

Please sign in to comment.