[mmfreedom] [Up] [int32] Data Type Conversion

mmgray
Convert a binary image into a gray-scale image.

Synopsis

y = mmgray( f, TYPE = "uint8", k1 = None )

Implemented in Python.

Input

f Image Binary image.
TYPE String

'uint8', 'uint16', or 'int32'.

Default: "uint8"

k1 Double Non-negative integer.

Default: None (Maximum pixel level in pixel type)

Output

y Image Unsigned gray-scale (uint8 or uint16), signed (int32) or binary image.

Description

mmgray converts a binary image into a gray-scale image of a specified data type. The value k1 is assigned to the 1 pixels of f, while the 0 pixels are assigned to the minimum value associated to the specified data type.

Examples

>>> b=mmbinary([0, 1, 0, 1])

              
>>> print b
[0 1 0 1]
>>> c=mmgray(b)

              
>>> print c
[  0 255   0 255]
>>> d=mmgray(b,'uint8',100)

              
>>> print d
[  0 100   0 100]
>>> e=mmgray(b,'uint16')

              
>>> print e
[    0 65535     0 65535]
>>> f=mmgray(b,'int32',0)

              
>>> print f
[-2147483647           0 -2147483647           0]

Equation

Source Code

def mmgray(f, TYPE="uint8", k1=None):
    from Numeric import array
    if k1 is None: k1 = mmmaxleveltype(TYPE)
    if type(f) is list: f = mmbinary(f)
    assert mmis(f,'binary'), 'f must be binary'
    if k1==None:
        k1=mmmaxleveltype(TYPE)
    if   TYPE == 'uint8' : y = uint8(f*k1)
    elif TYPE == 'uint16': y = uint16(f*k1)
    elif TYPE == 'int32' : y = int32(f*k1) - int32(mmneg(f)*mmmaxleveltype(TYPE))
    else:
        assert 0, 'type not supported:'+TYPE
    return y
    

See also

mmfreedom Control automatic data type conversion.
mmbinary Convert a gray-scale image into a binary image
mmthreshad Threshold (adaptive)
mmis Verify if a relationship among images is true or false.
[mmfreedom] [Up] [int32] Python