public int[] GetAOI(ShapePolygon[] geometrys, Envelope dstEnvelope, Size size)
        {
            if (dstEnvelope == null || size.IsEmpty)
            {
                return(null);
            }
            double   resX        = dstEnvelope.Width / size.Width;
            double   resY        = dstEnvelope.Height / size.Height;
            Envelope aoiEnvelope = GetSrcEnvelope(geometrys);

            aoiEnvelope = aoiEnvelope.IntersectWith(dstEnvelope);
            if (aoiEnvelope == null)
            {
                return(null);
            }
            Size aoiSize = new Size((int)GetInteger((aoiEnvelope.Width / resX), resX), (int)GetInteger((aoiEnvelope.Height / resY), resY));

            if (aoiSize.IsEmpty)
            {
                return(null);
            }
            // by chennan 修正当AOI区域因精度问题计算出现偏差时,导致索引超出界限问题
            if (aoiSize.Width > size.Width)
            {
                aoiSize.Width = size.Width;
            }
            if (aoiSize.Height > size.Height)
            {
                aoiSize.Height = size.Height;
            }
            //
            int offsetX = (int)((aoiEnvelope.MinX - dstEnvelope.MinX) / resX);
            int offsetY = (int)((dstEnvelope.MaxY - aoiEnvelope.MaxY) / resY);

            using (Bitmap buffer = GetBitmap(geometrys, aoiEnvelope, aoiSize))
            {
                //buffer.Save(@"D:\bmp\" + (bmptext++.ToString()) + ".bmp");
                using (IBitmap2RasterConverter c = new Bitmap2RasterConverter())
                {
                    int[] aoi = c.ToRaster(buffer, Color.Red);
                    if (aoi == null)
                    {
                        return(null);
                    }
                    int count = aoi.Length;
                    int newWidth = aoiSize.Width;
                    int oldWidth = size.Width;
                    int row = 0, col = 0;
                    for (int i = 0; i < count; i++)
                    {
                        row    = aoi[i] / newWidth;
                        col    = aoi[i] % newWidth;
                        row   += offsetY;
                        col   += offsetX;
                        aoi[i] = row * oldWidth + col;
                    }
                    return(aoi);
                }
            }
        }
