public static List <RasterRegion> regionLabeling(byte[,] slika)
        {
            List <RasterRegion> regions = new List <RasterRegion>();
            int w = slika.GetLength(1);
            int h = slika.GetLength(0);

            byte[,] retVal = new byte[h, w];
            int[] ii     = { 0, 1, 1, 1, 0, -1, -1, -1 };
            int[] jj     = { 1, 1, 0, -1, -1, -1, 0, 1 };
            int   n      = ii.Length;
            byte  regNum = 0;

            for (int y = 1; y < h - 1; y++)
            {
                for (int x = 1; x < w - 1; x++)
                {
                    if (slika[y, x] == 0)
                    {
                        regNum++;
                        byte rr = (byte)(regNum * 50);
                        if (rr == 0)
                        {
                            rr = 1;
                        }
                        slika[y, x] = rr;
                        List <Point> front  = new List <Point>();
                        Point        pt     = new Point(x, y);
                        RasterRegion region = new RasterRegion();
                        region.regId = regNum;
                        region.points.Add(pt);
                        regions.Add(region);
                        front.Add(pt);
                        while (front.Count > 0)
                        {
                            Point p = front[0];
                            front.RemoveAt(0);
                            for (int t = 0; t < n; t++)
                            {
                                Point point = new Point(p.X + jj[t], p.Y + ii[t]);
                                if (point.X > -1 && point.X < w && point.Y > -1 && point.Y < h)
                                {
                                    byte pp = slika[point.Y, point.X];
                                    if (pp == 0)
                                    {
                                        slika[point.Y, point.X] = slika[y, x];
                                        region.points.Add(point);
                                        front.Add(point);
                                    }
                                }
                            }
                        }
                    }
                }
            }
            return(regions);
        }
Exemple #2
0
 private void _rasterImageViewer_TransformChanged(object sender, EventArgs e)
 {
     if (IsHandleCreated)
     {
         if (_viewerRegionCopy)
         {
             RegionG = _rasterImageViewer.Image.GetRegion(null);
             _rasterImageViewer.CombineFloater(true);
             _viewerRegionPage = _rasterImageViewer.Image.Page;
             _viewerRegionCopy = false;
             _viewerRegion     = true;
         }
         UpdateZoomValueFromControl();
         UpdateUIState();
     }
 }
        private void ApplyFilter()
        {
            int orignalPage = _cell.Image.Page;

            _cell.Image.Page = _cell.ActiveSubCell + 1;
            _region          = _cell.Image.GetRegion(null);
            _cell.RemoveRegion();
            HistogramEqualizeType type = HistogramEqualizeType.None;

            switch (_cbColorSpace.SelectedIndex)
            {
            case 0:
                type = HistogramEqualizeType.Rgb;
                break;

            case 1:
                type = HistogramEqualizeType.Yuv;
                break;

            case 2:
                type = HistogramEqualizeType.Gray;
                break;
            }

            HistogramEqualizeCommand command = new HistogramEqualizeCommand(type);

            _mainForm.FilterRunCommand(command, false, true);


            _cell.Image.SetRegion(null, _region, RasterRegionCombineMode.Set);
            if (_cell.Image.BitsPerPixel == 8)
            {
                _cell.SetWindowLevel(_cell.ActiveSubCell, 255, 128);
            }
            else if (_cell.Image.BitsPerPixel == 16)
            {
                _cell.SetWindowLevel(_cell.ActiveSubCell, 65000, 32000);
            }

            _cell.Image.Page = orignalPage;
            _cell.Invalidate();
        }
 public static void FillSection_Png( object sender, Leadtools.Printer.EmfEventArgs e )
 {
     ConsoleMethods.Info( "EMF Event: FillSection_Png" );
      const string format = "png";
      string path = Path.Combine(
     GetOutputRootPath(),
     format + @"\",
     GetRandomFileName( format ) );
      Directory.CreateDirectory( Path.GetDirectoryName( path ) );
      // Get the EMF in memory and save as PNG.
      Metafile metaFile = null;
      try
      {
     metaFile = new Metafile( e.Stream );
     IntPtr hEmf = metaFile.GetHenhmetafile();
     using ( RasterImage image = RasterImageConverter.FromEmf( hEmf, 0, 0, RasterColor.White ) )
     {
        using ( RasterRegion region = new RasterRegion( new LeadRect( 20, 30, 100, 200 ) ) )
        {
           image.SetRegion( null, region, RasterRegionCombineMode.Set );
           new FillCommand( RasterColor.FromKnownColor( RasterKnownColor.Black ) ).Run( image );
        }
        using ( RasterCodecs codecs = new RasterCodecs() )
        {
           codecs.Options.Png.Save.QualityFactor = 9;
           codecs.Save( image, path, RasterImageFormat.Png, 32 );
        }
     }
     ConsoleMethods.Success( "FillSection_Png: PNG saved. " );
     ConsoleMethods.Verbose( path );
      }
      catch ( Exception ex )
      {
     ConsoleMethods.Error( ex.Message, 4000 );
      }
 }