public double Correlate(FreeImageAlgorithmsBitmap backgroundImage, FreeImageAlgorithmsBitmap fib, CorrelationTile tile1, CorrelationTile tile2, bool randomise, out Point pt) { this.backgroundIntersectArea = Rectangle.Empty; this.searchArea = Rectangle.Empty; this.searchAreaWithinMosaic = Rectangle.Empty; double measure = 0.0; pt = new Point(); // Find the intersection between the tile and the background drawn bounds. this.backgroundIntersectArea = Rectangle.Intersect(tile1.CorrelatedBoundsRelativeToOrigin, tile2.CorrelatedBoundsRelativeToOrigin); if (this.backgroundIntersectArea == Rectangle.Empty) { SendFeedback(String.Format("{0} and {1} did not intersect ?", tile1.Tile.FileName, tile2.Tile.FileName) + Environment.NewLine, Color.Red); return(0.0); } // determine the area over which to perform the correlation // defines the maximum shift allowed of the new tile. this.searchArea = this.SearchBounds(this.backgroundIntersectArea, randomise); // find the kernel area in the bg image this.kernelAreaWithinBackground = this.KernelBounds(this.backgroundIntersectArea, this.searchArea, randomise); // locate the area in the new image this.kernelArea = this.kernelAreaWithinBackground; this.kernelArea.X -= tile1.CorrelatedBoundsRelativeToOrigin.X; this.kernelArea.Y -= tile1.CorrelatedBoundsRelativeToOrigin.Y; // Call start correlation delegate, for screen update this.SendTileCorrelatationBegin(tile1, fib); if (KernalBasedOverlapCorrelator.prefilter == null) { backgroundImage.KernelCorrelateImageRegions(fib, backgroundIntersectArea, kernelArea, this.searchArea, out pt, out measure); } else { backgroundImage.KernelCorrelateImageRegions(fib, backgroundIntersectArea, kernelArea, this.searchArea, KernalBasedOverlapCorrelator.prefilter, out pt, out measure); } if (measure > KernalBasedOverlapCorrelator.GoodCorrelation) { pt = CorrelationTile.TranslateBackgroundPointToMosaicPoint(pt); return(measure); } if (tile1.NumberOfAtemptedCorrelations < CorrelationTile.MaxNumberOfCorrelationAttempts) { tile1.NumberOfAtemptedCorrelations++; return(this.Correlate(backgroundImage, fib, tile1, tile2, this.knownOverlapCorrelatorOptionPanel.RandomKernelSearch, out pt)); } else { // If we are debugging lets pause the thread for closer inspection #if DEBUG this.CorrelationPause(); #endif } return(measure); }