You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When one needs to compute the sum/average of all blocks extracted from an image, pre-building the integral array usually provides a more efficient computation.
using BenchmarkTools, IntegralArrays
# simplified 3x3 mean filter; only for demo purpose
function mean_filter_naive!(out, X)
Δ = CartesianIndex(1, 1)
for i in CartesianIndex(2, 2):CartesianIndex(size(X).-1)
block = @view X[i-Δ: i+Δ]
out[i] = mean(block)
end
return out
end
function mean_filter_integral!(out, X)
iX = IntegralArray(X)
for i in CartesianIndex(2, 2):CartesianIndex(size(X).-1)
x, y = i.I
out[i] = iX[x±1, y±1]/9
end
return out
end
X = Float32.(rand(1:5, 64, 64));
m1 = copy(X);
m2 = copy(X);
@btime mean_filter_naive!($m1, $X); # 65.078 μs (0 allocations: 0 bytes)
@btime mean_filter_integral!($m2, $X); # 12.161 μs (4 allocations: 16.17 KiB)
m1 == m2 # true
One needs to specialize the mapwindow on mean function, e.g.,
When one needs to compute the sum/average of all blocks extracted from an image, pre-building the integral array usually provides a more efficient computation.
One needs to specialize the
mapwindow
onmean
function, e.g.,The text was updated successfully, but these errors were encountered: