コード例 #1
0
        public HRegion Extract(HImage image)
        {
            var    domain        = image.GetDomain();
            HImage changeDomain1 = image.ChangeDomain(domain);
            var    region1       = RegionExtractor1.Extract(changeDomain1);
            HImage changeDomain2 = image.ChangeDomain(domain);
            var    region2       = RegionExtractor2.Extract(changeDomain2);
            var    unionRegion   = region1.Union2(region2);

            changeDomain1.Dispose();
            changeDomain2.Dispose();
            region1.Dispose();
            region2.Dispose();
            return(unionRegion);
        }
コード例 #2
0
        public HImage Process(HImage image)
        {
            var domain          = image.GetDomain();
            var fullDomainImage = image.FullDomain();
            var fullDomain      = fullDomainImage.GetDomain();

            //
            var expandImage     = image.ExpandDomainGray(ExpansionRange);
            var expandFullImage = expandImage.FullDomain();
//            expandFullImage.WriteImage("tiff", 0, "D:\\test-0-expandFullImage.tif");

            //
            var holeRegion = fullDomain.Difference(domain);

            HImage paintedImage = expandFullImage;

            for (int i = 0; i < Items.Count; i++)
            {
                var imageFilter  = Items[i];
                var reducedImage = image.ChangeDomain(holeRegion);
                var meanedImage  = imageFilter.Process(reducedImage);
//                meanedImage.WriteImage("tiff", 0, "D:\\test-1-meanedImage_" + i + ".tif");

                var paintedImage2 = meanedImage.PaintGray(paintedImage);
                paintedImage.Dispose();
                paintedImage = paintedImage2;
//                paintedImage.WriteImage("tiff", 0, "D:\\test-2-paintedImage_" + i + ".tif");
            }

            return(paintedImage);
        }
コード例 #3
0
        public HImage Process(HImage image)
        {
            var region       = RegionExtractor.Extract(image);
            var reducedImage = image.ChangeDomain(region);

            region.Dispose();
            return(reducedImage);
        }
コード例 #4
0
        public static void WriteImageOfTiffLzwOfCropDomain(this HImage image, HRegion domain, string fileName,
                                                           double background = 0)
        {
            var changeDomain = image.ChangeDomain(domain);

            changeDomain.WriteImageOfTiffLzwOfCropDomain(fileName);
            changeDomain.Dispose();
        }
コード例 #5
0
        public virtual HRegion Extract(HImage image, HRegion domain)
        {
            var domainChangedImage = image.ChangeDomain(domain);

            if (RegionExtractor == null)
            {
                return(domainChangedImage);
            }
            else
            {
                return(RegionExtractor.Extract(domainChangedImage));
            }
        }
コード例 #6
0
        public static HImage ReduceDomainForRing(this HImage hImage, double centerX, double centerY, double innerRadius,
                                                 double outerRadius)
        {
            var innerCircle = new HRegion();

            innerCircle.GenCircle(centerY, centerX, innerRadius);

            var outerCircle = new HRegion();

            outerCircle.GenCircle(centerY, centerX, outerRadius);

            var ring         = outerCircle.Difference(innerCircle);
            var reducedImage = hImage.ChangeDomain(ring);

            innerCircle.Dispose();
            outerCircle.Dispose();
            ring.Dispose();

//            reducedImage.CropDomain()
//                      .ToBitmapSource()
//                      .SaveToJpeg("_EnhanceEdgeArea_Domain.jpg");

            return(reducedImage);
        }
