Practice Homework on Parallel Computing - Fall 2006 | CS 632, Assignments of Computer Science

Material Type: Assignment; Professor: Bangalore; Class: Parallel Computing; Subject: Computer Science; University: University of Alabama - Birmingham; Term: Fall 2006;

Typology: Assignments

Pre 2010

Uploaded on 04/12/2010

koofers-user-z16
koofers-user-z16 🇺🇸

1

(1)

9 documents

1 / 2

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Fall 2006 CS 432/632/732 Parallel Computing
Homework-0
8/29/2006 1-2
Individual Work Only. 100 points. Due September 5, 2006.
Write a program in C/C++ or Fortran that performs the smoothing/sharpening operation
on an image stored as a two-dimensional array of pixels. Use mean and median methods
for smoothing and high-pass sharpening filter mask for sharpening (described in section
12.4.1 – 12.4.3 of the text, pages 374-379) to compute the new pixel values.
To simplify computation along the boundary (edges) use additional rows/columns (ghost
cells) with the values set to zero as shown in the diagram below. Due to the additional
rows/columns if the original image size is M X N then you have to allocate an array of
size (M+2) X (N+2) (in this example, the allocated array size is 5 X 5 while the real pixel
array size is 3 X 3).
00000
01230
04560
07890
00000
Use the driver program provided as a starting point to complete the program. The
program reads the name of PPM (portable pix map) image file in P3 format and a string
to indicate which smoothing/sharpening method to apply (“mean” for mean method,
“median” for median method, and “hpfilter” for high-pass filter) as command-line
arguments. After performing the smoothing/sharpening operation (using the method
specified by the command-line argument) the program writes the new image in PPM P3
format to a file with “-out” appended to the input filename. (Note that we are using PPM
P3 format since it is easier to debug, in real applications we would use the PPM P6
format. P6 format uses binary values instead of ASCII values for the pixels, thus results
in a smaller file size). The PPM format stores the pixel values for red, blue, and green
colors; hence a two-dimensional array is used to store pixel values for each of the
primary colors. For more details about the PPM format please see:
http://netpbm.sourceforge.net/doc/ppm.html or type “man ppm” on a UNIX system.
Most of the program is already written, your task is to understand what the current
program does and implement the three functions mean, median, and high-pass filter.
Specifically understand the memory allocation routines alloc2Darray and alloc3Darray
and the use of the function pointer – funcptr. Test the program with the different images
provided along with the driver program. During initial testing using the small image file
and after you have worked out all the bugs then try with larger file sizes. Note down the
time taken for each operation with the different input files and complete the table below:
Time Taken
(in seconds) Mean Median High-pass
filter
Image1
Image2
Image3
pf2

Partial preview of the text

Download Practice Homework on Parallel Computing - Fall 2006 | CS 632 and more Assignments Computer Science in PDF only on Docsity!

Fall 2006 CS 432/632/732 Parallel Computing Homework-

Individual Work Only. 100 points. Due September 5, 2006.

Write a program in C/C++ or Fortran that performs the smoothing/sharpening operation on an image stored as a two-dimensional array of pixels. Use mean and median methods for smoothing and high-pass sharpening filter mask for sharpening (described in section 12.4.1 – 12.4.3 of the text, pages 374-379) to compute the new pixel values.

To simplify computation along the boundary (edges) use additional rows/columns (ghost cells) with the values set to zero as shown in the diagram below. Due to the additional rows/columns if the original image size is M X N then you have to allocate an array of size (M+2) X (N+2) (in this example, the allocated array size is 5 X 5 while the real pixel array size is 3 X 3).

0 0 0 0 0 0 1 2 3 0 0 4 5 6 0 0 7 8 9 0 0 0 0 0 0

Use the driver program provided as a starting point to complete the program. The program reads the name of PPM (portable pix map) image file in P3 format and a string to indicate which smoothing/sharpening method to apply (“mean” for mean method, “median” for median method, and “hpfilter” for high-pass filter) as command-line arguments. After performing the smoothing/sharpening operation (using the method specified by the command-line argument) the program writes the new image in PPM P format to a file with “-out” appended to the input filename. (Note that we are using PPM P3 format since it is easier to debug, in real applications we would use the PPM P format. P6 format uses binary values instead of ASCII values for the pixels, thus results in a smaller file size). The PPM format stores the pixel values for red, blue, and green colors; hence a two-dimensional array is used to store pixel values for each of the primary colors. For more details about the PPM format please see: http://netpbm.sourceforge.net/doc/ppm.html or type “man ppm” on a UNIX system.

Most of the program is already written, your task is to understand what the current program does and implement the three functions mean, median, and high-pass filter. Specifically understand the memory allocation routines alloc2Darray and alloc3Darray and the use of the function pointer – funcptr. Test the program with the different images provided along with the driver program. During initial testing using the small image file and after you have worked out all the bugs then try with larger file sizes. Note down the time taken for each operation with the different input files and complete the table below:

Time Taken (in seconds) Mean Median High-pass filter Image Image Image

Fall 2006 CS 432/632/732 Parallel Computing Homework-

Answer the following questions w.r.t the driver program:

  1. What is the rationale for allocation memory dynamically (in functions alloc2Darray and alloc3Darray) instead of using static memory allocation?
  2. Draw a diagram to illustrate how memory is allocated in function alloc3Darray. For example, the allocation in function alloc2Darray is illustrated below:
  3. Instead of using alloc2Darray and alloc3Darray, we could have allocated memory for the whole three-dimensional array with a single malloc functions as shown below: int pixels; pixels = (int )malloc(3heightwidth*sizeof(int)); Is there any advantage to the approach followed in the driver program instead of using the above simple allocation? Explain your answer.
  4. What is the rationale for using ghost cell along the boundaries?
  5. What is the rationale for using pointer to function - funcptr?

Submission: Email the source code along with any scripts/Makefile and typed answers to the above questions (Text, Word, PDF, PS file) as a single tar/zip file attachment to [email protected] with the subject “CS432/632-Homework0.”

Resources: Driver program and input files for testing are available at: http://www.cis.uab.edu/cs432/software/index.html.

temp

temp[0]

temp[N]

temp[2N]

temp[3N]

temp[(M-1)*N]

a

a[0]

a[M-1]

a[1]