290 likes | 393 Views
Programming Assignment 1. CS308 Data Structures. 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 .
E N D
Programming Assignment 1 CS308 Data Structures
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.
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. • Enlarge an image by some factors • Shrink an image by sine factor s • Reflect an image in the horizontal or vertical derections.
Image Type Functions (cont’d) • Translate an image by some amount t • 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.
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
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; • };
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
writeImage(fileName, image) • Writes out an image to a file in PGM format. • Not a member function
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”
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.
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.
bool inBounds(r, c) • Returns true if the pixel (r, c) is inside the image..
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 )
int meanGray() • Computes the average gray-level value of an image. • Returns the value as “int” (truncate the result)
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
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.
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
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.
reflectImage(flag, oldImage) • Reflects the input image along the horizontal or vertical directions. vertical reflection
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
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: + =
operator- (image subtraction) • Computes the difference of two given images. • Useful for change detection. • Consider absolute difference: - =
negateImage() • Computes the negative of an image. • This can be done using the following transformation
translateImage(t, oldImage) • Translates the input image by some amount t. • The translation process is performed with the following equations: • 32 x 32 translation
rotateImage(theta, oldImage) • Rotates the input image by some angle theta. • The rotation process requires the use of the following equations: theta>0: counter-clockwise about (0,0) -45 degrees rotation (about the center of the image)
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:
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
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 !!
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.