Binning

Often we want to bin the data (sum pixels) in microscopy

MicroscopyTools.binFunction
bin(arr, binning)

Bins a arr by the factors given in binning.

For efficient 2 binning, see bin2.

Examples

Simple Usage

julia> bin([1 2 3 4; 5 6 7 8], (2, 2))
1×2 Matrix{Int64}:
 14  22

julia> bin(ones((4, 4)), (2, 4))
2×1 Matrix{Float64}:
 8.0
 8.0

julia> bin([1,2,3,4,5], (2,))
2-element Vector{Int64}:
 3
 7

You can leave out trailing 1s

julia> bin(ones((2,2,2)), (2,))
1×2×2 Array{Float64, 3}:
[:, :, 1] =
 2.0  2.0

[:, :, 2] =
 2.0  2.0

julia> bin(ones((2,2,2)), (2,)) == bin(ones((2,2,2)), (2,1,1))
true
source
MicroscopyTools.bin2Function
bin2(arr)

Essentially calls bin(arr, (2,2)). However, works only for Union{AbstractArray{T, 2}, AbstractArray{T, 3}} where T since we use specialized methods of Tullio for that.

Examples

julia> x = [1 2 3 4; 5 6 7 8]
2×4 Matrix{Int64}:
 1  2  3  4
 5  6  7  8

julia> bin2(x)
1×2 Matrix{Int64}:
 14  22

julia> bin2(x) ≈ bin(x, (2,2))
true
source