[iacontour] [Up] [iapconv] | Image Filtering |
Implemented in Python.
g | Image. Gray-scale (uint8 or uint16) or binary image (logical). |
Perform a 2D discrete convolution. The kernel origin is at the center of image h.
>>> import Numeric
>>> f = Numeric.zeros((5,5))
>>> f[2,2] = 1
>>> print f
[[0 0 0 0 0] [0 0 0 0 0] [0 0 1 0 0] [0 0 0 0 0] [0 0 0 0 0]]
>>> h = Numeric.array([[1,2,3],[4,5,6]])
>>> print h
[[1 2 3] [4 5 6]]
>>> a = iaconv(f,h)
>>> print a
[[0 0 0 0 0 0 0] [0 0 0 0 0 0 0] [0 0 1 2 3 0 0] [0 0 4 5 6 0 0] [0 0 0 0 0 0 0] [0 0 0 0 0 0 0]]
>>> f = Numeric.array([[1,0,0,0],[0,0,0,0]])
>>> print f
[[1 0 0 0] [0 0 0 0]]
>>> h = Numeric.array([1,2,3])
>>> print h
[1 2 3]
>>> a = iaconv(f,h)
>>> print a
[[1 2 3 0 0 0] [0 0 0 0 0 0]]
>>> f = Numeric.array([[1,0,0,0,0,0],[0,0,0,0,0,0]])
>>> print f
[[1 0 0 0 0 0] [0 0 0 0 0 0]]
>>> h = Numeric.array([1,2,3,4])
>>> print h
[1 2 3 4]
>>> a = iaconv(f,h)
>>> print a
[[1 2 3 4 0 0 0 0 0] [0 0 0 0 0 0 0 0 0]]
>>> f = iaread('cameraman.pgm')
>>> h = [[1,2,1],[0,0,0],[-1,-2,-1]]
>>> g = iaconv(f,h)
>>> gn = ianormalize(g, [0,255])
>>> iashow(gn)
(258, 258) Min= 0.0 Max= 255.0 Mean=131.495 Std=19.08
gn |
Both image and kernel are internally converted to double.
def iaconv(f, h): from Numeric import asarray, NewAxis, zeros, array, product f, h = asarray(f), asarray(h) if len(f.shape) == 1: f = f[NewAxis,:] if len(h.shape) == 1: h = h[NewAxis,:] if product(f.shape) < product(h.shape): f, h = h, f g = zeros(array(f.shape) + array(h.shape) - 1) for i in range(h.shape[0]): for j in range(h.shape[1]): g[i:i+f.shape[0], j:j+f.shape[1]] += h[i,j] * f return g
iaconv | 2D convolution. |
[iacontour] [Up] [iapconv] | |