JuliaImages / JuliaImages/ImageFiltering.jl
possible performance improvement to `mapwindow`
Open
Nobody has claimed this yet.
- Dominant language
- Julia
- Stars
- 104
- Forks
- 52
- PR merge metrics
- No merged PRs in 30d
Description
Didn't explore it in depth, but the following hand-written version in 5mins is faster than what mapwindow provides, so I believe there are still room for performance tweak:
# Julia Version 1.6.0-DEV.497
# Commit bd318e6662 (2020-07-20 22:11 UTC)
julia> img = float32.(testimage("camera"))
julia> function my_mapwindow(f, img, window)
out = zeros(eltype(img), axes(img))
R = CartesianIndices(img)
I_first, I_last = first(R), last(R)
Δ = CartesianIndex(ntuple(x->window ÷ 2, ndims(img)))
@inbounds @simd for I in R
patch = max(I_first, I-Δ):min(I_last, I+Δ)
out[I] = f(view(img, patch))
end
return out
end
my_mapwindow (generic function with 1 methods)
# LoopVectorization v0.8.6
julia> function my_mapwindow_avx(f, img, window=3)
out = zeros(eltype(img), axes(img))
R = CartesianIndices(img)
I_first, I_last = first(R), last(R)
Δ = CartesianIndex(ntuple(x->window ÷ 2, ndims(img)))
@avx for I in R
patch = max(I_first, I-Δ):min(I_last, I+Δ)
out[I] = f(view(img, patch))
end
return out
end
julia> mse(my_mapwindow(mean, img, 3), mapwindow(mean, img, (3, 3)))
1.2622413f-8
julia> @btime my_mapwindow(mean, $img, 3);
7.183 ms (2 allocations: 1.00 MiB)
julia> @btime my_mapwindow_avx(mean, $img, 3);
6.423 ms (2 allocations: 1.00 MiB)
julia> @btime mapwindow(mean, $img, (3, 3));
8.069 ms (57271 allocations: 3.78 MiB)
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at the mapwindow implementation and reproduce the issue's Julia benchmarks comparing mapwindow with the hand-written versions on the camera image. Investigate the timing and allocation gap, then verify that any optimization preserves the shown mean-based result and improves the reported performance.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- julia
- Domain
- performance
- Issue type
- Refactor
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100