机器视觉入门之路(四九---B,神奇的线图像的设计D(完整代码))

以下是DdaFindPtImprove函数的完整代码,完整代码,完美运行。

  public PointF DdaFindPtImprove(ref byte[] buffer8, PointF Start, PointF End, int thresDelta, int Dir, Size wh, ref int Pos)
        {
            float x, y;
            float dx, dy, k;
            PointF backPoint = new PointF();

            dx = (float)(End.X - Start.X);
            dy = (float)(End.Y - Start.Y);
            k = dy / dx;
            if (Math.Abs(dx) < 0.001)
            {
                k = 65535;//随意给定一个最大值,还需论证。20150727
            }
            x = Start.X;
            if (Start.Y < 0) Start.Y = 0;
            y = Start.Y;

            List<float> temparrclor = new List<float>();
            List<PointF> position = new List<PointF>();
            #region xiaoyu1
            if (Math.Abs(k) < 1)
            {
                if (x > End.X)
                {
                    for (; x >= End.X; x--)
                    {
                        float j = y;
                        int i = (int)(x);
                        float tempf = Math.Abs(j - (int)j);
                        PointF tempPt = new PointF(i, j);
                        float grey = 0;
                        if (k > -1 && k <= 0)
                        {
                            float avgGrey = (float)buffer8[(int)j * wh.Width + i];
                            float avgGrey1 = (float)buffer8[((int)j + 1) * wh.Width + i];
                            grey = avgGrey * (1 - tempf) + avgGrey1 * tempf;
                        }
                        else
                        {
                            float avgGrey = (float)buffer8[(int)j * wh.Width + i];
                            float avgGrey1 = (float)buffer8[((int)j - 1) * wh.Width + i];
                            grey = avgGrey * (1 - tempf) + avgGrey1 * tempf;
                        }
                        temparrclor.Add(grey);
                        position.Add(tempPt);

                        y = y - k;
                    }
                    //  backPoint = FindCrosspoint(ref temparrclor, ref position, Dir, thresDelta); 
                    backPoint = FindCrosspointimprove(ref temparrclor, ref position, Dir, thresDelta, ref Pos);//测试纯色区域影响0804
                }
                else
                {
                    temparrclor.Clear();
                    position.Clear();
                    for (; x <= End.X; x++)
                    {
                        float j = y;
                        int i = (int)(x);
                        float tempf = Math.Abs(j - (int)j);
                        PointF tempPt = new PointF(i, j);
                        float grey = 0;
                        if (k < 1 && k >= 0)
                        {
                            float avgGrey = (float)buffer8[(int)j * wh.Width + i];
                            float avgGrey1 = (float)buffer8[((int)j + 1) * wh.Width + i];
                            grey = avgGrey * (1 - tempf) + avgGrey1 * tempf;
                        }
                        else
                        {
                            float avgGrey = (float)buffer8[(int)j * wh.Width + i];
                            float avgGrey1 = (float)buffer8[((int)j - 1) * wh.Width + i];
                            grey = avgGrey * (1 - tempf) + avgGrey1 * tempf;
                        }
                        temparrclor.Add(grey);
                        position.Add(tempPt);

                        y = y + k;
                    }
                    //   backPoint = FindCrosspoint(ref temparrclor, ref position, Dir, thresDelta); 
                    backPoint = FindCrosspointimprove(ref temparrclor, ref position, Dir, thresDelta, ref Pos);//测试纯色区域影响0804
                }
            }

            #endregion xiaoyu1
            #region dayu1
            if (Math.Abs(k) >= 1)
            {

                if (y > End.Y)
                {
                    temparrclor.Clear();
                    position.Clear();
                    for (; y >= End.Y; y--)
                    {
                        int j = (int)(y);
                        float i = x;

                        float tempf = Math.Abs(i - (int)i);
                        PointF tempPt = new PointF(i, j);
                        float grey = 0;

                        if (k > 1)
                        {
                            float avgGrey = (float)buffer8[j * wh.Width + (int)i];
                            float avgGrey1 = (float)buffer8[j * wh.Width + (int)i - 1];
                            grey = avgGrey * (1 - tempf) + avgGrey1 * tempf;
                        }
                        else
                        {
                            float avgGrey = (float)buffer8[j * wh.Width + (int)i];
                            float avgGrey1 = (float)buffer8[j * wh.Width + (int)i + 1];
                            grey = avgGrey * (1 - tempf) + avgGrey1 * tempf;
                        }
                        temparrclor.Add(grey);
                        position.Add(tempPt);

                        x = x - 1 / k;
                    }
                    // backPoint = FindCrosspoint(ref temparrclor, ref position, Dir, thresDelta); 
                    backPoint = FindCrosspointimprove(ref temparrclor, ref position, Dir, thresDelta, ref Pos);//测试纯色区域影响0804
                }
                else
                {
                    temparrclor.Clear();
                    position.Clear();
                    for (; y <= End.Y; y++)
                    {
                        int j = (int)(y);
                        float i = x;

                        PointF tempPt = new PointF(i, j);
                        float tempf = Math.Abs(i - (int)i);

                        float grey = 0;
                        if (k < -1)
                        {
                            float avgGrey = (float)buffer8[j * wh.Width + (int)i];
                            float avgGrey1 = (float)buffer8[j * wh.Width + (int)i - 1];
                            grey = avgGrey * (1 - tempf) + avgGrey1 * tempf;
                        }
                        else
                        {
                            float avgGrey = (float)buffer8[j * wh.Width + (int)i];
                            float avgGrey1 = (float)buffer8[j * wh.Width + (int)i + 1];
                            grey = avgGrey * (1 - tempf) + avgGrey1 * tempf;
                        }
                        temparrclor.Add(grey);
                        position.Add(tempPt);

                        x = x + 1 / k;
                    }
                    //  backPoint = FindCrosspoint(ref temparrclor,ref position,Dir,thresDelta);
                    backPoint = FindCrosspointimprove(ref temparrclor, ref position, Dir, thresDelta, ref Pos);  //测试纯色区域影响0804
                }
            }
            #endregion dayu1
            return backPoint;
        }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值