Tài liệu Xử lý hình ảnh kỹ thuật số P21 docx

20 241 0
Tài liệu Xử lý hình ảnh kỹ thuật số P21 docx

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

Thông tin tài liệu

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: 678 PIKS IMAGE PROCESSING PROGRAMMING EXERCISES (a) Display the RGB source gamma 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 YCbCr colour space. (e) Display the Y, Cb and Cr components as monochrome images. (f) Convert the YCbCr destination image to gamma RGB colour space. (g) Display the gamma RGB destination image. The executable example_colour_conversion_RGB_YCbCr performs this exercise. See the extract_pixel_plane, convert_image_datatype, monadic_ arithmetic, and colour_conversion_linear manual pages. 3.5 Develop a program that converts a gamma RGB colour image to the IHS colour space and converts the IHS colour image back to the gamma RGB colour space. Steps: (a) Display the RGB source gamma 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 IHS colour space. (e) Display the I, H and S components as monochrome images. (f) Convert the IHS destination image to gamma RGB colour space. (g) Display the gamma RGB destination image. The executable example_colour_conversion_RGB_IHS performs this exer- cise. See the extract_pixel_plane, convert_image_datatype, monadic_ arithmetic, and colour_conversion_linear manual pages. 21.4 REGION-OF-INTEREST EXERCISES 4.1 Develop a program that forms the complement of an unsigned integer, 8-bit, 512 × 512, monochrome, image under region-of-interest control. Case 1: Full source and destination ROIs. Case 2: Rectangular source ROI, upper left corner at (50, 100), lower right corner at (300, 350) and full destination ROI. Case 3: Full source ROI and rectangular destination ROI, upper left cor- ner at (150, 200), lower right corner at (400, 450). Case 4: Rectangular source ROI, upper left corner at (50, 100), lower right corner at (300, 350) and rectangular destination ROI, upper left corner at (150, 200), lower right corner at (400, 450). QUANTIZATION EXERCISES 679 Steps: (a) Display the source monochrome image. (b) Create a constant destination image of value 150. (c) Complement the source image into the destination image. (d) Display the destination image. (e) Create a constant destination image of value 150. (f) Bind the source ROI to the source image. (g) Complement the source image into the destination image. (h) Display the destination image. (i) Create a constant destination image of value 150. (j) Bind the destination ROI to the destination image. (k) Complement the source image into the destination image. (l) Display the destination image. (m) Create a constant destination image of value 150. (n) Bind the source ROI to the source image and bind the destination ROI to the destination image. (o) Complement the source image into the destination image. (p) Display the destination image. The executable example_complement_monochrome_roi performs this exercise. See the image_constant, generate_2d_roi_rectangular, bind_roi, and com- plement manual pages. 21.5 IMAGE MEASUREMENT EXERCISES 5.1 Develop a program that computes the extrema of the RGB components of an unsigned integer, 8-bit, colour image. Steps: (a) Display the source colour image. (b) Compute extrema of the colour image and print results for all bands. The executable example_extrema_colour performs this exercise. See the extrema manual page. 5.2 Develop a program that computes the mean and standard deviation of an unsigned integer, 8-bit, monochrome image. Steps: 680 PIKS IMAGE PROCESSING PROGRAMMING EXERCISES (a) Display the source monochrome image. (b) Compute moments of the monochrome image and print results. The executable example_moments_monochrome performs this exercise. See the moments manual page. 5.3 Develop a program that computes the first-order histogram of an unsigned integer, 8-bit, monochrome image with 16 amplitude bins. Steps: (a) Display the source monochrome image. (b) Allocate the histogram. (c) Compute the histogram of the source image. (d) Export the histogram and print its contents. The executable example_histogram_monochrome performs this exercise. See the allocate_histogram, histogram_1d, and export_histogram manual pages. 21.6 QUANTIZATION EXERCISES 6.1 Develop a program that re-quantizes an unsigned integer, 8-bit, monochrome image linearly to three bits per pixel and reconstructs it to eight bits per pixel. Steps: (a) Display the source image. (b) Perform a right overflow shift by three bits on the source image. (c) Perform a left overflow shift by three bits on the right bit-shifted source image. (d) Scale the reconstruction levels to 3-bit values. (e) Display the destination image. The executable example_linear_quantizer executes this example. See the bit_shift, extrema, and window_level manual pages. 6.2 Develop a program that quantizes an unsigned integer, 8-bit, monochrome image according to the cube root lightness function of Eq. 6.3-4 and recon- structs it to eight bits per pixel. Steps: (a) Display the source image. (b) Scale the source image to unit range. (c) Perform the cube root lightness transformation. (d) Scale the lightness function image to 0 to 255. (e) Perform a right overflow shift by three bits on the source image. (f) Perform a left overflow shift by three bits on the right bit-shifted source image. CONVOLUTION EXERCISES 681 (g) Scale the reconstruction levels to 3-bit values. (h) Scale the reconstruction image to the lightness function range. (i) Perform the inverse lightness function. (j) Scale the inverse lightness function to the display range. (k) Display the destination image. The executable example_lightness_quantizer executes this example. See the monadic_arithmetic, unary_integer, window_level, and bit_shift manual pages. 21.7 CONVOLUTION EXERCISES 7.1 Develop a program that convolves a test image with a 3 × 3 uniform impulse response array for three convolution boundary conditions. Steps: (a) Create a 101 × 101 pixel, real datatype test image consisting of a 2 × 2 cluster of amplitude 1.0 pixels in the upper left corner and a single pixel of amplitude 1.0 in the image center. Set all other pixels to 0.0. (b) Create a 3 × 3 uniform impulse response array. (c) Convolve the source image with the impulse response array for the fol- lowing three boundary conditions: enclosed array, zero exterior, reflected exterior. (d) Print a 5 × 5 pixel image array about the upper left corner and image cen- ter for each boundary condition and explain the results. The executable example_convolve_boundary executes this example. See the allocate_neighbourhood_array, impulse_rectangular, image_constant, put_pixel, get_pixel, and convolve_2d manual pages. 7.2 Develop a program that convolves an unsigned integer, 8-bit, colour image with a 5 × 5 uniform impulse response array acquired from the data object repository. Steps: (a) Display the source colour image. (b) Allocate the impulse response array. (c) Fetch the impulse response array from the data object repository. (d) Convolve the source image with the impulse response array. (e) Display the destination image. The executable example_repository_convolve_colour executes this example. See the allocate_neighbourhood_array, return_repository_id, and convolve_2d manual pages. 682 PIKS IMAGE PROCESSING PROGRAMMING EXERCISES 21.8 UNITARY TRANSFORM EXERCISES 8.1 Develop a program that generates the Fourier transform log magnitude ordered display of Figure 8.2-4d for the smpte_girl_luma image. Steps: (a) Display the source monochrome image. (b) Scale the source image to unit amplitude. (c) Perform a two-dimensional Fourier transform on the unit amplitude source image with the ordered display option. (d) Scale the log magnitude according to Eq. 8.2-9 where a = 1.0 and b = 100.0. (e) Display the Fourier transformed image. The executable example_fourier_transform_spectrum executes this example. See the convert_image_datatype, monadic_arithmetic, image_constant, complex_composition, transform_fourier, complex_magnitude, window_level, and unary_real manual pages. 8.2 Develop a program that generates the Hartley transform log magnitude ordered display of Figure 8.3-2c for the smpte_girl_luma image by manipulation of the Fourier transform coefficients of the image. Steps: (a) Display the source monochrome image. (b) Scale the source image to unit amplitude. (c) Perform a two-dimensional Fourier transform on the unit amplitude source image with the dc term at the origin option. (d) Extract the Hartley components from the Fourier components. (e) Scale the log magnitude according to Eq. 8.2-9 where a = 1.0 and b = 100.0. (f) Display the Hartley transformed image. The executable example_transform_hartley executes this example. See the convert_image_datatype, monadic_arithmetic, image_constant, complex_composi- tion, transform_fourier, complex_decomposition, dyadic_arithmetic, complex_ magnitude, window_level, and unary_real manual pages. 21.9 LINEAR PROCESSING EXERCISES 9.1 Develop a program that performs fast Fourier transform convolution following the steps of Section 9.3. Execute this program using an 11 × 11 uniform impulse response array on an unsigned integer, 8-bit, 512 × 512 monochrome image without zero padding. Steps:

Ngày đăng: 26/01/2014, 13:20

Từ khóa liên quan

Tài liệu cùng người dùng

  • Đang cập nhật ...

Tài liệu liên quan