
673
21
PIKS IMAGE PROCESSING
PROGRAMMING EXERCISES
Digital image processing is best learned by writing and executing software programs
that implement image processing algorithms. Toward this end, the compact disk
affixed to the back cover of this book provides executable versions of the PIKS Core
Application Program Interface C programming language library, which can be used
to implement exercises described in this chapter.
The compact disk contains the following items:
A Solaris operating system executable version of the PIKS Core API.
A Windows 2000 and Windows NT operating system executable version
of the PIKS Core API.
A Windows 2000 and Windows NT operating system executable version
of PIKSTool, a graphical user interface method of executing many of the
PIKS Core operators without program compilation.
A PDF file format version of the PIKS Core C Programmer’s Reference
Manual.
PDF file format and Word versions of the PIKSTool User’s Manual.
A PDF file format version of the image database directory.
A digital image database of most of the source images used in the book
plus many others widely used in the literature. The images are provided in
the PIKS file format. A utility program is provided for conversion from
the PIKS file format to the TIFF file format.
Digital Image Processing: PIKS Inside, Third Edition. William K. Pratt
Copyright © 2001 John Wiley & Sons, Inc.
ISBNs: 0-471-37407-5 (Hardback); 0-471-22132-5 (Electronic)

674 PIKS IMAGE PROCESSING PROGRAMMING EXERCISES
Digital images of many of the book photographic figures. The images are
provided in the TIFF file format. A utility program is provided for con-
version from the TIFF file format to the PIKS file format.
C program source demonstration programs.
C program executable programs of the programming exercises.
To install the CD on a Windows computer, insert the CD into the CD drive and
follow the screen instructions. To install the CD on a Solaris computer, create a sub-
directory called PIKSrelease, and make that your current working directory by exe-
cuting:
mkdir PIKSrelease
cd PIKSrelease
Insert the PIKS CD in the CD drive and type:
/cdrom/piks_core_1_6/install.sh
See the README text file in the PIKSrelease directory for further installation infor-
mation.
For further information about the PIKS software, please refer to the PixelSoft,
Inc. web site:
or send email to:
pixelsoft@pixelsoft.com
The following sections contain descriptions of programming exercises. All of
them can be implemented using the PIKS API. Some can be more easily imple-
mented using PIKSTool. It is, of course, possible to implement the exercises with
other APIs or tools that match the functionality of PIKS Core.
21.1 PROGRAM GENERATION EXERCISES
1.1 Develop a program that:
(a) Opens a program session.
(b) Reads file parameters of a source image stored in a file.
(c) Allocates unsigned integer, monochrome source and destination images.
(d) Reads an unsigned integer, 8-bit, monochrome source image from a file.
(e) Opens an image display window and displays the source image.
(f) Creates a destination image, which is the complement of the source
image.

IMAGE MANIPULATION EXERCISES 675
(g) Opens a second display window and displays the destination image.
(h) Closes the program session.
The executable example_complement_monochrome_ND performs this exer-
cise. The utility source program DisplayMonochromeND.c provides a PIKS
template for this exercise. Refer to the input_image_file manual page of the PIKS
Programmer’s Reference Manual for file reading information.
1.2 Develop a program that:
(a) Creates, in application space, an unsigned integer, 8-bit, 512 × 512 pixel
array of a source ramp image whose amplitude increases from left-to-
right from 0 to 255.
(b) Imports the source image for display.
(c) Creates a destination image by adding value 100 to each pixel
(d) Displays the destination image
What is the visual effect of the display in step (d)? The monadic_arithmetic operator
can be used for the pixel addition. The executable example_import_ramp per-
forms this exercise. See the monadic_arithmetic, and import_image manual pages.
21.2 IMAGE MANIPULATION EXERCISES
2.1 Develop a program that passes a monochrome image through the log part of
the monochrome vision model of Figure 2.4-4. Steps:
(a) Convert an unsigned integer, 8-bit, monochrome source image to floating
point datatype.
(b) Scale the source image over the range 1.0 to 100.0.
(c) Compute the source image logarithmic lightness function of Eq. 6.3-4.
(d) Scale the log source image for display.
The executable example_monochrome_vision performs this exercise. Refer
to the window-level manual page for image scaling. See the unary_real and
monadic_arithmetic manual pages for computation of the logarithmic lightness
function.
2.2 Develop a program that passes an unsigned integer, monochrome image
through a lookup table with a square root function. Steps:
(a) Read an unsigned integer, 8-bit, monochrome source image from a file.
(b) Display the source image.