コード例 #7
0
        public SurfaceResult SearchSurface(HImage image, SurfaceDefinition definition)
        {
            var swSearchSurface = new NotifyStopwatch("SearchSurface: " + definition.Name);

            if (definition.SaveAllCacheImageEnabled)
            {
//                definition.SaveCacheImageEnabled = true;
                foreach (var part in definition.ExcludeParts)
                {
                    part.SaveCacheImageEnabled = true;
                }
                foreach (var part in definition.IncludeParts)
                {
                    part.SaveCacheImageEnabled = true;
                }
            }

            var surfaceResult = new SurfaceResult()
            {
                Definition = definition.DeepClone(),
            };

            var unionIncludeRegion = new HRegion();
            var unionIncludeDomain = new HRegion();

            unionIncludeRegion.GenEmptyRegion();
            unionIncludeDomain.GenEmptyRegion();

            var unionExcludeRegion = new HRegion();
            var unionExcludeDomain = new HRegion();

            unionExcludeRegion.GenEmptyRegion();
            unionExcludeDomain.GenEmptyRegion();

            foreach (var excludeRegion in definition.ExcludeParts)
            {
                var     sw     = new NotifyStopwatch("excludeRegion.Process: " + excludeRegion.Name);
                HRegion region = excludeRegion.Extract(image);
                sw.Dispose();
                var domain = excludeRegion.Domain;

                unionExcludeRegion = unionExcludeRegion.Union2(region);
                unionExcludeDomain = unionExcludeDomain.Union2(domain);

                if (excludeRegion.SaveCacheImageEnabled)
                {
                    var fileName = "SurfaceDefinition_" + definition.Name + "_Exclude_" + excludeRegion.Name;
                    image.SaveCacheImagesForRegion(domain, region, fileName);
                }

                surfaceResult.ExcludeRegionResults.Add(new RegionResult()
                {
                    SurfaceGroupName = definition.GroupName,
                    SurfaceName      = definition.Name,
                    RegionName       = excludeRegion.Name,
                    Domain           = domain,
                    Region           = region,
                });

                //                    region.Dispose();
                //                    domain.Dispose();
            }

            foreach (var includeRegion in definition.IncludeParts)
            {
                var domain = includeRegion.Domain;
                unionIncludeDomain = unionIncludeDomain.Union2(domain);

                var remainDomain = domain.Difference(unionExcludeRegion);
                var reducedImage = image.ChangeDomain(remainDomain);

                HRegion region;
                using (new NotifyStopwatch("includeRegion.Process: " + includeRegion.Name))
                    region = includeRegion.Extract(reducedImage);
                var remainRegion = region.Difference(unionExcludeRegion);
                unionIncludeRegion = unionIncludeRegion.Union2(remainRegion);

                if (includeRegion.SaveCacheImageEnabled)
                {
                    var fileName = "SurfaceDefinition_" + definition.Name + "_Include_" + includeRegion.Name;
                    //                        _hDevelopExportHelper.HImage.SaveCacheImagesForRegion(domain, remainRegion, fileName);
                    image.SaveCacheImagesForRegion(domain, remainRegion, unionExcludeRegion,
                                                   fileName);
                }

                surfaceResult.IncludeRegionResults.Add(new RegionResult()
                {
                    SurfaceGroupName = definition.GroupName,
                    SurfaceName      = definition.Name,
                    RegionName       = includeRegion.Name,
                    Domain           = domain,
                    Region           = remainRegion,
                });
            }

            if (definition.SaveCacheImageEnabled && definition.IncludeParts.Any())
            {
                var fileName = "SurfaceDefinition_" + definition.Name + "_Include";
                image.SaveCacheImagesForRegion(unionIncludeDomain, unionIncludeRegion,
                                               unionExcludeRegion, fileName);
            }

            if (definition.SaveCacheImageEnabled && definition.ExcludeParts.Any())
            {
                var fileName = "SurfaceDefinition_" + definition.Name + "_Exclude";
                image.SaveCacheImagesForRegion(unionExcludeDomain, unionExcludeRegion,
                                               fileName);
            }

            surfaceResult.ExcludeRegion = unionExcludeRegion;
            surfaceResult.IncludeRegion = unionIncludeRegion;

            swSearchSurface.Dispose();
            return(surfaceResult);
        }
コード例 #8
0
        public IList <RegionDefectResult> SearchDefects(HImage image, DefectDefinition definition,
                                                        IList <SurfaceResult> surfaceResults)
        {
            var swSearchDefects = new NotifyStopwatch("SearchDefects: " + definition.Name);

            var rdrs = new List <RegionDefectResult>();

            foreach (var refer in definition.References)
            {
                var regionResult = surfaceResults.GetRegionResult(refer.SurfaceName, refer.RegionName);

                if (regionResult == null)
                {
                    continue;
                }

                var regionDefectResult = new RegionDefectResult {
                    RegionResult = regionResult
                };

                var changeDomainImage = image.ChangeDomain(regionResult.Region);

                HImage filterImage;
                if (definition.ImageFilter != null)
                {
                    filterImage = definition.ImageFilter.Process(changeDomainImage);
                    changeDomainImage.Dispose();
                }
                else
                {
                    filterImage = changeDomainImage;
                }

                var blob = definition.RegionExtractor.Extract(filterImage);

                HRegion finalBlob;
                if (definition.RegionProcessor != null)
                {
                    finalBlob = definition.RegionProcessor.Process(blob);
                    blob.Dispose();
                }
                else
                {
                    finalBlob = blob;
                }

                if (definition.SaveCacheImageEnabled)
                {
                    var image2 = image.ChangeDomain(regionResult.Region);

                    if (finalBlob.CountObj() > 0)
                    {
                        var paintImage = image2.PaintRegion(finalBlob, 222.0, "fill");
                        paintImage.WriteImageOfTiffLzwOfCropDomain(_cacheImageDir + "\\SearchCircles_" + definition.Name +
                                                                   "_1_Domain.tif");
                    }
                    else
                    {
                        image2.WriteImageOfTiffLzwOfCropDomain(_cacheImageDir + "\\SearchCircles_" + definition.Name +
                                                               "_1_Domain.tif");
                    }
                }

                var blobs = finalBlob.ToList();

                int index = 0;
                foreach (var hRegion in blobs)
                {
                    var dr = new DefectResult
                    {
                        Index  = index,
                        X      = hRegion.GetColumn(),
                        Y      = hRegion.GetRow(),
                        Width  = hRegion.GetWidth(),
                        Height = hRegion.GetHeight(),
                        Name   = definition.Name,
                    };
                    regionDefectResult.DefectResults.Add(dr);
                    index++;
                }

                rdrs.Add(regionDefectResult);
            }
            swSearchDefects.Dispose();
            return(rdrs);
        }
