Qu

imfilter

Builtin index · Images

result = imfilter(img, kernel)

Input: img, kernel · Output: result

What it is

img is an Image; kernel is an arbitrary odd-sized (e.g. 3x3, 5x5) square Mat of numeric weights. Generic 2-D convolution with edge-clamped borders — the escape hatch when blur/sharpen/edge_detect's fixed kernels aren't enough.

Overloads

One call shape — this function is not overloaded.

CodeInputOutputDescription
result = imfilter(img, kernel)
img Imageimg is an Image.
kernel —kernel is an arbitrary odd-sized (e.g.
result Image
Returns a new Image, same dimensions as img.

Examples

From the documentation, and run by the build -- the output and the figure below are what the engine actually produced. Simplest first.

m = [10, 200, 10, 200, 10; 200, 10, 200, 10, 200; 10, 200, 10, 200, 10]
img = image_from_matrix(m)

soft = blur(img)
crisp = sharpen(img)
imshow(soft)
imshow(crisp)

kernel = [0, -1, 0; -1, 5, -1; 0, -1, 0]      # explicit unsharp kernel

custom = imfilter(img, kernel)
print(soft.width, crisp.width, custom.width)
output
5 5 5
a synthetic field with one bright patch

from images