Title: Programming Assignment 1
1Programming Assignment 1
2Goals
- 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.
3Image 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 factor s
- Shrink an image by sine factor s
- Reflect an image in the horizontal or vertical
derections.
4Image Type Functions (contd)
- 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.
5Image Type Specification
- class Image
- public
- constructor //default - no parameters
- constructor //with parameters
- copy_constructor
- operator //overload assignment
- getImageInfo
- getPixelVal
- setPixelVal
- inBounds
- getSubImage
- meanGray
- enlargeImage
6Image Type Specification (contd)
- 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
7readImage(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
8writeImage(fileName, image)
- Writes out an image to a file in PGM format.
- Not a member function
9getImageInfo(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
10int 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.
11setPixelVal(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.
12bool inBounds(r, c)
- Returns true if the pixel (r, c) is inside the
image..
13getSubImage(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 )
14int meanGray()
- Computes the average gray-level value of an
image. - Returns the value as int (truncate the result)
15enlargeImage(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
16enlargeImage (contd)
- 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.
17shrinkImage(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
18shrinkImage (contd)
- 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.
19reflectImage(flag, oldImage)
- Reflects the input image along the horizontal or
vertical directions.
vertical reflection
20reflectImage (contd)
- Reflection along either direction can be
performed by simply reversing the order of pixels
in the rows or columns of the image
21operator (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
22operator- (image subtraction)
- Computes the difference of two given images.
- Useful for change detection.
- Consider absolute difference
-
23negateImage()
- Computes the negative of an image.
- This can be done using the following
transformation
24translateImage(t, oldImage)
- Translates the input image by some amount t.
- The translation process is performed with the
following equations -
32 x 32 translation
25rotateImage(theta, oldImage)
- Rotates the input image by some angle theta.
- The rotation process requires the use of the
following equations
thetagt0 counter-clockwise about (0,0)
-45 degrees rotation (about the center of
the image)
26rotateImage(contd)
- 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
27rotateImage(contd)
- 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
28Questions 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 !!
29Useful Tips
- Learn how to use the debugger
- Very important for debugging your programs
efficiently ! - There is information in the courses webpage
- Learn how to use makefiles
- Very useful when your application is split over
many files. - There is information in the courses webpage.