public override void Compare(ByteWrapper image1, ByteWrapper image2)
        {
            var bm1 = new BitmapWrapper(ImageConvert.ReturnBitmap(image1.bytes));
            bm1.sequenceNumber = logging.imagesReceived - 2;
            var bm2 = new BitmapWrapper(ImageConvert.ReturnBitmap(image2.bytes));
            bm2.sequenceNumber = logging.imagesReceived - 1;

            PixelMatrix matrix = new PixelMatrix();
            matrix.LinkCompare = settings.linkCompare;
            if (settings.searchHeight > 0) { matrix.SearchHeight = settings.searchHeight; }
            if (settings.searchWidth > 0) { matrix.SearchWidth = settings.searchWidth; }
            if (settings.horizontalPixelsToSkip > 0) { matrix.WidthSearchOffset = settings.horizontalPixelsToSkip + 1; }
            if (settings.verticalPixelsToSkip > 0) { matrix.WidthSearchOffset = settings.verticalPixelsToSkip + 1; }

            if (settings.linkCompare && Comparison != null)
            {
                matrix.Populate(Comparison, bm2);
            }
            else
            {
                matrix.Populate(bm1, bm2);
            }

            double sumChangedPixels = matrix.SumChangedPixelsPositive;

            //keep adding for threshold calculation, set the threshold, or monitor
            if (ThresholdSet)
            {
                //now scanning, compare the two images and see what the difference is
                if (sumChangedPixels > pixelChangeThreshold)
                {
                    OnMotionAsync(image1, image2);
                }
            }
            else if (!ThresholdSet && pixelChange.Count < ControlImageNumber)
            {
                pixelChange.Add(sumChangedPixels);
            }
            else
            {
                SetThreshold(); //enough images received to set the threshold and start monitoring
            }

            Comparison = matrix.Comparator;

            if (logging.LoggingOn && logging.matrices != null) { logging.matrices.Add(matrix); }

            //clean up the memory
            matrix.Dispose();
            bm1.bitmap.Dispose();
            bm2.bitmap.Dispose();
            bm1 = null;
            bm2 = null;

        }//Compare
        public void Grid()
        {
            PixelMatrix matrix = new PixelMatrix();
            matrix.GridSystemOn = true;
            matrix.Populate(@"d:\temp\MotionSensor\2.2\test_101.jpg", @"d:\temp\MotionSensor\2.2\test_128.jpg");

            Assert.IsNotNull(matrix.imageGrid.Columns);
            Assert.IsTrue(matrix.imageGrid.Columns.Count == 4);
            Assert.IsTrue(matrix.imageGrid.Columns[0].grids.Count == 4);
            Assert.IsTrue(matrix.imageGrid.Columns[1].grids.Count == 4);
            Assert.IsTrue(matrix.imageGrid.Columns[2].grids.Count == 4);
            Assert.IsTrue(matrix.imageGrid.Columns[3].grids.Count == 4);
        }
        public void GridPopulation()
        {
            PixelMatrix matrix = new PixelMatrix();
            matrix.GridSystemOn = true;
            matrix.Populate(@"d:\temp\MotionSensor\2.2\test_101.jpg", @"d:\temp\MotionSensor\2.2\test_128.jpg");

            for(int i = 0; i < matrix.imageGrid.Columns.Count; i++)
            {
                for(int n = 0; n < matrix.imageGrid.Columns[i].grids.Count; n++)
                {
                    Assert.IsTrue(matrix.imageGrid.Columns[i].grids[n].change != 0);
                }                     
            }
        }//GridPopulation
        public ImageGrid ThresholdImage{get; private set;} //the thresholds, per grid

        public override void Compare(ByteWrapper image1, ByteWrapper image2)
        {
            var bm1 = new BitmapWrapper(ImageConvert.ReturnBitmap(image1.bytes));
            var bm2 = new BitmapWrapper(ImageConvert.ReturnBitmap(image2.bytes));

            PixelMatrix matrix = new PixelMatrix();
            if (settings.searchHeight > 0) { matrix.SearchHeight = settings.searchHeight; }
            if (settings.searchWidth > 0) { matrix.SearchWidth = settings.searchWidth; }
            if (settings.linkCompare) { matrix.LinkCompare = true; }
            matrix.GridSystemOn = true;
            matrix.Populate(bm1, bm2);

            double sumChangedPixels = matrix.SumChangedPixels;

            //keep adding for threshold calculation, set the threshold, or monitor
            if (ThresholdSet)
            {
                //do the motion detection
                for(int i = 0; i < ThresholdImage.Columns.Count; i++)
                {
                    for(int n = 0; n < ThresholdImage.Columns[i].grids.Count; n++)
                    {
                        if(matrix.imageGrid.Columns[i].grids[n].change > ThresholdImage.Columns[i].grids[n].threshold)
                        {
                            OnMotion(image1, image2, ThresholdImage.GridNumber(i, n));
                            return;
                        }
                    }
                }
            }
            else if (!ThresholdSet && gridImages.Count < ControlImageNumber)
            {
                gridImages.Add(matrix.imageGrid); //keep adding for the later threshold calculation
            }
            else
            {
                SetThreshold(); //enough images received to set the threshold and start monitoring
            }

            Comparison = matrix.Comparator;

            //clean up the memory
            matrix.Dispose();
            bm1.bitmap.Dispose();
            bm2.bitmap.Dispose();
            bm1 = null;
            bm2 = null;

        }//Compare