JuliaImages / ImageFiltering.jl

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

Not an issue: factorkernel(centered(ones(3,3))) all negative #109

Closed rapus95 closed 4 years ago

rapus95 commented 5 years ago

Hey, when building the local 3x3 sum over an intensity image I came across the question whether it'd be not much less performant to use imfilter with a ones(3,3) kernel than to do it in a map or broadcast since edgehandling is way more convenient for imfilter. In order to speed things up, I called factorkernel ahead of filtering and stumbled over:

julia> ImageFiltering.factorkernel(centered(ones(Float64,3,3)))
([-1.0; ; -1.0; ; -1.0], [-1.0 -1.0 -1.0])

I know that the sign doesn't matter here since 1*1=(-1)*(-1) though I'm curious if there is a faster way if these are all positive (maybe because *1 can be optimized) etc. What would be the best solution to my problem? mapwindow(x->sum(x),...) map(areasum.(Ref(layer),x),CartesianIndices(layer)) imfilter(layer, ImageFiltering.factorkernel(centered(ones(3,3)))) imfilter(layer, centered.((ones(3), ones(3))))

timholy commented 5 years ago

You can also supply the kernel as

kern = kernelfactors(centered.(([1,1,1], [1,1,1])))

I'm not sure which is best, so why don't you just benchmark them and let us know the answer?