3
$\begingroup$

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

$\endgroup$
  • $\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 '15 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$ – Niki Estner May 11 '15 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 '15 at 15:11
3
$\begingroup$

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

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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