Template matching program to find an image within an image The program I've made is a template matching program which finds an image within an image - where's Wally/Waldo! I've complete the program and all works fine despite being very slow (around a minute). I would appreciate some advice on how I could improve the following code. I'm happy to share the rest of the source code if anyone is interested.

        #include "Matrix.h"

    Matrix::Matrix(int sizeR, int sizeC, double val){
    M = sizeR; // Set number of rows.
    N = sizeC; // Set number of cols.
    data = new double[sizeR * sizeC]; 
    }

    Matrix::Matrix(int sizeR, int sizeC, double* inputData){    
    M = sizeR;
    N = sizeC;

    data = new double[sizeR * sizeC]; // Set data sixe
    for (int i = 0; i &lt; sizeR * sizeC; i++) //  input data store
    {
        data[i] = inputData[i];
    }
    }

    Matrix::~Matrix(){
    delete[] data;
    data = 0;
    }

    Matrix::Matrix(const Matrix&amp; existingMatrix){
    M = existingMatrix.M;
    N = existingMatrix.N;

    data = new double[M * N]; // Allocate memory
    for (int i = 0; i &lt; M * N; i++) 
    {
        data[i] = existingMatrix.data[i];
    }
    }

         Matrix Matrix::getBlock(int width, int height, int r, int c, int yMove,     int xMove) const{  
    int startCol = r * width;
    int startRow = c * height;
    int cols = width;
    int rows = height;
    Matrix R(rows, cols, 0.0);

    for (int i = 0; i &lt; rows; i++) {

        for (int ii = 0; ii &lt; cols; ii++) {

            R.setElmt(i, ii, getElmt(i + startRow + yMove, ii + startCol + xMove));
        }
        }return R;
     }

    void Matrix::setBlock(int r, int c, int yMove, int xMove, const Matrix&amp; blockValues){
    int rows = blockValues.M;
    int cols = blockValues.N;
    int startCol = c * blockValues.N;
    int startRow = r * blockValues.M;

    for (int i = 0; i &lt; rows; i++) // Rows
    {
        for (int ii = 0; ii &lt; cols; ii++) //Cols
        {
            this-&gt;setElmt(i + startRow + yMove, ii + startCol +     xMove, blockValues.getElmt(i, ii));
        }
    }
}

double Matrix::getElmt(int i, int j) const{
    return data[i * N + j];
}

void Matrix::setElmt(int i, int j, double val)
{
    data[i * N + j] = val;
}

int Matrix::getCol() const{
    return N;
}

int Matrix::getRow() const{
    return M;
}

Matrix Matrix::operator-(double value){
    double val = 0;
    Matrix C(M, N, val);

    for (int i = 0; i &lt; M; i++) // Rows
    {
        for (int j = 0; j &lt; N; j++) // Cols
        {
            val = data[i * N + j] - value;
            C.setElmt(i, j, val);
        }
    }return C;
}

Matrix Matrix::operator*(const Matrix&amp; B){
    double val = 0;
    Matrix C(M, N, val);

    for (int i = 0; i &lt; M; i++) // Rows
    {
        for (int j = 0; j &lt; N; j++) // Cols
        {
            val = data[i * N + j] * B.getElmt(i, j);
            C.setElmt(i, j, val);
        }
    }
    return C;
}

Matrix&amp; Matrix::operator=(const Matrix&amp; B){
    if (this == &amp;B) {
        return *this;
    }
    else {
        delete[] data;

        M = B.getRow();
        N = B.getCol();
        data = new double[M * N];

        for (int i = 0; i &lt; M; i++) // Rows
        {
            for (int j = 0; j &lt; N; j++) // Cols
            {
                setElmt(i, j, B.getElmt(i, j));
            }
        }
    }
}

double Matrix::getSum() const{
    double result = 0.0;

    for (int i = 0; i &lt; M * N; i++) {
        result += data[i];
    }
    return result;
}
This code seems very straightforward and easy to read, making it relatively easy to maintain. Here are some ways you could improve it further.
Naming
I would suggest working a bit on your member variable and local variable names. While in math we often use M and N as matrix width and height, it can be confusing which is which, and it can be difficult to communicate which you're talking about when speaking because they sound so similar. I would recommend using width and height as the variable names instead.
Using i and j for loop counters is a well-understood convention and just fine. I would caution against using ii (or iii and iiii as you had in an earlier version of the code) because it's too easy to confuse it with i or make a typo and end up with a subtle bug in your code. (I've done that before!)
Using const
The arguments to almost all of your methods remain unchanged in the method. When that happens, they should be marked as const to let a reader know they won't change. It also helps the compiler in a number of ways.
Performance
You mentioned that it's taking a long time to run. The best way to figure out why is to profile it and see where the slowdown is. I have a guess that it's probably due to the large numbers of copies that the code makes, particularly in getBlock(). I can see 2 ways to improve them:

Don't make a function-call per element you need to copy. Instead use a block copy function like the standard-C library memcpy() function for each row or sub-row you need to copy. This will be much faster than what you're currently doing.
Don't copy anything at all. You could modify the Matrix class to keep track of the width of a row separate from the number of elements in the row. This would allow you to create a new Matrix that just indexed into a current one. You would also need to make sure not to delete the array from that type of matrix, so you'd need another member variable - a bool that says whether it owns the array or not. It's slightly more housekeeping, but the result is that your copies now become a pointer assignment and a little bit of housekeeping instead of actual copies. They almost disappear!