Download presentation
Presentation is loading. Please wait.
1
Programming Assignment 1 CS302 Data Structures
2
Goals Improve your skills with manipulating dynamic arrays. Improve your understanding of constructors, destructors, and copy-constructors. Improve your skills with operator overloading. Familiarize yourself with reading/writing images from/to a file. Familiarize yourself with image processing. Improve your skills with documenting and describing your programs.
3
Implementation You should implement: image.h (class specification) image.cpp (class implementation) driver.cpp (application or client)
4
image.h class Image { public: constructor //parameter less constructor //with parameters copy_constructor operator= getImageInfo getPixelVal setPixelVal getSubImage meanGray
5
image.h (cont’d) enlargeImage shrinkImage reflectImage translateImage rotateImage operator+ operator- negateImage private: int N; //no of rows int M; //no of columns int Q; //no of gray-level values int **pixelVal; };
6
First... Carefully implement the following functions: –constructor –destructor –copy-constructor –assignment
7
readImage(fileName, image) (client function – has been provided) Reads in an image in PGM format from a file. A “NOT-PGM” exception should be raised if the image is not in PGM format.
8
writeImage(fileName, image) (client function – has been provided) Writes out an image to a file in PGM format.
9
getImageInfo(noRows, noCols, maxVal) (member function – has been provided) Returns: –the height (# of rows) –width (# of columns) of the image –the max gray-level value allowed (i.e., 255 for 8-bit images) These values are “returned” using call by reference.
10
int getPixelVal(r, c) (member function – has been provided) Returns the pixel value at (r, c) location. An OUT-OF-BOUNDS exception should be raised if (r,c) falls outside the image.
11
setPixelVal(r, c, value) (member function – has been provided) Sets the pixel value at location (r, c) to value. An OUT-OF-BOUNDS exception should be raised if (r,c) falls outside the image.
12
getSubImage(Ulr, Ulc, LRr, LRc, oldImage) It crops a rectangular subimage from the input image. –The subimage can be defined by the coordinates of its upper-left (UL) and lower-right (LR) corners. –Useful for limiting the extent of image processing operations to some small part of the image.
13
int meanGray() Computes the average gray-level value of an image. Returns the value as “int” (i.e., truncate the result)
14
enlargeImage(s, oldImage) Enlarges the input image by some integer factor s It is useful for magnifying small details in an image. 2 times the original size
15
enlargeImage (cont’d) Replicate pixels such that each pixel in the input image becomes an s x s block of identical pixels in the output image. Most easily implemented by iterating over pixels of the output image and computing the coordinates of the corresponding input image pixel. Example: s = 2
16
shrinkImage(s, oldImage) Shrinks the input image by some integer factor s It is useful, for example, for reducing a large image in size so it fits on the screen. 1/2 times the original size
17
shrinkImage (cont’d) Sample every s-th pixel in the horizontal and vertical dimensions and ignore the other. Most easily implemented by iterating over pixels of the output image and computing the coordinates of the corresponding input image pixel. Example: s = 2
18
reflectImage(flag, oldImage) Reflects the input image along the horizontal or vertical directions. vertical reflection
19
reflectImage (cont’d) Reflection along either direction can be performed by simply reversing the order of pixels in the rows or columns of the image
20
operator+ (image addition) Computes the weighted sum of two images. You can use it for simple image morphing ! + =
21
operator- (image subtraction) Computes the difference of two given images. Useful for change detection. Compute absolute difference: - =
22
negateImage() Computes the negative of an image. This can be done using the following transformation negative
23
translateImage(t, oldImage) Translates the pixel locations by some amount t. Translation can be performed using the equations: 32 x 32 translation
24
rotateImage(theta, oldImage) Rotates the input image by some angle theta about (0,0). Rotation uses the following equations: if theta > 0: counter- clockwise about (0,0) if theta < 0: clockwise about (0,0)
25
rotateImage (cont’d) Equations to rotate an image about any point : -45 degrees rotation (about the center of the image)
26
Ignore pixels whose coordinates fall outside the range. Find nearest neighbors to and rotateImage (cont’d) Practical problems: –consider rotating pixel (0,100) by 90 degrees: –consider rotating pixel (50,0) by 35 degrees:
27
rotateImage(cont’d) Serious problem: the rotated image could contain numerous “holes” where no value was computed for a pixel !! original rotated
28
Extra Credit Usually, each assignment will contain a number of extra credit questions; answering the extra credit questions is optional. Your are expected to spend some time thinking about each question and provide a reasonable answer. Reasonable ideas, which have been implemented and demonstrated to the TA, will get extra credit !!
29
Useful Tips Learn how to use a debugger –Very important for debugging your programs efficiently! Learn how to use makefiles (especially if you use Linux/Unix): –Very useful when your application is split over many files.
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.