[iawrite] [Up] [iacolormap] Contrast Manipulation

iaapplylut
Intensity image transform.

Synopsis

g = iaapplylut( fi, it )

Implemented in Python.

Input

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

input image, gray scale or index image.

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

Intensity transform. Table of one or three columns.

Output

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

Description

Apply an intensity image transform to the input image. The input image can be seen as an gray scale image or an index image. The intensity transform is represented by a table where the input (gray scale) color address the table line and its column contents indicates the output (gray scale) image color. The table can have one or three columns. If it has three columns, the output image is a three color band image. This intensity image transformation is very powerful and can be use in many applications involving gray scale and color images. If the input image has an index (gray scale color) that is greater than the size of the intensity table, an error is reported.

Examples

>>> f = [[0,1,2], [3,4,5]]

              
>>> it = Numeric.array(range(6)) # identity transform

              
>>> print it
[0 1 2 3 4 5]
>>> g = iaapplylut(f, it)

              
>>> print g
[[0 1 2]
 [3 4 5]]
>>> itn = 5 - it  # negation

              
>>> g = iaapplylut(f, itn)

              
>>> print g
[[5 4 3]
 [2 1 0]]
>>> f = iaread('cameraman.pgm')

              
>>> it = 255 - Numeric.arange(256)

              
>>> g = iaapplylut(f, it)

              
>>> iashow(f)
(256, 256) Min= 0 Max= 251 Mean=137.066 Std=87.20
>>> iashow(g)
(256, 256) Min= 4 Max= 255 Mean=117.934 Std=87.20
f g
>>> f = [[0,1,1], [0,0,1]]

              
>>> ct = [[255,0,0], [0,255,0]]

              
>>> g = iaapplylut(f,ct)

              
>>> print g
[[[255   0   0]
  [255 255   0]]
 [[  0 255 255]
  [  0   0 255]]
 [[  0   0   0]
  [  0   0   0]]]
>>> f = iaread('cameraman.pgm')

              
>>> aux = Numeric.resize(range(256), (256,1))

              
>>> ct = Numeric.concatenate((aux, Numeric.zeros((256,2))), 1)

              
>>> g = iaapplylut(f, ct)

              
>>> iashow(f)
(256, 256) Min= 0 Max= 251 Mean=137.066 Std=87.20
>>> iashow(g)
(3, 256, 256) Min= 0 Max= 251 Mean=45.689 Std=81.91
f g

Equation

Source Code

def iaapplylut(fi, it):
    from Numeric import asarray, product, ravel, NewAxis, reshape, array, transpose
    it = asarray(it)
    if product(it.shape) == max(it.shape): # 1D
        it = ravel(it)
    def lut_map(intens, it=it):
        return it[intens]
    fi = asarray(fi)
    if len(fi.shape) == 1:
        fi = fi[NewAxis,:]
    aux = ravel(fi)
    if len(it.shape) == 1: # 1D
        g = reshape(map(lut_map, aux), fi.shape)
    elif it.shape[1] == 3:
        g = reshape(transpose(map(lut_map, aux)), (3,fi.shape[0],fi.shape[1]))
    else:
        iaerror('error, table should be 1 or 3 columns')
        g = array([])
    return g
    

See also

iacolormap Create a colormap table.
[iawrite] [Up] [iacolormap] http://www.python.org