Functions > Image Processing > Image Manipulation > Example: Function and Level Mapping
Example: Function and Level Mapping
Use the funmap and levelmap functions to map a function of intensity, or a vector of new intensity levels, onto an existing image. Function and level maps specify a uniform transformation on intensity levels in an image or image transform. Like equalization, you can also use these functions to optimize the display of an image.
For information on using this example, refer to About Image Processing Examples.
funmap
This function applies the defined function to each element of the matrix.
1. Construct a test matrix:
2. Define a function.
3. Call funmap to apply function f on every element of matrix M.
The same result can be achieved by using the vectorize operator:
4. Read in a sample image.
5. Define a new function.
6. Call funmap to apply function f to the image R. Use the Re function to make sure all the values returned are real.
7. Display the original and transformed images.
 (arcs.bmp) (arcs_fm.bmp)
8. Try other definitions of function f and view the different transformations.
 f2 x 255 e
x 159 2 10
fmap2 Re funmap R f2 Pix WRITEBMP arcs_fm2.bmp fmap2 (arcs_fm2.bmp) f3 x 255 cos
π x 160
fmap3 Re funmap R f3 Pix WRITEBMP arcs_fm3.bmp fmap3 (arcs_fm3.bmp) f4 x 255 sin
π x 160
fmap4 Re funmap R f4 Pix WRITEBMP arcs_fm4.bmp fmap4 (arcs_fm4.bmp)
levelmap
The levelmap function replaces the intensities in an image with the intensity levels given by vector vec. For example, the 100th element in vec gives the new level for pixels with intensity 100.
0 < the entries of M < (vec - 1)
1. To compensate an image with a squared intensity scale, create the following vector.
2. Define a level map that maps the image display irregularities to their correct values.
Recall that:
The level map is:
3. Apply levelmap to the sample image and view the effect.
 (arcs_level.bmp)