Ejemplo n.º 1
0
        private void _Process()
        {
            int width  = _srcImage.Width;
            int height = _srcImage.Height;

            System.IntPtr srcScan;
            BitmapData    srcBmData;

            ImageExtract.InitPonitMethod(_srcImage, width, height, out srcScan, out srcBmData);

            unsafe
            {
                byte *srcP      = (byte *)srcScan;
                int   srcOffset = srcBmData.Stride - width * 3;

                for (int y = 0; y < height; y++)
                {
                    for (int x = 0; x < width; x++, srcP += 3)
                    {
                        //byte gray = (byte)(.299 * srcP[2] + .587 * srcP[1] + .114 * srcP[0]);
                        _imageMap[x, y] = srcP[2];
                    }
                    srcP += srcOffset;
                }
            }
            _srcImage.UnlockBits(srcBmData);
        }
Ejemplo n.º 2
0
        public static Bitmap binarization(Bitmap bitmap, int value)
        {
            int width  = bitmap.Width;
            int height = bitmap.Height;

            System.IntPtr srcScan, dstScan;
            BitmapData    srcBmData, dstBmData;
            Bitmap        dstBitmap = ImageExtract.InitPonitMethod(bitmap, width, height, out srcScan, out dstScan, out srcBmData, out dstBmData);

            unsafe //啟動不安全代碼
            {
                byte *srcP = (byte *)srcScan;
                byte *dstP = (byte *)dstScan;
                int   srcOffset = srcBmData.Stride - width * 3;
                int   dstOffset = dstBmData.Stride - width * 3;
                byte  MAX = 255, MIN = 0;

                for (int y = 0; y < height; y++)
                {
                    for (int x = 0; x < width; x++, srcP += 3, dstP += 3)
                    {
                        *dstP = (srcP[0] > value) ? MAX : MIN;       //blue
                        *(dstP + 1) = (srcP[1] > value) ? MAX : MIN; //green
                        *(dstP + 2) = (srcP[2] > value) ? MAX : MIN; //red
                    }
                    srcP += srcOffset;
                    dstP += dstOffset;
                }
            }

            bitmap.UnlockBits(srcBmData);
            dstBitmap.UnlockBits(dstBmData);

            return(dstBitmap);
        }
Ejemplo n.º 3
0
            public static Bitmap extract(Bitmap bitmap, out byte[,] pix, out byte[,] resPix)
            {
                int    width = bitmap.Width, height = bitmap.Height;
                Bitmap dstBitmap = new Bitmap(bitmap);

                pix    = ImageExtract.getimageArray(bitmap);
                resPix = new byte[3, width *height];
                return(dstBitmap);
            }
        public Bitmap Process()
        {
            int width  = _srcImage.Width;
            int height = _srcImage.Height;

            System.IntPtr srcScan, dstScan;
            BitmapData    srcBmData, dstBmData;
            Bitmap        dstBitmap = ImageExtract.InitPonitMethod(_srcImage, width, height, out srcScan, out dstScan, out srcBmData, out dstBmData);


            unsafe //啟動不安全代碼
            {
                byte *srcP      = (byte *)srcScan;
                byte *dstP      = (byte *)dstScan;
                int   srcOffset = srcBmData.Stride - width * 3;
                int   dstOffset = dstBmData.Stride - width * 3;

                for (int y = 0; y < height; y++)
                {
                    for (int x = 0; x < width; x++, srcP += 3, dstP += 3)
                    {
                        bool isHightLight = false;
                        foreach (Point item in _targets)
                        {
                            if (x == item.X && y == item.Y)
                            {
                                for (int i = 0; i < 5; i++)
                                {
                                    int offset = i * 3;
                                    dstP[0 + offset] = 245;
                                    dstP[1 + offset] = 255;
                                    dstP[2 + offset] = 255;
                                }
                                isHightLight = true;
                            }
                        }

                        if (!isHightLight)
                        {
                            dstP[0] = srcP[0];
                            dstP[1] = srcP[1];
                            dstP[2] = srcP[2];
                        }
                    }
                    srcP += srcOffset;
                    dstP += dstOffset;
                }
            }

            _srcImage.UnlockBits(srcBmData);
            dstBitmap.UnlockBits(dstBmData);
            return(dstBitmap);
        }
