Example #1
0
        public override IImage Clone()
        {
            ImageGrad img = new ImageGrad(this.Width, this.Height);

            img.CloneFrom(this);
            return(img);
        }
        public unsafe ImageGrad CreateGradImage(Boolean computeDirection = true)
        {
            int step = this.Step;

            using (ImageChannel32 gradX = new ImageChannel32(this.Width, this.Height))
                using (ImageChannel32 gradY = new ImageChannel32(this.Width, this.Height))
                {
                    CopyToIntChannel(this, gradX);
                    CopyToIntChannel(this, gradY);
                    gradX.ApplyConvolution(ConvolutionKernel.SobelX);
                    gradY.ApplyConvolution(ConvolutionKernel.SobelY);
                    ImageGrad grad   = new ImageGrad(this.Width, this.Height);
                    Int32 *   xStart = (Int32 *)gradX.StartIntPtr;
                    Int32 *   yStart = (Int32 *)gradY.StartIntPtr;
                    Grad *    g      = grad.Start;
                    Grad *    gEnd   = g + grad.Length;
                    if (computeDirection == true)
                    {
                        while (g != gEnd)
                        {
                            Int32 x     = *xStart;
                            Int32 y     = *yStart;
                            float f     = (float)Math.Sqrt(x * x + y * y);
                            float theta = (float)Math.Atan2(x, y);
                            g->Value = f;
                            g->Theta = theta;
                            xStart++;
                            yStart++;
                            g++;
                        }
                    }
                    else
                    {
                        while (g != gEnd)
                        {
                            Int32 x = *xStart;
                            Int32 y = *yStart;
                            float f = (float)Math.Sqrt(x * x + y * y);
                            g->Value = f;
                            g->Theta = 0;
                            xStart++;
                            yStart++;
                            g++;
                        }
                    }

                    return(grad);
                }
        }