图片旋转及得到倾斜度(未加验证是否正确)

本文介绍了一种图像处理方法,该方法首先通过遍历图像像素并应用数学公式来提取图像特征,随后对图像进行旋转处理。核心步骤包括计算每个像素点在不同角度和半径下的投影值,并统计这些投影值以确定图像的主要方向。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

            int lHeight = bmpobj.Height;
            int lWidth = bmpobj.Width;
            int iRow, iCol;
            int radius, angle, x, y;
            double a;
            int d;
            d = Convert.ToInt32(System.Math.Sqrt(lHeight * lHeight + lWidth * lWidth));
            double p = 3.1415926 / 180;
            int[,] temp = new int[360, d];

            for (iRow = 0; iRow < lHeight; iRow++)
            {
                for (iCol = 0; iCol < lWidth; iCol++)
                {
                    if (bmpobj.GetPixel(iCol, iRow).R < 128)
                    {
                        x = iCol;
                        y = iRow;

                        for (angle = 0; angle < 360; angle++)
                        {
                            a = angle * p;
                            radius = Convert.ToInt32((double)x * System.Math.Cos(a) + (double)y * System.Math.Sin(a));
                            temp[angle, radius > 0 ? radius : -radius]++;
                        }

                    }
                }
            }
                 
            int max = 0;
            int R;
            int s = 0, l = 0;
            for (iRow = 0; iRow < 360; iRow++)
            {
                for (iCol = 0; iCol < d; iCol++)
                {
                   if (temp[iRow, iCol] > max)
                    {
                        max = temp[iRow, iCol];
                        s = iRow;
                        l = iCol;
                    }

                }
            }

 

    

        //bomobj 原始img图片
            int w = bmpobj.Width, h = bmpobj.Height;
            Bitmap result = new Bitmap(w, h);
            using (Graphics g = Graphics.FromImage(result))
            {
                g.TranslateTransform(w / 2, h / 2);
                g.RotateTransform(-1);
                g.TranslateTransform(-w / 2, -h / 2);
                g.DrawImageUnscaled(bmpobj, 0, 0);
            }       
            result.Save("c://a.bmp");

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值