void OnCorrelationTileImageViewMouseMoveHandler(TiledImageView sender, TiledImageViewMouseEventArgs args) { if (!this.knownOverlapCorrelatorOptionPanel.SelectStartTile.Checked) return; this.startPosition = args.VirtualAreaPosition; Point pt = new Point((int) this.startPosition.X, (int) this.startPosition.Y); this.startTile = FindTileAroundPoint(pt); sender.Invalidate(); }
private void DrawPreviouslyPlacedTiles(CorrelationTile tile) { this.BackgroundImage.Clear(); // Paste the previous placed images (correlated) onto the temporary (bg) image foreach (CorrelationTile t in this.CorrelationTiles) { if (t.PerformedCorrelation == false) continue; if (!t.BoundsRelativeToMosaic.IntersectsWith(tile.BoundsRelativeToMosaic)) continue; // FreeImageAlgorithmsBitmap fib = Tile.LoadFreeImageBitmapFromFile(t.Tile.FilePath); // fib.ConvertToStandardType(true); FreeImageAlgorithmsBitmap fib = TileImage(t.Tile); // Paste first image. We blend as it may improve the correlation. try { this.BackgroundImage.PasteFromTopLeft(fib, t.CorrelatedBoundsRelativeToOrigin.Location, true); } catch (FreeImageException) { this.SendFeedback("Tile positions do not intersect for pasting together" + Environment.NewLine , Color.Red); } finally { fib.Dispose(); } } }
private List<CorrelationTile> GetFourBorderingTiles(CorrelationTile tile) { // Here we filter the previous placed tile list so they are sorted to the overlap // with the largest area is first. // The overalp must greater than 25% in one direction // We than return the first 4, which are probably the ones above, below, left and right List<CorrelationTile> tiles = new List<CorrelationTile>(); foreach (CorrelationTile t in this.CorrelationTiles) { if (tile.Equals(t)) continue; if (t.PerformedCorrelation == false) continue; if (t.Tile.IsAdjusted == false) continue; if (t.Tile.IsDummy) continue; if (t.Tile.Bounds.IntersectsWith(tile.Tile.Bounds)) { Rectangle intersection = t.Tile.Bounds; intersection.Intersect(tile.Tile.Bounds); if (intersection.Width < 0.25 * tile.Tile.Width && intersection.Height < 0.25 * tile.Tile.Height) { continue; } tiles.Add(t); } } if (tiles.Count == 0) return null; tiles.Sort(new TileIntersectionComparer(tile)); // We now, after this line, will have the tiles with the largest intersection areas tiles = tiles.GetRange(0, Math.Min(tiles.Count, 4)); return tiles; }
protected override void CorrelationStarted() { if (this.knownOverlapCorrelatorOptionPanel.Filter == FiltersEnum.GenericEdgeDetection) KernalBasedOverlapCorrelator.Prefilter = new CorrelationPrefilter(FreeImageAlgorithmsBitmap.EdgeDetect); this.KernelMinSizeMicrons = this.knownOverlapCorrelatorOptionPanel.StripSize; this.SearchMinSizeMicrons = this.knownOverlapCorrelatorOptionPanel.SearchSize; this.channel = this.knownOverlapCorrelatorOptionPanel.Channel; this.knownOverlapCorrelatorOptionPanel.SelectStartTile.Checked = false; this.startTile = null; }
// If quick is true the the tile is correlated with only the previously placed // tile that is overlapping by the largest area. quick is opposite to SearchAllEdges private bool CorrelateTileWithPreviousPlacedTiles(CorrelationTile tile, bool quick) { bool success = false; // Here we keep a reference to the one that correlates best. double measure = 0.0; int count = 0; double[] measures = new double[4]; Point[] points = new Point[4]; if (tile.DontCorrelate) return success; // Return max of four tiles List<CorrelationTile> overLappingTiles = GetFourBorderingTiles(tile); tile.PerformedCorrelation = true; // FreeImageAlgorithmsBitmap fib = tile.Tile.LoadFreeImageBitmap(); // fib.ConvertToStandardType(true); FreeImageAlgorithmsBitmap fib = TileImage(tile.Tile); if (overLappingTiles == null || overLappingTiles.Count < 1) { success = false; this.NumberOfFailedCorrelations++; tile.CorrelationFailed = true; this.SendTileCorrelated(tile, tile.Tile.Bounds, fib, false); return false; } if (quick) // just use the first of these 4 bordering tiles { overLappingTiles = overLappingTiles.GetRange(0, 1); } if (overLappingTiles != null) { foreach (CorrelationTile t in overLappingTiles) { success = false; Point pt = new Point(); if (this.knownOverlapCorrelatorOptionPanel.AdjustPosBeforeCorrelate) { // We are trying to correlate tile with tile (t) // Tile t should have been correlated so here we first adjust the position of // tile so it is moved the same amount that tile t was. pt = new Point(tile.Tile.OriginalPosition.X + t.Tile.AdjustedPositionShift.X, tile.Tile.OriginalPosition.Y + t.Tile.AdjustedPositionShift.Y); tile.CorrelationPosition = pt; } measure = this.Correlate(this.BackgroundImage, fib, tile, t, false, out pt); measures[count] = measure; points[count] = pt; count++; } } // Search the array of measures, one value for each correlation performed, and find the largest int maxIndex = FindMaxIndex(measures); Color colour = Color.Red; if (measures[maxIndex] > KernalBasedOverlapCorrelator.GoodCorrelation) { colour = Color.Blue; NumberOfCorrelatedTiles++; // We have a good correlation so we need to store the correlation point tile.CorrelationPosition = tile.Tile.AdjustedPosition = points[maxIndex]; tile.CorrelationFailed = false; tile.Tile.IsAdjusted = true; this.SendTileCorrelated(tile, tile.Tile.AdjustedBounds, fib, true); success = true; SendFeedback("Correlating "); SendFeedback(String.Format("{0} x {1} ", tile.Tile.FileName, overLappingTiles[maxIndex].Tile.FileName), Color.Green); SendFeedback("resulted in a factor of "); SendFeedback(String.Format(" {0:0.00}", measures[maxIndex]), colour); SendFeedback(String.Format(" Δ {0},{1}", tile.Tile.AdjustedPositionShift.X, tile.Tile.AdjustedPositionShift.Y)); SendFeedback(Environment.NewLine, Color.Red); } else { // Set the tile adjusted position to its normal position by default. tile.Tile.AdjustedPosition = tile.CorrelationPosition; success = false; this.NumberOfFailedCorrelations++; tile.Tile.IsAdjusted = false; tile.CorrelationFailed = true; this.SendTileCorrelated(tile, tile.Tile.Bounds, fib, false); SendFeedback("Correlating "); SendFeedback(String.Format("{0} x {1} ", tile.Tile.FileName, overLappingTiles[maxIndex].Tile.FileName), Color.Green); SendFeedback("resulted in a factor of "); SendFeedback(String.Format(" {0:0.00}", measures[maxIndex]), colour); SendFeedback(String.Format(" Δ {0},{1}", tile.Tile.AdjustedPositionShift.X, tile.Tile.AdjustedPositionShift.Y)); SendFeedback(Environment.NewLine, Color.Red); } this.ThreadController.ReportThreadPercentage(this, null, NumberOfCorrelatedTiles, this.CorrelationTiles.Count); return success; }
private void TileCorrelationCompleted(string updateText, bool aborted) { this.currentTile = null; this.tiledImageViewer.Invalidate(); this.progressBar.Value = 0; if (updateText != null) this.textBox.AppendText(updateText); TimeSpan duration = this.correlator.TimeTaken(); this.timeTakenStatusLabel.Text = "Time Taken: " + duration.Hours.ToString("00") + ":" + duration.Minutes.ToString("00") + ":" + duration.Seconds.ToString("00"); MosaicWindow.MosaicInfo.IsCorrelated = true; this.useCorrelationCheckBox.Checked = true; this.mosaicWindow.CorrelationEnabled = true; // Enable start button again this.correlateButton.Enabled = true; // Update the cache file with correlation positions this.mosaicWindow.SaveCache(); }
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; }
private void OnTileCorrelationBegin(CorrelationTile tile, FreeImageAlgorithmsBitmap fib) { this.useCorrelationCheckBox.Checked = false; this.currentTile = tile; #if DEBUG FreeImageAlgorithmsBitmap fg = new FreeImageAlgorithmsBitmap(fib); fg.ConvertToStandardType(true); fg.ConvertTo24Bits(); this.debugForm.TileImageView.Image = fg.ToBitmap(); this.debugForm.BackgroundImageView.Refresh(); this.debugForm.TileImageView.Refresh(); fg.Dispose(); #endif }
private void OnTileCorrelated(CorrelationTile tile, Rectangle bounds, FreeImageAlgorithmsBitmap fib, bool success) { this.tiledImageViewer.AddTile(bounds, fib); this.tiledImageViewer.Refresh(); #if DEBUG if (success == false) { FreeImageAlgorithmsBitmap bg = new FreeImageAlgorithmsBitmap(this.correlator.BackgroundImage); bg.ConvertTo24Bits(); bg.DrawColourRect(tile.OriginalBoundsRelativeToOrigin, Color.Red, 2); this.debugForm.BackgroundImageView.Image = bg.ToBitmap(); bg.Dispose(); } this.debugForm.Refresh(); #endif }
void OnMosaicLoaded(MosaicWindow sender, MosaicWindowEventArgs args) { this.currentTile = null; this.Initialise(); SetCorrelationForCombobox(); this.tiledImageViewer.Reset(); if (this.correlator != null && this.correlator.OptionPanel != null) this.correlator.OptionPanel.Reset(this.correlator.MosaicInfo); }
protected void SendTileCorrelated(CorrelationTile tile, Rectangle correlatedBounds, FreeImageAlgorithmsBitmap fib, bool success) { if (this.ThreadController.ThreadAborted) return; Object[] objects = { tile, correlatedBounds, fib, success}; this.threadController.InvokeObject.BeginInvoke(this.TileCorrelatedHandler, objects); }
protected void SendTileCorrelatationBegin(CorrelationTile tile, FreeImageAlgorithmsBitmap fib) { if (this.ThreadController.ThreadAborted) return; Object[] objects = { tile, fib }; this.threadController.InvokeObject.BeginInvoke(this.TileCorrelationBeginHandler, objects); }