MATLAB imresize with custom interpolation core

How can I use my function as an interpolation method for the imresize function in MATLAB?

I read the MATLAB help on how to use a user-defined function for the interpolation method, but there was no clear example. and I tried to write code for ma

+4
source share
2 answers

This is how you call the resize function for image A, which wants to resize to 64x52 using the special lanczos2 kernel:

B = imresize(A, [64 52], {@lanczos2,4.0} ); 

Here is one example of one interpolation kernel that you would save as lanczos2.m

 function f = lanczos2(x) f = (sin(pi*x) .* sin(pi*x/2) + eps) ./ ((pi^2 * x.^2 / 2) + eps); f = f .* (abs(x) < 2); end 

Please note that this particular kernel is already implemented in imresize.m. I think your problem is with "@", which is used to refer to functions.

+4
source

The imresize command uses the bicubic method by bicubic . You can also specify one of several built-in methods or interpolation kernels, for example

 imNewSize = imresize(imOldSize, sizeFactor, 'box') 

for a box in the form of a box. If you want to specify your own kernel to order, you can pass this as a function descriptor along with the width of the kernel in an array of cells. For example, to implement a kernel in the form of a kernel (without using the built-in) with a kernel width of 4, try:

 boxKernel = @(x)(-0.5 <= x) & (x < 0.5); imNewSize = imresize(imOldSize, sizeFactor, {boxKernel, 4}); 

If you type edit imresize and look inside the function, from line 893 you can find implementations of other built-in kernels, which may give you some clues about how you can implement your own.

+4
source

Source: https://habr.com/ru/post/1379983/


All Articles