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?


  • $\begingroup$ 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). $\endgroup$
    – Yves Klett
    May 11, 2015 at 14:35
  • $\begingroup$ Are you looking for Array or Table? Those evaluate a function resp. an expression for every cell in a matrix $\endgroup$ May 11, 2015 at 14:36
  • $\begingroup$ 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 $\endgroup$
    – user29336
    May 11, 2015 at 15:11

1 Answer 1


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:

Custom Kernel


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.