public TemplateMatchingResults FindTemplateInImageExhaustively()
        {
            TemplateMatchingResults results = new TemplateMatchingResults();
            int i = 0;
            int divisor;
            similarityMax = 0f;
            ExhaustiveTemplateMatching exhaustiveTemplateMatching = new ExhaustiveTemplateMatching(threshold);
            results.MatchFound = false;
            while ((results.MatchFound == false) && (i < pyramidLevels))
            {
                divisor = pyramidLevels - i;
                if (divisor != 0){
                    Rectangle sourceImageRegion = new Rectangle(0, 0, sourceImage.Width / divisor, sourceImage.Height / divisor);
                    matchings = exhaustiveTemplateMatching.ProcessImage(sourceImage, templateImage, sourceImageRegion);

                    foreach (TemplateMatch m in matchings){
                        if (m.Similarity > threshold){
                            results.MatchFound = true;
                            results.NumberOfMatches++;
                            if (m.Similarity > similarityMax){
                                similarityMax = m.Similarity;
                            }
                        }
                        else {
                            results.MatchFound = false;
                        }
                    }
                }
                i++;
            }
            results.SimilarityMax = similarityMax;
            return results;

        }
         public TemplateMatchingResults FindTemplateInROI()
        {
            TemplateMatchingResults results = new TemplateMatchingResults();
            similarityMax = 0f;
            ExhaustiveTemplateMatching exhaustiveTemplateMatching = new ExhaustiveTemplateMatching(threshold);
            matchings = exhaustiveTemplateMatching.ProcessImage(sourceImage, templateImage, regionOfInterest);
            BitmapData data = sourceImage.LockBits(
                            new Rectangle(0, 0, sourceImage.Width, sourceImage.Height),
                            ImageLockMode.ReadWrite, sourceImage.PixelFormat);
            foreach (TemplateMatch m in matchings)
            {
                Drawing.Rectangle(data, m.Rectangle, Color.Red); // Adding rectangles in the areas of possible matches
                // do something else with matching
                if (m.Similarity > similarityMax)
                {
                    similarityMax = m.Similarity;
                }
                results.NumberOfMatches++;
            }
            sourceImage.UnlockBits(data);
            sourceImage.Save("SourceImage_Processed.bmp", ImageFormat.Bmp); //Saving the image.
         
            if (similarityMax >= threshold)
            {
                results.MatchFound = true;
            }
            else {
                results.MatchFound = false;
            }

            results.SimilarityMax = similarityMax;
            return results;
        }