676 PIKS IMAGE PROCESSING PROGRAMMING EXERCISES
(c) Allocate a 256 level lookup table.
(d) Load the lookup table with a square root function.
(e) Pass the source image through the lookup table.
(f) Display the destination image.
The executable example_lookup_monochrome_ND performs this exercise.
See the allocate_lookup_table, import_lut, and lookup manual pages.
2.3 Develop a program that passes a signed integer, monochrome image through a
lookup table with a square root function. Steps:
(a) Read a signed integer, 16-bit, monochrome source image from a file.
(b) Linearly scale the source image over its maximum range and display
it.
(c) Allocate a 32,768 level lookup table.
(d) Load the lookup table with a square root function over the source image
maximum range.
(e) Pass the source image through the lookup table.
(f) Linearly scale the destination image over its maximum range and display it.
The executable example_lookup_monochrome_SD performs this exercise.
See the extrema, window_level, allocate_lookup_table, import_lut, and lookup
manual pages.
21.3 COLOUR SPACE EXERCISES
3.1 Develop a program that converts a linear RGB unsigned integer, 8-bit, colour
image to the XYZ colour space and converts the XYZ colour image back to the
RGB colour space. Steps:
(a) Display the RGB source linear colour image.
(b) Display the R, G and B components as monochrome images.
(c) Convert the source image to unit range.
(d) Convert the RGB source image to XYZ colour space.
(e) Display the X, Y and Z components as monochrome images.
(f) Convert the XYZ destination image to RGB colour space.
(g) Display the RGB destination image.

COLOUR SPACE EXERCISES 677
The executable example_colour_conversion_RGB_XYZ performs this
exercise. See the extract_pixel_plane, convert_image_datatype, monadic_ arithmetic,
and colour_conversion_linear manual pages.
3.2 Develop a program that converts a linear RGB colour image to the L*a*b*
colour space and converts the L*a*b* colour image back to the RGB colour
space. Steps:
(a) Display the RGB source linear colour image.
(b) Display the R, G and B components as monochrome images.
(c) Convert the source image to unit range.
(d) Convert the RGB source image to L*a*b* colour space.
(e) Display the L*, a* and b* components as monochrome images.
(f) Convert the L*a*b* destination image to RGB colour space.
(g) Display the RGB destination image.
The executable example_colour_conversion_RGB_Lab performs this exer-
cise. See the extract_pixel_plane, convert_image_datatype, monadic_ arithmetic, and
colour_conversion_linear manual pages.
3.3 Develop a program that converts a linear RGB colour image to a gamma cor-
rected RGB colour image and converts the gamma colour image back to the
linear RGB colour space. Steps:
(a) Display the RGB source linear colour image.
(b) Display the R, G and B components as monochrome images.
(c) Convert the source image to unit range.
(d) Perform gamma correction on the linear RGB source image.
(e) Display the gamma corrected RGB destination image.
(f) Display the R, G and B gamma corrected components as monochrome
images.
(g) Convert the gamma corrected destination image to linear RGB colour
space.
(h) Display the linear RGB destination image.
The executable example_colour_gamma_correction performs this exer-
cise. See the extract_pixel_plane, convert_image_datatype, monadic_arithmetic,
and gamma_correction manual pages.
3.4 Develop a program that converts a gamma RGB colour image to the YCbCr
colour space and converts the YCbCr colour image back to the gamma RGB
colour space. Steps:

