[iacrop] [Up] [iatile] Image Information and Manipulation

iapad
Extend the image inserting a frame around it.

Synopsis

g = iapad( f, thick = [1,1], value = 0 )

Implemented in Python.

Input

f Image. Gray-scale (uint8 or uint16) or binary image (logical).

input image.

thick Image. Gray-scale (uint8 or uint16) or binary image (logical).

[rows cols] to be padded.

Default: [1,1]

value Double.

value used in the frame around the image.

Default: 0

Output

g Image. Gray-scale (uint8 or uint16) or binary image (logical).

Examples

>>> f = Numeric.array([[0,1,2],[3,4,5]], Numeric.UnsignedInt8)

              
>>> print f
[[0 1 2]
 [3 4 5]]
>>> g1 = iapad(f)

              
>>> print g1
[[0 0 0 0 0]
 [0 0 1 2 0]
 [0 3 4 5 0]
 [0 0 0 0 0]]
>>> g2 = iapad(f, (1,3), 5)

              
>>> print g2
[[5 5 5 5 5 5 5 5 5]
 [5 5 5 0 1 2 5 5 5]
 [5 5 5 3 4 5 5 5 5]
 [5 5 5 5 5 5 5 5 5]]

Source Code

def iapad(f, thick=[1,1], value=0):
    from Numeric import asarray, ones, array
    f, thick = asarray(f), asarray(thick)
    g = (value * ones(array(f.shape)+2*thick)).astype(f.typecode())
    g[thick[0]:-thick[0], thick[1]:-thick[1]] = f
    return g
    

See also

iacrop Crop an image to find the minimum rectangle.
[iacrop] [Up] [iatile] http://www.python.org