}//Compare /// <summary> /// Creates a dummy threshold image, used for testing and benchmarking /// </summary> public void CreateDummyThreshold(int width, int height) { ThresholdImage = new ImageGrid(width, height); for(int i = 0; i < width; i++) { ThresholdImage.Columns.Add(new GridColumn()); for (int n = 0; n < height; n++) { Random random = new Random(); double buffer = ReturnBuffer(random.Next(25000000)); ThresholdImage.Columns[i].grids.Add(new Grid()); ThresholdImage.Columns[i].grids[n].threshold = Math.Round(buffer, 0); } } }
/// <summary> /// Does the actual population of the Pixel Matrix /// </summary> private void DoPopulate() { Columns = new List <PixelColumn>(); Comparator = null; if (LinkCompare) { Comparator = new List <PixelColumn>(); } //set the search dimensions if (SearchWidth <= 0) { SearchWidth = image2.bitmap.Width; } if (SearchHeight <= 0) { SearchHeight = image2.bitmap.Height; } //set thepixel scanning dimensions if (WidthSearchOffset < 1) { WidthSearchOffset = 1; } if (HeightSearchOffset < 1) { HeightSearchOffset = 1; } if (GridSystemOn) { imageGrid = new ImageGrid(SearchWidth, SearchHeight); } //set some grid and comparator variables here, for scope reasons GridColumn gridColumn = null; Grid grid = null; PixelCell comparatorCell = null; PixelColumn comparatorColumn = null; //look at every pixel in each image, and compare the colours for (int i = 0; i < SearchWidth; i += WidthSearchOffset) { PixelColumn column = new PixelColumn(); if (LinkCompare) { comparatorColumn = new PixelColumn(); } //set a new grid column, if required if (GridSystemOn) { if (i == 0) { gridColumn = new GridColumn(); } else if (i % imageGrid.GridWidth == 0) { imageGrid.Columns.Add(gridColumn); gridColumn = new GridColumn(); } } for (int n = 0; n < SearchHeight; n += HeightSearchOffset) { PixelCell cell = new PixelCell(); if (LinkCompare) { comparatorCell = new PixelCell(); } //set a new grid, if required if (GridSystemOn) { if (n > 0 && n % imageGrid.GridHeight == 0 && i % imageGrid.GridWidth == 0) { gridColumn.grids.Add(grid); grid = new Grid(); } else if (n == 0 && i % imageGrid.GridWidth == 0) { grid = new Grid(); } } //get the pixel colours. image 1 pixel one either comes from image1, or the comparison PixelMatrix, if it exists Int64 image1Pixel = Comparision == null?image1.bitmap.GetPixel(i, n).Name.HexToLong() : Comparision[i].Cells[n].colour; Int64 image2Pixel = image2.bitmap.GetPixel(i, n).Name.HexToLong(); //set the comparator if (LinkCompare) { comparatorCell.colour = image2Pixel; comparatorColumn.Cells.Add(comparatorCell); } if (image1Pixel != image2Pixel) { cell.hasChanged = true; cell.change = image1Pixel - image2Pixel; if (GridSystemOn) { grid.change += cell.positiveChange; } } else { cell.hasChanged = false; } column.Cells.Add(cell); if (GridSystemOn && n + 1 == image1.bitmap.Height && i % imageGrid.GridWidth == 0) { gridColumn.grids.Add(grid); } }//height Columns.Add(column); if (LinkCompare) { Comparator.Add(comparatorColumn); } if (GridSystemOn && i + 1 == image1.bitmap.Width) { imageGrid.Columns.Add(gridColumn); } }//width }
/// <summary> /// Called when the threshold is to be set, or re-set /// takes the current range of changes and calculates threshold /// based on these ranges, and the specified sensitivity /// sets the gridImages object as each grid has its own threshold /// </summary> private void SetThreshold() { //set the threshold image ThresholdImage = new ImageGrid(gridImages[0].Columns[0].grids.Count, gridImages[0].Columns.Count); //do the calculation grid by grid for(int i = 0; i < gridImages[0].Columns.Count; i++) { ThresholdImage.Columns.Add(new GridColumn()); for(int n = 0; n < gridImages[0].Columns[i].grids.Count; n++) { List<double> gridTotals = new List<double>(); for(int k = 0; k < gridImages.Count; k++) { gridTotals.Add(gridImages[k].Columns[i].grids[n].positiveChange); } double buffer = ReturnBuffer(ReturnMax(gridTotals)); ThresholdImage.Columns[i].grids.Add(new Grid()); ThresholdImage.Columns[i].grids[n].threshold = Math.Round(buffer, 0); } }//each grid column ThresholdSet = true; }
/// <summary> /// Does the actual population of the Pixel Matrix /// </summary> private void DoPopulate() { Columns = new List<PixelColumn>(); Comparator = null; if (LinkCompare) { Comparator = new List<PixelColumn>(); } //set the search dimensions if (SearchWidth <= 0 ) { SearchWidth = image2.bitmap.Width; } if (SearchHeight <= 0 ) { SearchHeight = image2.bitmap.Height; } //set thepixel scanning dimensions if (WidthSearchOffset < 1) { WidthSearchOffset = 1; } if (HeightSearchOffset < 1) { HeightSearchOffset = 1; } if (GridSystemOn) { imageGrid = new ImageGrid(SearchWidth, SearchHeight); } //set some grid and comparator variables here, for scope reasons GridColumn gridColumn = null; Grid grid = null; PixelCell comparatorCell = null; PixelColumn comparatorColumn = null; //look at every pixel in each image, and compare the colours for (int i = 0; i < SearchWidth; i += WidthSearchOffset) { PixelColumn column = new PixelColumn(); if (LinkCompare) { comparatorColumn = new PixelColumn(); } //set a new grid column, if required if (GridSystemOn) { if (i == 0) { gridColumn = new GridColumn(); } else if (i % imageGrid.GridWidth == 0) { imageGrid.Columns.Add(gridColumn); gridColumn = new GridColumn(); } } for (int n = 0; n < SearchHeight; n += HeightSearchOffset) { PixelCell cell = new PixelCell(); if (LinkCompare) { comparatorCell = new PixelCell(); } //set a new grid, if required if (GridSystemOn) { if (n > 0 && n % imageGrid.GridHeight == 0 && i % imageGrid.GridWidth == 0) { gridColumn.grids.Add(grid); grid = new Grid(); } else if (n == 0 && i % imageGrid.GridWidth == 0) { grid = new Grid(); } } //get the pixel colours. image 1 pixel one either comes from image1, or the comparison PixelMatrix, if it exists Int64 image1Pixel = Comparision == null ? image1.bitmap.GetPixel(i, n).Name.HexToLong() : Comparision[i].Cells[n].colour; Int64 image2Pixel = image2.bitmap.GetPixel(i, n).Name.HexToLong(); //set the comparator if (LinkCompare) { comparatorCell.colour = image2Pixel; comparatorColumn.Cells.Add(comparatorCell); } if (image1Pixel != image2Pixel) { cell.hasChanged = true; cell.change = image1Pixel - image2Pixel; if (GridSystemOn) { grid.change += cell.positiveChange; } } else { cell.hasChanged = false; } column.Cells.Add(cell); if (GridSystemOn && n + 1 == image1.bitmap.Height && i % imageGrid.GridWidth == 0) { gridColumn.grids.Add(grid); } }//height Columns.Add(column); if (LinkCompare) { Comparator.Add(comparatorColumn); } if (GridSystemOn && i + 1 == image1.bitmap.Width) { imageGrid.Columns.Add(gridColumn); } }//width }