コード例 #1
0
        private int DualGradient(int x, int y)
        {
            Pixel24b yUp       = GetPixelY(x, y + 1);
            Pixel24b yDown     = GetPixelY(x, y - 1);
            int      yGradient = (yUp.r - yDown.r) * (yUp.r - yDown.r) + (yUp.g - yDown.g) * (yUp.g - yDown.g) + (yUp.b - yDown.b) * (yUp.b - yDown.b);

            Pixel24b xLeft     = GetPixelX(x - 1, y);
            Pixel24b xRight    = GetPixelX(x + 1, y);
            int      xGradient = (xRight.r - xLeft.r) * (xRight.r - xLeft.r) + (xRight.g - xLeft.g) * (xRight.g - xLeft.g) + (xRight.b - xLeft.b) * (xRight.b - xLeft.b);

            return(xGradient + yGradient);
        }
コード例 #2
0
        private void PopulateBitmapMatrix()
        {
            BitmapData bmData = this.edge.LockBits(new Rectangle(0, 0, this.edge.Width, this.edge.Height), ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb);


            int size   = bmData.Stride * bmData.Height;
            int width  = this.edge.Width;
            int height = this.edge.Height;

            byte[] p = new byte[size];

            System.Runtime.InteropServices.Marshal.Copy(bmData.Scan0, p, 0, size);
            int x = 0;
            int y = 0;

            for (int i = 0; i < size; i += 3)
            {
                if (x == width)
                {
                    x = 0;
                    y++;
                    if (y == height)
                    {
                        break;
                    }
                }

                Pixel24b px = new Pixel24b();
                px.r = p[i + 2];
                px.g = p[i + 1];
                px.b = p[i];

                this.bitmapMatrix[y, x] = px;

                x++;
            }
            this.edge.UnlockBits(bmData);
        }