[iameshgrid] [Up] [ianormalize] Image Information and Manipulation

ianeg
Negate an image.

Synopsis

g = ianeg( f )

Implemented in Python.

Input

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

Set initial.

Output

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

Description

Returns an image that is the negation (i.e., inverse or involution) of the input image.

Examples

>>> c1 = Numeric.array([0, 53, 150, 255], Numeric.UnsignedInt8)

              
>>> print c1
[  0  53 150 255]
>>> n1 = ianeg(c1)

              
>>> print n1
[255 202 105   0]
>>> c2 = Numeric.array([-129, -128, 0, 127, 128], Numeric.Int8)

              
>>> print c2
[ 127 -128    0  127 -128]
>>> n2 = ianeg(c2)

              
>>> print n2
[-127.  128.    0. -127.  128.]

Equation

Source Code

def ianeg(f):
    from Numeric import asarray, Float
    f = asarray(f)
    if f.typecode() in ['b','???']: # (numarray implementara UnsignedInt16 e boolean)
        k = 2**(8*f.itemsize()) - 1
        g = k - f
    else: # Trata os tipos com sinal
        g = -f.astype(Float)
    return g
    
[iameshgrid] [Up] [ianormalize] http://www.python.org