JuliaImages / ImageFiltering.jl

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

Filtering non-color element type #110

Closed yha closed 5 years ago

yha commented 5 years ago

The docs seems to suggest that arrays with arbitrary element types can be filtered, but it fails depending on kernel size, e.g.,

using GeometryTypes
x = rand(Point{2,Float64},100)
y = centered(rand(31))    # smaller sizes work fine
imfilter(x,y)   # MethodError: no method matching realfloat(::Array{Point{2,Float64},1})

imfilter works fine in this example if the kernel is smaller or if explicitly choosing

imfilter(x, y, ImageFiltering.FIR())

If FFT is not supported for types other than numbers/Colorants, I think at least FIR should be automatically chosen regardless of kernel size for those types. Ideally, maybe FFT can be supported for other types by the user providing custom channelview or somthing similar.

johnnychen94 commented 5 years ago

Since it's named as "imfilter", I'm curious that how would you interpret Points as an image, and what's the meaning of filtering a point array?

yha commented 5 years ago

I'm not interpreting the Points as an image, but as a curve in 2D. Filtering the curve with a gaussian kernel smooths it, so it's a simple (naive) way to try to recover the "actual" curve from noisy Point data. I'm using ImageFiltering.jl because I find the interface much nicer for this purpose than that of DSP.jl (it's easy to get the indexes and boundary conditions right). It worked perfectly fine until I tried larger kernels.

johnnychen94 commented 5 years ago

It worked perfectly fine until I tried larger kernels.

Yes, perhaps you already know it, if you call imfilter(x, y) directly, there will be a step that infers the "optimal" filtering strategy. Currently >30 would trigger the FFT algorithm.

https://github.com/JuliaImages/ImageFiltering.jl/blob/8bc8aa088ffbefe1264865d3873f804f476541f1/src/imfilter.jl#L1532-L1539

I think at least FIR should be automatically chosen regardless of kernel size for those types.

LGTM, unfortunately, I don't have enough time recently to support this; I have a plan to update the whole package in the future.

timholy commented 5 years ago

Yes, the package should probably drop the Image part of its name, it has been confusing before. There is no good reason not to support non-images.

You're spot-on that in this case a custom channelview is all you need if you want to use FFT. (Or just reinterpret.) But it's not good for it error. Fix in a moment.