Download presentation
Presentation is loading. Please wait.
1
Programming Assignment 1 CS308 Data Structures
2
Goals Familiarize yourself with reading images from a file. Familiarize yourself with writing images to a file. Familiarize yourself with displaying/printing images. Improve your skills with manipulating arrays. Improve your understanding of constructors, destructors, and copy-constructors. Improve your skills with operator overloading. Learn to document and describe your programs.
3
Image Datatype Functions Read an image from a file Save an image to a file. Get the info of an image. Set the value of a pixel. Get the value of a pixel. Extract a region of interest (ROI) from an image. Compute the mean gray-level value of an image. sEnlarge an image by some factor s sShrink an image by sine factor s Reflect an image in the horizontal or vertical derections.
4
Image Type Functions (cont’d) tTranslate an image by some amount t theta.Rotate an image by some angle theta. Compute the sum of two images. Compute the difference of two images. Compute the negative of an image.
5
Image Type Specification class Image { public: constructor //default - no parameters constructor //with parameters copy_constructor operator= //overload assignment getImageInfo getPixelVal setPixelVal inBounds getSubImage meanGray enlargeImage
6
Image Type Specification (cont’d) 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; };
7
readImage(fileName, image) 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. Not a member function
8
writeImage(fileName, image) Writes out an image to a file in PGM format. Not a member function
9
getImageInfo(noRows, noCols, maxVal) It returns the height (no of rows) and width (no of columns) of the image. Also, it returns the max gray-level value allowed (i.e.,255) These values should be returned using “call by reference”
10
int getPixelVal(r, c) 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) 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
bool inBounds(r, c) Returns true if the pixel (r, c) is inside the image..
13
getSubImage(Ulr, Ulc, LRr, LRc, oldImage) It crops a rectangular subimage from the input image. It is useful for limiting the extent of image processing operations to some small part of the image. The subimage can be defined by the coordinates of its upper-left (UL) and lower-right (LR) corners newImage.getSubimage( xxx )
14
int meanGray() Computes the average gray-level value of an image. Returns the value as “int” (truncate the result)
15
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
16
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.
17
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
18
shrinkImage (cont’d) Sample every s-th pixel in the horizontal and vertical dimensions and ignore the others. Most easily implemented by iterating over pixels of the output image and computing the coordinates of the corresponding input image pixel.
19
reflectImage(flag, oldImage) Reflects the input image along the horizontal or vertical directions. vertical reflection
20
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
21
operator+ (image addition) Computes the sum of two given images. It is used to combine the information in two images. You can implement a simple image morphing algorithm ! formula: + =
22
operator- (image subtraction) Computes the difference of two given images. Useful for change detection. Consider absolute difference: - =
23
negateImage() Computes the negative of an image. This can be done using the following transformation
24
translateImage(t, oldImage) Translates the input image by some amount t. The translation process is performed with the following equations: 32 x 32 translation
25
rotateImage(theta, oldImage) Rotates the input image by some angle theta. The rotation process requires the use of the following equations: -45 degrees rotation (about the center of the image) theta>0: counter- clockwise about (0,0)
26
rotateImage(cont’d) Equations to rotate an image about its center : Practical problems: –consider rotating pixel (0,100) by 90 degrees: –consider rotating pixel (50,0) by 35 degrees:
27
rotateImage(cont’d) Possible solutions: –ignore pixels whose coordinates fall outside the range. –find nearest neighbors to and The rotated image can contain numerous “holes” where no value was computed for a pixel !! original rotated
28
Questions accompanying the assignments Each assignment contains a number of questions that you must answer. These questions are worth 10% of the assignment grade. Answering these questions does not require prior knowledge of image processing. Your are expected to spend some time thinking about these questions. Reasonable answers will receive full points … Interesting ideas which are implemented and demonstrated will get extra credit !!
29
Useful Tips Learn how to use the debugger: –Very important for debugging your programs efficiently ! –There is information in the course’s webpage Learn how to use makefiles: –Very useful when your application is split over many files. –There is information in the course’s webpage.
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.