# How to construct a kernel from a function?

I would like to convolve an image with a mathematical function. I understand that I need to have the mathematical function in a matrix form. How can I build it?

Thanks

• Please elaborate. At the moment the question seems quite broad / unspecific. Also, please try to explain your Mathematica angle and show what you have tried (if available). – Yves Klett May 11 '15 at 14:35
• Are you looking for Array or Table? Those evaluate a function resp. an expression for every cell in a matrix – Niki Estner May 11 '15 at 14:36
• At the moment I convolved an image with a Gaussian using ImageConvolve[Image,GaussianMatrix[{b, a}]]. Now I want to convolve the same image with different functions (i.e. Sinc[x,y], or other mathematical functions). But I don't know how to transform the mathematical function to kernel or matrix – user29336 May 11 '15 at 15:11

## 1 Answer

Just sample your function over a 2D window with a Table.

f[x_,y_]:= 1-2*Sinc[2(x^2 + y^2)]
step = .2;
kern = Table[f[x,y], {x, -3, 3, step}, {y, -3, 3, step}];


The dimensions of the kernel can be returned with Dimensions[kern]. Experiment with values of step and window sizes. Now just do an ImageConvolve[img,kern] and optionally use ImageAdjust to normalize and remove filter gain: