Пример #1
0
        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();
        }
Пример #2
0
        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);
        }
Пример #3
0
        public static PointF GetCentreOfTiles(List <CorrelationTile> tiles)
        {
            int left   = CorrelationTile.GetMostLeftPosition(tiles);
            int top    = CorrelationTile.GetMostTopPosition(tiles);
            int width  = CorrelationTile.GetMostRightPosition(tiles) - left;
            int height = CorrelationTile.GetMostBottomPosition(tiles) - top;

            return(new PointF(left + width / 2.0f, top + height / 2.0f));
        }
Пример #4
0
        private void CircularSortTiles(List <CorrelationTile> tiles)
        {
            //List<CorrelationTile> tileCopy = new List<Tile>(tiles);

            // Find centre of tiles
            PointF center = CorrelationTile.GetCentreOfTiles(tiles);

            // Sort the tile from the centre of the mosaic.
            tiles.Sort(new CorrelationTileCircularComparer(center));
        }
Пример #5
0
        protected void SendTileCorrelatationBegin(CorrelationTile tile, FreeImageAlgorithmsBitmap fib)
        {
            if (this.ThreadController.ThreadAborted)
            {
                return;
            }

            Object[] objects = { tile, fib };

            this.threadController.InvokeObject.BeginInvoke(this.TileCorrelationBeginHandler, objects);
        }
Пример #6
0
        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);
        }
Пример #7
0
        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);
            }
        }
Пример #8
0
        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();
        }
Пример #9
0
        public static CorrelationTile GetMostRightTile(List <CorrelationTile> tiles)
        {
            CorrelationTile rightMostTile = tiles[0];

            foreach (CorrelationTile tile in tiles)
            {
                if (tile.Tile.Position.X > rightMostTile.Tile.Position.X)
                {
                    rightMostTile = tile;
                }
            }

            return(rightMostTile);
        }
Пример #10
0
        public static CorrelationTile GetMostLeftTile(List <CorrelationTile> tiles)
        {
            CorrelationTile leftMostTile = tiles[0];

            foreach (CorrelationTile tile in tiles)
            {
                if (tile.Tile.Position.X < leftMostTile.Tile.Position.X)
                {
                    leftMostTile = tile;
                }
            }

            return(leftMostTile);
        }
Пример #11
0
        public static CorrelationTile GetMostTopTile(List <CorrelationTile> tiles)
        {
            CorrelationTile topMostTile = tiles[0];

            foreach (CorrelationTile tile in tiles)
            {
                if (tile.Tile.Position.Y < topMostTile.Tile.Position.Y)
                {
                    topMostTile = tile;
                }
            }

            return(topMostTile);
        }
Пример #12
0
        public static CorrelationTile GetMostBottomTile(List <CorrelationTile> tiles)
        {
            CorrelationTile bottomMostTile = tiles[0];

            foreach (CorrelationTile tile in tiles)
            {
                if (tile.Tile.Position.Y > bottomMostTile.Tile.Position.Y)
                {
                    bottomMostTile = tile;
                }
            }

            return(bottomMostTile);
        }
Пример #13
0
        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;
        }
Пример #14
0
        private CorrelationTile FindTileAroundPoint(Point pt)
        {
            CorrelationTile tile = null;

            // Find the tile that contains the centre point
            foreach (CorrelationTile t in this.CorrelationTiles)
            {
                if (t.Tile.Bounds.Contains(pt))
                {
                    tile = t;
                    break;
                }
            }

            return(tile);
        }
Пример #15
0
        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
        }
Пример #16
0
        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
        }
Пример #17
0
        private void PlaceFirstTile()
        {
            // puts the first tile in the sorted list at its default place
            CorrelationTile firstTile = this.CorrelationTiles[0];

            CorrelationTile.Origin = firstTile.BackgroundBoundsWithinMosaic.Location;
//            FreeImageAlgorithmsBitmap fib = firstTile.Tile.LoadFreeImageBitmap();
            FreeImageAlgorithmsBitmap fib = TileImage(firstTile.Tile);

            firstTile.Tile.IsAdjusted      = true;
            firstTile.PerformedCorrelation = true;
            NumberOfCorrelatedTiles++;
            firstTile.Tile.AdjustedPosition = firstTile.Tile.OriginalPosition;
            this.SendTileCorrelatationBegin(firstTile, fib);
            this.SendTileCorrelated(firstTile, firstTile.Tile.Bounds, fib, true);

            this.ThreadController.ReportThreadPercentage(this, "Placed  Tile " + firstTile.Tile.FileName + Environment.NewLine,
                                                         NumberOfCorrelatedTiles, CorrelationTiles.Count);

            //fib.Dispose();
        }
Пример #18
0
        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();
                }
            }
        }
Пример #19
0
 public static int GetMostTopPosition(List <CorrelationTile> tiles)
 {
     return(CorrelationTile.GetMostTopTile(tiles).Tile.Position.Y);
 }
Пример #20
0
        // 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);
        }
Пример #21
0
 public static int GetVerticalRangeOfTiles(List <CorrelationTile> tiles)
 {
     return(CorrelationTile.GetMostBottomPosition(tiles) - CorrelationTile.GetMostTopPosition(tiles));
 }
Пример #22
0
 public static int GetHorizontalRangeOfTiles(List <CorrelationTile> tiles)
 {
     return(CorrelationTile.GetMostRightPosition(tiles) - CorrelationTile.GetMostLeftPosition(tiles));
 }
Пример #23
0
 public static int GetMostBottomPosition(List <CorrelationTile> tiles)
 {
     return(CorrelationTile.GetMostBottomTile(tiles).Tile.Bounds.Bottom);
 }
Пример #24
0
 public static int GetMostRightPosition(List <CorrelationTile> tiles)
 {
     return(CorrelationTile.GetMostRightTile(tiles).Tile.Bounds.Right);
 }
Пример #25
0
 public static int GetMostLeftPosition(List <CorrelationTile> tiles)
 {
     return(CorrelationTile.GetMostLeftTile(tiles).Tile.Position.X);
 }
Пример #26
0
        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);
        }