Пример #1
0
        public IList <CircleSearchingResult> SearchCircles(HImage image, IList <CircleSearchingDefinition> circleSearchingDefinitions)
        {
            var    searchingResult = new CircleSearchingResultCollection();
            Random random          = new Random();

            for (int i = 0; i < circleSearchingDefinitions.Count; i++)
            {
                var definition   = circleSearchingDefinitions[i];
                int randomFactor = 0;
                var csr          = new CircleSearchingResult()
                {
                    Index  = i,
                    Name   = definition.Name,
                    Circle =
                        new Circle(definition.CenterX + random.NextDouble() * randomFactor,
                                   definition.CenterY + random.NextDouble() * randomFactor,
                                   (definition.InnerRadius + definition.OuterRadius) / 2.0 + random.NextDouble() * randomFactor),
                    Definition = definition.DeepClone(),
                };
                //                if (i == 2)
                //                    csr.IsNotFound = true;

                searchingResult.Add(csr);
            }

            return(searchingResult);
        }
Пример #2
0
        public static void UpdateRelativeCoordinate(this CircleSearchingResult circleResult,
                                                    IRelativeCoordinate relativeCoordinate)
        {
            var actualCenterPoint = circleResult.Circle.GetCenterPoint();
            var relativePoint     = relativeCoordinate.GetRelativePoint(actualCenterPoint);

            circleResult.RelativeCircle = new Circle(relativePoint, circleResult.Circle.Radius);
        }
Пример #3
0
        public CircleSearchingResult SearchCircle(HImage image, CircleSearchingDefinition definition)
        {
            Random random       = new Random();
            int    randomFactor = 0;
            var    csr          = new CircleSearchingResult()
            {
//                Index = i,
                Name   = definition.Name,
                Circle =
                    new Circle(definition.CenterX + random.NextDouble() * randomFactor,
                               definition.CenterY + random.NextDouble() * randomFactor,
                               (definition.InnerRadius + definition.OuterRadius) / 2.0 + random.NextDouble() * randomFactor),
                Definition = definition.DeepClone(),
            };

            return(csr);
        }
Пример #4
0
        public CircleSearchingResult SearchCircle(HImage image, CircleSearchingDefinition definition)
        {
            var swSearchCircle = new NotifyStopwatch("SearchCircle: " + definition.Name);

            var circleSearchingResult = new CircleSearchingResult
            {
                Definition = definition.DeepClone(),
                Name       = definition.Name,
//                Index = index
            };

            if (definition.ImageFilter_Disabled)
            {
                definition.ImageFilter = null;
            }

            //                if (circleDefinition.RegionExtractor_Disabled)
            //                    circleDefinition.RegionExtractor = null;

            var topLeftX     = definition.CenterX - definition.OuterRadius;
            var topLeftY     = definition.CenterY - definition.OuterRadius;
            var bottomRightX = definition.CenterX + definition.OuterRadius;
            var bottomRightY = definition.CenterY + definition.OuterRadius;

            var reg = new HRegion();

            reg.GenRectangle1(topLeftY, topLeftX, bottomRightY, bottomRightX);
            var reducedImage = image.ReduceDomain(reg);

            reg.Dispose();

            if (definition.Domain_SaveCacheImageEnabled)
            {
                reducedImage.WriteImageOfTiffLzwOfCropDomain(
                    _cacheImageDir + "\\SearchCircles_" + definition.Name + "_1_Domain.tif");
            }

            /*                HRegion domain;
             *              if (circleDefinition.RegionExtractor != null)
             *              {
             *                  throw new NotImplementedException();
             *                  var oldDomain = reducedImage.GetDomain();
             *                  domain = circleDefinition.RegionExtractor.Process(reducedImage);
             *                  oldDomain.Dispose();
             *
             *                  if (circleDefinition.ImageFilter_SaveCacheImageEnabled)
             *                      reducedImage
             *                          .ReduceDomain(domain)
             *                          .CropDomain()
             *                          .ToBitmapSource()
             *                          .SaveToTiff(_cacheImageDir + "\\SearchCircles_" + circleDefinition.Name + "_2_ROI.tif");
             *              }
             *              else
             *              {
             *                  domain = reducedImage.GetDomain();
             *              }*/

            HRegion domain  = reducedImage.GetDomain();
            int     offsetX = domain.GetColumn1();
            int     offsetY = domain.GetRow1();

            var roiImage = reducedImage.CropDomain();

            HImage filterImage = null;

            if (definition.ImageFilter != null)
            {
                var swImageFilter = new NotifyStopwatch("CircleInspector.ImageFilter: " + definition.Name);
                filterImage = definition.ImageFilter.Process(roiImage);
                swImageFilter.Dispose();

                if (definition.ImageFilter_SaveCacheImageEnabled)
                {
                    filterImage.WriteImageOfTiffLzwOfCropDomain(
                        _cacheImageDir + "\\SearchCircles_" + definition.Name + "_3_ImageFilter.tif");

                    //
                    var paintedImage = filterImage.PaintGrayOffset(image, offsetY, offsetX);
                    paintedImage.WriteImageOfJpeg(_cacheImageDir + "\\SearchCircles_" + definition.Name +
                                                  "_3_ImageFilter_PaintGrayOffset.jpg");
                    paintedImage.Dispose();
                }
            }
            else
            {
                filterImage = roiImage;
            }

            var offsetCenterX = definition.CenterX - offsetX;
            var offsetCenterY = definition.CenterY - offsetY;

            var swFindCircle = new NotifyStopwatch("CircleInspector.FindCircle: " + definition.Name);
            var circle       = definition.CircleExtractor.FindCircle(filterImage,
                                                                     offsetCenterX, offsetCenterY, definition.InnerRadius, definition.OuterRadius);

            swFindCircle.Dispose();

            if (circle.IsEmpty)
            {
                circleSearchingResult.HasError   = true;
                circleSearchingResult.IsNotFound = true;
                //                    circleSearchingResult.Circle = new Circle(circleDefinition.CenterX, circleDefinition.CenterY);
            }
            else
            {
                var newCircle = new Circle(circle.CenterX + offsetX, circle.CenterY + offsetY, circle.Radius);
                circleSearchingResult.Circle = newCircle;
            }

            swSearchCircle.Dispose();
            return(circleSearchingResult);
        }