Ejemplo n.º 1
0
        public HImage Process(HImage image)
        {
//            image.WriteImage("tiff", 0, @"B:\Test_Ori");

            var preprocessImage = PreprocessFilter.Process(image);
//            preprocessImage.WriteImage("tiff", 0, @"B:\Test_preprocessImage");

            var thresholdImage = ThresholdImageFilter.Process(preprocessImage);
//            thresholdImage.WriteImage("tiff", 0, @"B:\Test_thresholdImage");

            HRegion region = preprocessImage.DynThreshold(
                thresholdImage,
                Offset,
                LightDark.ToHalconString());
            var complement = region.Complement();

            thresholdImage.OverpaintRegion(region, (double)ForegroundGray, "fill");
            thresholdImage.OverpaintRegion(complement, (double)BackgroundGray, "fill");
//            thresholdImage.WriteImage("tiff", 0, @"B:\Test_OverpaintRegion");

            region.Dispose();
            complement.Dispose();
            preprocessImage.Dispose();

            return(thresholdImage);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Test the neighborhood.
        /// </summary>
        private void NeighborhoodTest()
        {
            HImage  image            = new HImage("byte", 512, 512);
            HRegion regionLine       = new HRegion();
            HRegion regionComplement = new HRegion();
            HRegion regionConnected  = new HRegion();
            HTuple  hv_DefWindow     = new HTuple();
            HWindow HalconWindow1    = HalconWindowControl1.HalconWindow;
            HWindow HalconWindow2    = HalconWindowControl2.HalconWindow;

            try
            {
                HalconWindow1.SetColored(6);
                HalconWindow2.SetColored(6);
                int numObjects;

                image.GenImageGrayRamp(0, 0, 128, 256, 256, 512, 512);

                // Display code
                image.DispImage(HalconWindow1);
                image.DispImage(HalconWindow2);

                regionLine.GenRegionLine(100, -1, 150, 512);
                regionComplement = regionLine.Complement();

                HOperatorSet.SetSystem("neighborhood", 4);
                regionConnected = regionComplement.Connection();
                image.DispImage(HalconWindow1);
                regionConnected.DispRegion(HalconWindow1);

                numObjects  = regionConnected.CountObj();
                label1.Text = "Number of objects 4-connected:" + numObjects.ToString();

                regionConnected.Dispose();
                HOperatorSet.SetSystem("neighborhood", 8);
                regionConnected = regionComplement.Connection();
                image.DispImage(HalconWindow2);
                regionConnected.DispRegion(HalconWindow2);

                numObjects  = regionConnected.CountObj();
                label2.Text = "Number of objects 8-connected:" + numObjects.ToString();

                HOperatorSet.CloseWindow(HDevWindowStack.Pop());
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                image.Dispose();
                regionLine.Dispose();
                regionConnected.Dispose();
                regionComplement.Dispose();
            }
        }