Beispiel #2
0
 public int[] GetAOIByFeature(Bitmap bitmap, Color color)
 {
     using (IBitmap2RasterConverter c = new Bitmap2RasterConverter())
     {
         return(c.ToRaster(bitmap, color));
     }
 }
        /// <summary>
        /// 解决了大图像AOI栅格化内存溢出的问题
        /// 解决方法:
        /// 1、按照AOI的最小外包矩形栅格化计算AOI索引
        /// 2、将计算完成的AOI索引平移到大图
        /// </summary>
        /// <param name="rasterPoints"></param>
        /// <param name="types"></param>
        /// <param name="size"></param>
        /// <returns></returns>
        public int[] GetAOI(PointF[] rasterPoints, byte[] types, Size size)
        {
            Envelope evp = new Envelope(0, 0, size.Width, size.Height);

            using (IVector2BitmapConverter c = new Vector2BitmapConverter())
            {
                int    offsetX, offsetY;
                Size   newSize;
                Bitmap buffer = GetBitmapUseRasterII(rasterPoints, types, evp, size, out offsetX, out offsetY, out newSize);
                if (newSize.IsEmpty || buffer == null)
                {
                    return(null);
                }
                using (IBitmap2RasterConverter rstc = new Bitmap2RasterConverter())
                {
                    int[] aoi = rstc.ToRaster(buffer, Color.Red);
                    if (aoi == null || aoi.Length == 0)
                    {
                        return(null);
                    }
                    if (aoi != null)
                    {
                        Array.Sort <int>(aoi);
                    }
                    int        count = aoi.Length;
                    int        newWidth = newSize.Width;
                    int        oldWidth = size.Width;
                    int        oldHeight = size.Height;
                    int        row = 0, col = 0;
                    List <int> newAio = new List <int>();
                    for (int i = 0; i < count; i++)
                    {
                        row  = aoi[i] / newWidth;
                        col  = aoi[i] % newWidth;
                        row += offsetY;
                        col += offsetX;
                        if (col < 0 || col >= oldWidth || row < 0 || row >= oldHeight)
                        {
                            continue;
                        }
                        else
                        {
                            newAio.Add(row * oldWidth + col);
                        }
                    }
                    return(newAio.ToArray());
                }
            }
        }
        public int[] GetAOI_OLD(ShapePolygon[] geometrys, Envelope dstEnvelope, Size size)
        {
            if (dstEnvelope == null || size.IsEmpty)
            {
                return(null);
            }

            using (Bitmap buffer = GetBitmap(geometrys, dstEnvelope, size))
            {
                using (IBitmap2RasterConverter c = new Bitmap2RasterConverter())
                {
                    return(c.ToRaster(buffer, Color.Red));
                }
            }
        }
 public int[] GetAOI(PointF[] coordPoints, byte[] types, Envelope dstEnvelope, Size size)
 {
     if (dstEnvelope == null || size.IsEmpty)
     {
         return(null);
     }
     using (IVector2BitmapConverter c = new Vector2BitmapConverter())
     {
         Bitmap buffer = GetBitmap(coordPoints, types, dstEnvelope, size);
         using (IBitmap2RasterConverter rstc = new Bitmap2RasterConverter())
         {
             return(rstc.ToRaster(buffer, Color.Red));
         }
     }
 }
 public byte[] GetRaster(ShapePolygon[] geometrys, Envelope dstEnvelope, Size size)
 {
     if (dstEnvelope == null || size.IsEmpty)
     {
         return(null);
     }
     Color[] colors = GetColors(geometrys.Length);
     using (Bitmap buffer = GetBitmap(geometrys, colors, dstEnvelope, size))
     {
         using (IBitmap2RasterConverter c = new Bitmap2RasterConverter())
         {
             return(c.ToRaster(buffer, colors));
         }
     }
 }
        public int[] GetAOI_OLD(PointF[] rasterPoints, byte[] types, Size size)
        {
            Envelope evp = new Envelope(0, 0, size.Width, size.Height);

            using (IVector2BitmapConverter c = new Vector2BitmapConverter())
            {
                Bitmap buffer = GetBitmapUseRaster(rasterPoints, types, evp, size);
                using (IBitmap2RasterConverter rstc = new Bitmap2RasterConverter())
                {
                    int[] aoi = rstc.ToRaster(buffer, Color.Red);
                    if (aoi != null)
                    {
                        Array.Sort <int>(aoi);
                    }
                    return(aoi);
                }
            }
        }
Beispiel #8
0
 public static int[] Reverse(int[] aoi, Size size)
 {
     if (aoi == null || aoi.Length == 0 || size.Width == 0 || size.Height == 0)
     {
         return(null);
     }
     using (IBinaryBitmapBuilder b = new BinaryBitmapBuilder())
     {
         Bitmap bm = b.CreateBinaryBitmap(size, Color.Red, Color.Black);
         try
         {
             b.Fill(aoi, size, ref bm);
             using (IBitmap2RasterConverter c = new Bitmap2RasterConverter())
             {
                 return(c.ToRaster(bm, Color.Black));
             }
         }
         finally
         {
             bm.Dispose();
         }
     }
 }
        public int GetAOICount(ShapePolygon[] geometrys, Envelope dstEnvelope, Size size)
        {
            if (dstEnvelope == null || size.IsEmpty)
            {
                return(0);
            }
            double   resX        = dstEnvelope.Width / size.Width;
            double   resY        = dstEnvelope.Height / size.Height;
            Envelope aoiEnvelope = GetSrcEnvelope(geometrys);

            aoiEnvelope = aoiEnvelope.IntersectWith(dstEnvelope);
            if (aoiEnvelope == null)
            {
                return(0);
            }
            Size aoiSize = new Size((int)GetInteger((aoiEnvelope.Width / resX), resX), (int)GetInteger((aoiEnvelope.Height / resY), resX));

            if (aoiSize.IsEmpty)
            {
                return(0);
            }
            int offsetX = (int)((aoiEnvelope.MinX - dstEnvelope.MinX) / resX);
            int offsetY = (int)((dstEnvelope.MaxY - aoiEnvelope.MaxY) / resY);

            using (Bitmap buffer = GetBitmap(geometrys, aoiEnvelope, aoiSize))
            {
                using (IBitmap2RasterConverter c = new Bitmap2RasterConverter())
                {
                    int[] aoi = c.ToRaster(buffer, Color.Red);
                    if (aoi == null)
                    {
                        return(0);
                    }
                    return(aoi.Length);
                }
            }
        }