Algorithmix.Preprocessing.Preprocessing.Orient C# (CSharp) Method

Orient() public static method

Rotates the blobs to be vertical
public static Orient ( Bitmap blob ) : Bitmap
blob System.Drawing.Bitmap image blob to orient
return System.Drawing.Bitmap
        public static Bitmap Orient(Bitmap blob)
        {
            int width = blob.Width;
            int height = blob.Height;
            int area = width * height;
            Image<Bgra, Byte> blobb = new Image<Bgra, byte>(blob);
            Rectangle crop = GetCropZone(blobb);
            System.Drawing.Point trPoint = new System.Drawing.Point(crop.Right, crop.Top);
            System.Drawing.Point blPoint = new System.Drawing.Point(crop.Left, crop.Top);
            double slope = Utility.SlopeFromPoints(trPoint, blPoint);
            double angle = Math.Atan(slope);
            float angleToRotate = (float)(90.0 - angle);
            Bitmap rotated = RotateImg(blobb.ToBitmap(), angleToRotate, Color.Transparent);
            if (rotated.Height < rotated.Width)
            {
                return RotateImg(blobb.ToBitmap(), angleToRotate + 90, Color.Transparent);
            }
            if (DOUBLE_ROTATE)
            {
                rotated = Orient_Step2(rotated);
            }
            return rotated;
        }