コード例 #9
0
        public RegionTargetResult SearchRegionTarget(HImage image, RegionTargetDefinition definition)
        {
            var swSearchRegionTarget = new NotifyStopwatch("SearchRegionTarget: " + definition.Name);

            var result = new RegionTargetResult
            {
                Definition = definition.DeepClone(),
            };

            var roiImage = HDevelopExport.Singletone.ChangeDomainForRectangle(
                image,
                definition.RoiActualLine,
                definition.RoiHalfWidth);

            if (definition.Domain_SaveCacheImageEnabled)
            {
                roiImage.WriteImageOfTiffLzwOfCropDomain(
                    _cacheImageDir + "\\SearchRegionTarget_" + definition.Name + "_1_Domain_Cropped.tif");
            }

            // Around
            HImage aroundFilterImage;

            if (definition.AroundImageFilter != null)
            {
                var swAroundImageFilter = new NotifyStopwatch("RegionTargetInspector.AroundImageFilter: " + definition.Name);
                aroundFilterImage = definition.AroundImageFilter.Process(roiImage);
                swAroundImageFilter.Dispose();
            }
            else
            {
                aroundFilterImage = roiImage;
            }

            HRegion aroundRegion;

            if (definition.AroundRegionExtractor != null)
            {
                var swAroundRegionExtractor = new NotifyStopwatch("RegionTargetInspector.AroundRegionExtractor: " + definition.Name);
                aroundRegion = definition.AroundRegionExtractor.Extract(aroundFilterImage);
                swAroundRegionExtractor.Dispose();
            }
            else
            {
                aroundRegion = aroundFilterImage.GetDomain();
            }

            if (definition.AroundRegionExtractor_SaveCacheImageEnabled)
            {
//                var reducedImage = image.ChangeDomain(aroundRegion.Union1());
//                reducedImage.WriteImageOfTiffLzwOfCropDomain(
//                    _cacheImageDir + "\\SearchRegionTarget_" + definition.Name + "_1_AroundRegionExtractor.tif");
//                reducedImage.Dispose();
                image.WriteImageOfTiffLzwOfCropDomain(aroundRegion,
                                                      _cacheImageDir + "\\SearchRegionTarget_" + definition.Name + "_1_AroundRegionExtractor.tif");
            }

            HRegion aroundProcessedRegion;

            if (definition.AroundRegionProcessor != null)
            {
                var swAroundRegionProcessor = new NotifyStopwatch("RegionTargetInspector.AroundRegionProcessor: " + definition.Name);
                aroundProcessedRegion = definition.AroundRegionProcessor.Process(aroundRegion);
                swAroundRegionProcessor.Dispose();
            }
            else
            {
                aroundProcessedRegion = aroundRegion;
            }

            HImage aroundImage = image.ChangeDomain(aroundProcessedRegion);

            if (definition.AroundRegionProcessor_SaveCacheImageEnabled)
            {
                aroundImage.WriteImageOfTiffLzwOfCropDomain(
                    _cacheImageDir + "\\SearchRegionTarget_" + definition.Name + "_1_Around_Cropped.tif");
            }

            aroundProcessedRegion.Dispose();
            aroundFilterImage.Dispose();
            aroundRegion.Dispose();

            // Target

            HImage targetFilterImage;

            if (definition.TargetImageFilter != null)
            {
                var swTargetImageFilter = new NotifyStopwatch("RegionTargetInspector.TargetImageFilter: " + definition.Name);
                targetFilterImage = definition.TargetImageFilter.Process(aroundImage);
                swTargetImageFilter.Dispose();
            }
            else
            {
                targetFilterImage = aroundImage;
            }

            if (definition.TargetImageFilter_SaveCacheImageEnabled)
            {
                targetFilterImage.WriteImageOfTiffLzwOfCropDomain(
                    _cacheImageDir + "\\SearchRegionTarget_" + definition.Name + "_1_TargetImageFilter_Cropped.tif");
            }

            HRegion targetRegion;

            if (definition.TargetRegionExtractor != null)
            {
                var swTargetRegionExtractor = new NotifyStopwatch("RegionTargetInspector.TargetRegionExtractor: " + definition.Name);
                targetRegion = definition.TargetRegionExtractor.Extract(targetFilterImage);
                swTargetRegionExtractor.Dispose();
            }
            else
            {
                targetRegion = targetFilterImage.GetDomain();
            }

            HRegion targetProcessedRegion;

            if (definition.TargetRegionProcessor != null)
            {
                var swTargetRegionProcessor = new NotifyStopwatch("RegionTargetInspector.TargetRegionProcessor: " + definition.Name);
                targetProcessedRegion = definition.TargetRegionProcessor.Process(targetRegion);
                swTargetRegionProcessor.Dispose();
            }
            else
            {
                targetProcessedRegion = targetRegion;
            }

            targetFilterImage.Dispose();
            roiImage.Dispose();

            result.TargetRegion = targetProcessedRegion;

            if (targetProcessedRegion.CountObj() == 0)
            {
                result.HasError = true;
            }

            swSearchRegionTarget.Dispose();
            return(result);
        }
