In this course you will be performing different manipulations on images. This library was written to remove some of the more tedius and error-prone aspects from the labs.
The main structure in this library is the Image
class and some variations, the ComplexImage
and ComplexFFTImage
.
The Image
class is for images whose pixels are integer-valued, from 0 through 255.
The ComplexImage
class (used in Lab 2) is for images whose pixels have complex floating-point values.
the ComplexFFTImage
class (used in Lab 3) is the same as ComplexImage
except it has built-in routines to Fourier-transform and untransform the image.
In addition to using the course-specific structures, you will also use the Complex
class, which is an instance of the C++ Standard Template Library's built-in support for complex numbers.
The following documentation will give you enough information to complete all of the labs in this course. You are encouraged to look at the source code of the library.
The following line will create an Image
called myImage
:
Image myImage;
To load the contents of inPicture.png
into myImage
type:
myImage.LoadPng ("inPicture.png");
To save the contents of myImage
into outPicture.png
type:
myImage.SavePng ("outPicture.png");
To resize myImage
to be x
by y
pixels, type:
myImage.Resize (x, y);
To get the grey value of the pixel at (x,y)
and store it in z
, type:
z = myImage.Pixel (x, y);
To set the grey value of the pixel at (x,y)
to z
, type:
myImage.Pixel (x, y) = z;
Note that for setting and getting pixel values, if myImage
is a ComplexImage
or ComplexFFTImage
then z
must be of type Complex
.
The STL that comes with C++ includes support for complex variables.
In this class, the Complex
type represents floating-point complex variables.
Here are some of their more useful features:
To create a complex variable z
initialized to zero, type:
Complex z;
To create a complex variable w
initialized to a+bi
, type:
Complex w (a, b);
To access the real or complex parts of z
, type:
z.real ()
or z.imag ()
Note that you can NOT write to these, typing z.real () = 3
will not compile.
If you want to set z
to a + bi
, you will have to type:
z = Complex (a, b);
To set x
to the magnitude of z
, type:
x = abs(z);
Note that in many cases, the double
type and Complex
types are compatible.
That is you can add, multiply, divide, and assign Complex
variables with double
variables.
Therefore, the following code block is valid and will do what you expect it to do.
Complex z (3, 3);
double x = 3;
z /= x; // sets z to 1+i
z = x; // sets z to 3