CMP2090M? ?Object? ?Oriented?
?Programming? ?Assignment Report

 

Introduction

We Will Write a Custom Essay Specifically
For You For Only $13.90/page!


order now

?(Your? ?understanding? ?of? ?the? ?aims? ?of?
?the? ?problem.)

The aim of this assignment was to produce a program written
in the C++ language that was capable of un-shuffling a shuffled image, the
image being the old University of Lincoln logo. This was to be achieved with
the implementation of the “Nearest Neighbour Search” while using good
object-oriented principles and practice. The image input would be a text file
containing the 0 – 255 representing a greyscale colour. The output of the
finished unshuffled logo was to be in a PGM format with the ability to view the
image using an online converter to JPG. The assignment also includes a part to
convert a noisy version of the image that requires translating into a binary
image. This assignment is broken down into the two parts the first objective is
to unshuffle the 512 by 512 logo image which is broken down into blocks of 32
by 32. Then there is the second part which involves an unshuffled noisy image
of the logo. This second objective involves cleaning the noisy image by using a
threshold. Then all the blocks in the cleaned image will need to be compared
against all the blocks in the shuffled image. For a complete new unshuffled
image of the logo a new matrix will then need to be created. This is for the
block from the shuffled image to go to its correct location from the cleaned
block into the new image created.      

Methods

?(Design? ?(e.g.? ?the? ?OO? ?principles? ?used,? ?the?
?interface? ?of? ?your? ?library,? ?that  is,? ?the? ?.h? ?file? ?with?
?Class? ?definitions)? ?and? ?Pseudo-Code.)

The project contains three classes: main.cpp, Matrix.cpp
and BinaryImage.cpp with two .h files Matrix.h and BinaryImage.h.

Main Class

The project’s Main class is the entry for program to start
at, it contains:

·        
The
methods for reading in the txt files the shuffled image and the noisy image.

·        
The
Nearest Neighbour Search algorithm.

·        
The
Summed Squared Difference

·        
And
the method for writing out the complete unshuffled image to PGM format

 

 

 

 

Matrix Class

The project’s Matrix class contains methods that are
designed to handle the data as the class has been designed to hold the data of
the images. This class has been created to make the handling of the data
easier. As images are two dimensional matrices the class treats one-dimensional
arrays as two-dimensional arrays. The class also has a header file, as it uses
templates the class declaration and member functions need to be in the same
header file this allows them to be linked together correctly.

Within the specifications of the assignment it stated the
matrix class should contain:

·        
Constructors

·        
A
destructor

·        
Operator
overloads

·        
Matrix
operations

Constructors

The program uses three different constructors in the matrix
class, a blank constructor, a constructor that takes two integers and a double
value and another constructor that takes two constructors that takes two
integers and a double that points to an array.

Constructor 1

The blank constructor has been made so that it can used for
creating placeholder matrixes.

Constructor 2

The constructor takes M, N and an input data value, then will
set the inputted M and N to the M and N of the object then allocate memory to
data and set every location in that memory to the input value.

M = input row

N = input column

Data = new double M * N   

For (i = 0; i < M * N; i++) { datai = input_datai } Constructor 3 The copy constructor will set the matrix its running off, equal to the inputted matrix while copying the values over.   Destructor The destructor in the program is used when an object goes out of scope. This code is used to make sure that a large amount of memory isn't used. It does this by deleting the data that the matric class has used and created.       Operator Overload -   The operator overload for the - is declared virtual so that it can be overridden for later so that they will be able to return a matrix. The operator will take one argument a constant Matrix reference. Then the method will declare an array of matrix temp and allocate it M * N of allotted memory and will then go through every element of each matrix and will subtraction.   temp.data = new double temp.M*temp.N   for (i = 0; i < temp.M * temp.N; i++) { temp.datai = datai - datai } return temp   Operator Overload = The purpose of the operator overload for the = is to set the value of one matrix to another matrix. The operator achieves this by deleting the data of the first matrix. Then it will set the matrix M and N of the first matrix to the second matrix's M and N. It then allocates the memory sized M * N for data and sets each of its values in data equal to the values in the second matrix's data. Once this has been done the operator will then go on to return the pointer of the matrix.   Operator Overload () The () operator overload takes two ints i and j coordinates and then returns a value in that position. It does this by returning a value from theData using i * N + j formula.   Sum of Squared Difference       The sum of squared difference method works by taking two blocks then subtracts one from the other one and then returns the sum of the squared values from the subtraction. The method returns a score of the Matrix in the form of a double