Ejemplo n.º 5
0
        public Bitmap Process()
        {
            int width  = srcBitmap.Width;
            int height = srcBitmap.Height;

            System.IntPtr srcScan, dstScan;
            BitmapData    srcBmData, dstBmData;
            Bitmap        dstBitmap = ImageExtract.InitPonitMethod(srcBitmap, width, height, out srcScan, out dstScan, out srcBmData, out dstBmData);

            int limit = width - (width / SegmationSize);

            unsafe //啟動不安全代碼
            {
                byte *srcP      = (byte *)srcScan;
                byte *dstP      = (byte *)dstScan;
                int   srcOffset = srcBmData.Stride - width * 3;
                int   dstOffset = dstBmData.Stride - width * 3;


                for (int y = 0; y < height; y++)
                {
                    int count = 0;
                    int size  = 0;
                    for (int x = 0; x < width; x++, srcP += 3, dstP += 3)
                    {
                        if (srcP[ImageExtract.COLOR_R] == 0)
                        {
                            count++;
                        }
                        size++;
                    }

                    if (count > limit)
                    {
                        dstP = dstP - (3 * size);
                        for (int x = 0; x < width; x++, dstP += 3)
                        {
                            dstP[0] = dstP[1] = dstP[2] = 0;
                        }
                    }


                    srcP += srcOffset;
                    dstP += dstOffset;
                }
            }

            srcBitmap.UnlockBits(srcBmData);
            dstBitmap.UnlockBits(dstBmData);
            return(dstBitmap);
        }
Ejemplo n.º 6
0
        public Bitmap Process()
        {
            int width  = _srcImage.Width;
            int height = _srcImage.Height;

            System.IntPtr srcScan, dstScan;
            BitmapData    srcBmData, dstBmData;
            Bitmap        dstBitmap = ImageExtract.InitPonitMethod(_srcImage, width, height, out srcScan, out dstScan, out srcBmData, out dstBmData);


            unsafe //啟動不安全代碼
            {
                byte *srcP      = (byte *)srcScan;
                byte *dstP      = (byte *)dstScan;
                int   srcOffset = srcBmData.Stride - width * 3;
                int   dstOffset = dstBmData.Stride - width * 3;

                for (int y = 0; y < height; y++)
                {
                    for (int x = 0; x < width; x++, srcP += 3, dstP += 3)
                    {
                        if (y >= _rejectStart && y <= _rejectEnd)
                        {
                            dstP[0] = dstP[1] = dstP[2] = 0;
                        }
                        else
                        {
                            dstP[0] = dstP[1] = dstP[2] = srcP[2];
                        }

                        //byte gray = (byte)(.299 * srcP[2] + .587 * srcP[1] + .114 * srcP[0]);
                        //for (int c = 0; c < 3; c++)
                        //    *(dstP + c) = gray;
                    }
                    srcP += srcOffset;
                    dstP += dstOffset;
                }
            }

            _srcImage.UnlockBits(srcBmData);
            dstBitmap.UnlockBits(dstBmData);
            return(dstBitmap);
        }
        public Bitmap Process()
        {
            int width  = _srcImage.Width;
            int height = _srcImage.Height;

            System.IntPtr srcScan, dstScan;
            BitmapData    srcBmData, dstBmData;
            Bitmap        dstBitmap = ImageExtract.InitPonitMethod(_srcImage, width, height, out srcScan, out dstScan, out srcBmData, out dstBmData);


            unsafe
            {
                byte *srcP      = (byte *)srcScan;
                byte *dstP      = (byte *)dstScan;
                int   srcOffset = srcBmData.Stride - width * 3;
                int   dstOffset = dstBmData.Stride - width * 3;

                for (int y = 0; y < height; y++)
                {
                    for (int x = 0; x < width; x++, srcP += 3, dstP += 3)
                    {
                        if (_frameImageMap[x, y] > 0)
                        {
                            dstP[0] = 45;
                            dstP[1] = 45;
                            dstP[2] = 255;
                        }
                        else
                        {
                            dstP[0] = dstP[1] = dstP[2] = srcP[ImageExtract.COLOR_R];
                        }
                    }
                    srcP += srcOffset;
                    dstP += dstOffset;
                }
            }

            _srcImage.UnlockBits(srcBmData);
            dstBitmap.UnlockBits(dstBmData);
            return(dstBitmap);
        }
Ejemplo n.º 8
0
        public System.Drawing.Bitmap Process()
        {
            int width  = _srcImage.Width;
            int height = _srcImage.Height;

            System.IntPtr srcScan, dstScan;
            BitmapData    srcBmData, dstBmData;
            Bitmap        dstBitmap = ImageExtract.InitPonitMethod(_srcImage, width, height, out srcScan, out dstScan, out srcBmData, out dstBmData);

            unsafe //啟動不安全代碼
            {
                byte *srcP      = (byte *)srcScan;
                byte *dstP      = (byte *)dstScan;
                int   srcOffset = srcBmData.Stride - width * 3;
                int   dstOffset = dstBmData.Stride - width * 3;

                byte tempVal = 0;
                for (int y = 0; y < height; y++)
                {
                    tempVal = srcP[ImageExtract.COLOR_R];
                    for (int x = 0; x < width; x++, srcP += 3, dstP += 3)
                    {
                        int t = srcP[ImageExtract.COLOR_R] - tempVal;
                        dstP[0] = dstP[1] = dstP[2] = (byte)((t < 0) ? 0 : t);
                        tempVal = srcP[ImageExtract.COLOR_R];
                    }

                    srcP += srcOffset;
                    dstP += dstOffset;
                }
            }

            _srcImage.UnlockBits(srcBmData);
            dstBitmap.UnlockBits(dstBmData);
            return(dstBitmap);
        }