# Need help to make imfilter calculate only on specifies indices

Hi,
I have a question about how to use the `imfilter!` function from ImageFiltering so that is computes only on provided inds. I am having trouble making a simple example work. Here is my code:

``````using ImageFiltering, Images, ComputationalResources

# Create a sample image:
tile_size = 50
board_size = 4 # must be even
mini_board = [zeros(tile_size, tile_size) ones(tile_size, tile_size);
ones(tile_size, tile_size) zeros(tile_size, tile_size)]
chessboard = repeat(mini_board, outer=(convert(Integer,(board_size/2)), convert(Integer,(board_size/2))))
img = chessboard

# Create a filter:
sigma = 3
filter_size = 21
gaus = ImageFiltering.KernelFactors.gaussian(sigma, filter_size)
kernel = kernelfactors((gaus, gaus))

# params of imfilter function
imgfilt = similar(img)
inds = CartesianIndex(50, 50) # simple inds

# The filtering that errors:
imfilter!(CPU1(Algorithm.FIRTiled()), imgfilt, img, kernel, "symmetric", inds)
``````

From the documentation I thought this would work, but it doesn’t. I get an error like this:

``````ERROR: MethodError: no method matching factorkernel(::Tuple{ImageFiltering.KernelFactors.ReshapedOneD{Float64,2,0,OffsetArrays.OffsetArray{Float64,1,Array{Float64,1
}}},ImageFiltering.KernelFactors.ReshapedOneD{Float64,2,1,OffsetArrays.OffsetArray{Float64,1,Array{Float64,1}}}})
Closest candidates are:
factorkernel(::AbstractArray{T,2}) where T at /Users/MrTrololord/.julia/packages/ImageFiltering/jhBno/src/imfilter.jl:1493
factorkernel(::AbstractArray) at /Users/MrTrololord/.julia/packages/ImageFiltering/jhBno/src/imfilter.jl:1489
factorkernel(::ImageFiltering.Kernel.Laplacian) at /Users/MrTrololord/.julia/packages/ImageFiltering/jhBno/src/imfilter.jl:1490
Stacktrace:
[1] imfilter!(::CPU1{ImageFiltering.Algorithm.FIRTiled{0}}, ::Array{Float64,2}, ::Array{Float64,2}, ::Tuple{ImageFiltering.KernelFactors.ReshapedOneD{Float64,2,0,O
ffsetArrays.OffsetArray{Float64,1,Array{Float64,1}}},ImageFiltering.KernelFactors.ReshapedOneD{Float64,2,1,OffsetArrays.OffsetArray{Float64,1,Array{Float64,1}}}}, :
:String, ::CartesianIndex{2}) at /Users/MrTrololord/.julia/packages/ImageFiltering/jhBno/src/imfilter.jl:585
``````

Can anyone help me make this work?

EDIT:
I think there might be something wrong with ImageFiltering dispatch? I’m going to post an issue at ImageFiltering.jl.

Mapwindow seems to have the the functionality I need, if I make it do a filter as the supplied function. Something like this perhaps:

``````function f(img_pix)
sum(img_pix .* [0 1/10 0;
1/10 6/10 1/10;
0 1/10 0])
end

mapped_img = mapwindow(f, img, (3, 3), "symmetric", (2:8, 2:8))
``````

But I was hopping to use imfilter, since I thought it is supposed to have this functionality and and is made for filtering, so it might be faster I thought.

Also, it would be nice have it work for discontinuous indices. Where I can provide pixel coordinates and mapwindow calculates only on those, but I skimmed through the source code and this is not possible, I think.