JuliaImages / ImageFiltering.jl

Julia implementations of multidimensional array convolution and nonlinear stencil operations
Other
99 stars 51 forks source link

Add findall_window #225

Open timholy opened 2 years ago

timholy commented 2 years ago

Continued from #223

Closes #224

codecov[bot] commented 2 years ago

Codecov Report

Merging #225 (7179644) into master (02407fa) will decrease coverage by 1.31%. The diff coverage is 0.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #225      +/-   ##
==========================================
- Coverage   91.60%   90.29%   -1.32%     
==========================================
  Files          11       12       +1     
  Lines        1513     1535      +22     
==========================================
  Hits         1386     1386              
- Misses        127      149      +22     
Impacted Files Coverage Δ
src/ImageFiltering.jl 77.27% <ø> (ø)
src/findall_window.jl 0.00% <0.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update 02407fa...7179644. Read the comment docs.

johnnychen94 commented 2 years ago

I haven't checked it very carefully, but maybe this is related to the performance gap to findlocalmaxima

function sum_window_mean_ver1(X)
    out = zero(float(eltype(X)))
    R = CartesianIndices(X)
    Δ = oneunit(eltype(R))
    @inbounds @simd for p in R
        window = max(p-Δ, first(R)):min(p+Δ, last(R))
        out += mean(view(X, window))
    end
    return out
end

function sum_window_mean_ver2(X)
    out = zero(float(eltype(X)))
    R = CartesianIndices(X)
    Δ = oneunit(eltype(R))
    @inbounds @simd for p in R
        window = max(p-Δ, first(R)):min(p+Δ, last(R))
        mean_val = zero(eltype(out))
        for q in window
            mean_val += X[q]
        end
        out += mean_val/length(window)
    end
    return out
end
julia> @btime sum_window_mean_ver1($X);
  164.748 μs (0 allocations: 0 bytes)
julia> @btime sum_window_mean_ver2($X)
  64.137 μs (0 allocations: 0 bytes)
timholy commented 2 years ago

Did you try creating your own mean function in case it's something about the one in Statistics?