コード例 #10
0
        public static void SaveCacheImagesForRegion(this HImage image, HRegion domain, HRegion includeRegion,
                                                    HRegion excludeRegion, string fileName)
        {
            var dir      = typeof(Ex).Assembly.GetAssemblyDirectoryPath();
            var cacheDir = Path.Combine(dir, "CacheImages");

            if (!Directory.Exists(cacheDir))
            {
                Directory.CreateDirectory(cacheDir);
            }

            var imageWidth  = image.GetWidth();
            var imageHeight = image.GetHeight();

            // Domain.Ori
            var reducedImage = image.ChangeDomain(domain);
            var croppedImage = reducedImage.CropDomain();

            croppedImage.WriteImageOfTiff(cacheDir.CombilePath(fileName) + ".Domain.Ori.tif");
            reducedImage.Dispose();
            croppedImage.Dispose();

            // Domain.PaintMargin
            var reducedImage4     = image.ChangeDomain(domain);
            var paintRegionImage  = reducedImage4.PaintRegion(includeRegion, 250.0, "margin");
            var paintRegion2Image = paintRegionImage.PaintRegion(excludeRegion, 5.0, "margin");
            var croppedImage2     = paintRegion2Image.CropDomain();

            croppedImage2.WriteImageOfTiff(cacheDir.CombilePath(fileName) + ".Domain.PaintMargin.tif");
            reducedImage4.Dispose();
            croppedImage2.Dispose();
            paintRegionImage.Dispose();
            paintRegion2Image.Dispose();

            // PaintFill
//            var paintRegion3Image = reducedImage.PaintRegion(includeRegion, 250.0, "fill");
//            var croppedImage2bImage = paintRegion3Image.CropDomain();
//            croppedImage2bImage.ToBitmapSource().SaveToTiff(cacheDir.CombilePath(fileName) + ".Domain.PaintFill.tif");
//            croppedImage2bImage.Dispose();

            // Domain.Crop
            var reducedImage3 = image.ChangeDomain(includeRegion);
            var croppedImage3 = reducedImage3.CropDomain();

            croppedImage3.WriteImageOfTiff(cacheDir.CombilePath(fileName) + ".Domain.Crop.tif");
            reducedImage3.Dispose();
            croppedImage3.Dispose();

            // bin image in domain
            var row1        = domain.GetRow1();
            var column1     = domain.GetColumn1();
            var movedRegion = includeRegion.MoveRegion(-row1, -column1);

            var w        = domain.GetWidth();
            var h        = domain.GetHeight();
            var binImage = movedRegion.RegionToBin(255, 0, w, h);

            binImage.WriteImageOfTiff(cacheDir.CombilePath(fileName) + ".Domain.Bin.tif");
            binImage.Dispose();
            movedRegion.Dispose();

            // Full.Bin,
            var binImage2 = includeRegion.RegionToBin(255, 0, imageWidth, imageHeight);

            binImage2.WriteImageOfJpeg(cacheDir.CombilePath(fileName) + ".Full.Bin.jpg");
            binImage2.Dispose();

            // Full.BinOnlyDomain
            var binImage3          = includeRegion.RegionToBin(255, 0, imageWidth, imageHeight);
            var reducedImage5      = binImage3.ReduceDomain(domain);
            var binOnlyDomainImage = image.Clone();

            binOnlyDomainImage.OverpaintGray(reducedImage5);
            binOnlyDomainImage.WriteImageOfJpeg(cacheDir.CombilePath(fileName) + ".Full.BinOnlyDomain.jpg");

            binImage3.Dispose();
            reducedImage5.Dispose();
            binOnlyDomainImage.Dispose();
        }