Title: Programming Assignment 1
1Programming Assignment 1
2Goals
- 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.
3Implementation
- You should implement
-
- image.h (class specification)
-
- image.cpp (class implementation)
-
- driver.cpp (application or client)
4image.h
- class Image
- public
- constructor //parameter less
- constructor //with parameters
- copy_constructor
- operator
- getImageInfo
- getPixelVal
- setPixelVal
- getSubImage
- meanGray
5image.h (contd)
- 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
6First ...
- Carefully implement the following functions
- constructor
- destructor
- copy-constructor
- assignment
7readImage(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.
8writeImage(fileName, image) (client function
has been provided)
- Writes out an image to a file in PGM format.
9getImageInfo(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.
10int 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.
11setPixelVal(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.
12getSubImage(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.
13int meanGray()
- Computes the average gray-level value of an
image. - Returns the value as int (i.e., truncate the
result)
14enlargeImage(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
15enlargeImage (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.
Example s 2
16shrinkImage(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
17shrinkImage (contd)
- 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
18reflectImage(flag, oldImage)
- Reflects the input image along the horizontal or
vertical directions.
vertical reflection
19reflectImage (contd)
- Reflection along either direction can be
performed by simply reversing the order of pixels
in the rows or columns of the image
20operator (image addition)
- Computes the weighted sum of two images.
- You can use it for simple image morphing !
21operator- (image subtraction)
- Computes the difference of two given images.
- Useful for change detection.
- Compute absolute difference
-
22negateImage()
- Computes the negative of an image.
- This can be done using the following
transformation
negative
23translateImage(t, oldImage)
- Translates the pixel locations by some amount t.
- Translation can be performed using the equations
-
-
32 x 32
translation
24rotateImage(theta, oldImage)
- Rotates the input image by some angle theta about
(0,0). - Rotation uses the following equations
if theta gt 0 counter- clockwise about (0,0)
if theta lt 0 clockwise about (0,0)
25rotateImage (contd)
- Equations to rotate an image about any point
-45 degrees rotation (about the center of
the image)
26rotateImage (contd)
- Practical problems
- consider rotating pixel (0,100) by 90 degrees
- consider rotating pixel (50,0) by 35 degrees
Ignore pixels whose coordinates fall outside the
range. Find nearest neighbors to and
27rotateImage(contd)
- Serious problem the rotated image could contain
numerous holes where no value was computed for
a pixel !! -
- original rotated
28Extra 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 !!
29Useful 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.