[iacos] [Up] [iaellipse] | Image Creation |
Implemented in Python.
s | Image. Gray-scale (uint8 or uint16) or binary image (logical).
[rows columns] |
mu | Image. Gray-scale (uint8 or uint16) or binary image (logical).
Mean vector. 2D point (x;y). Point of maximum value. |
sigma | Image. Gray-scale (uint8 or uint16) or binary image (logical).
covariance matrix (square). [ Sx^2 Sxy; Syx Sy^2] |
g | Image. Gray-scale (uint8 or uint16) or binary image (logical). |
A 2D Gaussian image is an image with a Gaussian distribution. It can be used to generate test patterns or Gaussian filters both for spatial and frequency domain. The integral of the gaussian function is 1.0.
>>> import Numeric
>>> f = iagaussian([8,4], [3,1], [[1,0],[0,1]])
>>> print Numeric.array2string(f, precision=4, suppress_small=1)
[[ 0.0011 0.0018 0.0011 0.0002] [ 0.0131 0.0215 0.0131 0.0029] [ 0.0585 0.0965 0.0585 0.0131] [ 0.0965 0.1592 0.0965 0.0215] [ 0.0585 0.0965 0.0585 0.0131] [ 0.0131 0.0215 0.0131 0.0029] [ 0.0011 0.0018 0.0011 0.0002] [ 0. 0.0001 0. 0. ]]
>>> g = ianormalize(f, [0,255]).astype(Numeric.UnsignedInt8)
>>> print g
[[ 1 2 1 0] [ 20 34 20 4] [ 93 154 93 20] [154 255 154 34] [ 93 154 93 20] [ 20 34 20 4] [ 1 2 1 0] [ 0 0 0 0]]
>>> f = iagaussian(100, 50, 10*10)
>>> g = ianormalize(f, [0,1])
>>> g,d = iaplot(g)
>>>
g |
>>> f = iagaussian([50,50], [25,10], [[10*10,0],[0,20*20]])
>>> g = ianormalize(f, [0,255]).astype(Numeric.UnsignedInt8)
>>> iashow(g)
(50, 50) Min= 0 Max= 255 Mean=83.974 Std=72.81
g |
def iagaussian(s, mu, sigma): from Numeric import asarray, product, arange, NewAxis, transpose, matrixmultiply, reshape, concatenate, resize, sum, zeros, Float, ravel, pi, sqrt, exp from LinearAlgebra import inverse, determinant if type(sigma).__name__ in ['int', 'float', 'complex']: sigma = [sigma] s, mu, sigma = asarray(s), asarray(mu), asarray(sigma) if (product(s) == max(s)): x = arange(product(s)) d = x - mu if len(d.shape) == 1: tmp1 = d[:,NewAxis] tmp3 = d else: tmp1 = transpose(d) tmp3 = tmp1 if len(sigma) == 1: tmp2 = 1./sigma else: tmp2 = inverse(sigma) k = matrixmultiply(tmp1, tmp2) * tmp3 else: aux = arange(product(s)) x, y = iaind2sub(s, aux) xx = reshape(concatenate((x,y)), (2, product(x.shape))) d = transpose(xx) - resize(reshape(mu,(len(mu),1)), (s[0]*s[1],len(mu))) if len(sigma) == 1: tmp = 1./sigma else: tmp = inverse(sigma) k = matrixmultiply(d, tmp) * d k = sum(transpose(k)) g = zeros(s, Float) aux = ravel(g) if len(sigma) == 1: tmp = sigma else: tmp = determinant(sigma) aux[:] = 1./(2*pi*sqrt(tmp)) * exp(-1./2 * k) return g
iacircle | Create a binary circle image. |
[iacos] [Up] [iaellipse] | |