Is there something like skimage's view_as_windows in Julia?

The function to apply to each window is the first argument to mapwindow. For example:

julia> A=permutedims(reshape(collect(0:15), 4,4))
4×4 Matrix{Int64}:
  0   1   2   3
  4   5   6   7
  8   9  10  11
 12  13  14  15

julia> mapwindow(maximum, A, (0:1,0:1))
4×4 Matrix{Int64}:
  5   6   7   7
  9  10  11  11
 13  14  15  15
 13  14  15  15

If you really need the full array (perhaps your function needs to access two windows at the same time?) you could use a StridedView

using Strided

julia> A=permutedims(reshape(collect(0:15), 4,4))
4×4 Matrix{Int64}:
  0   1   2   3
  4   5   6   7
  8   9  10  11
 12  13  14  15

julia> V=StridedView(A, (3,3,2,2), (1,4,1,4));

julia> V[1,1,:,:]
2×2 StridedView{Int64, 2, Vector{Int64}, typeof(identity)}:
 0  1
 4  5

julia> V[1,2,:,:]
2×2 StridedView{Int64, 2, Vector{Int64}, typeof(identity)}:
 1  2
 5  6
1 Like