Search

Atalasoft Knowledge Base

HOWTO: Deskew a Color Image

Administrator
DotImage

AutoDeskewCommand only operates on 1 bpp images. If you set its ApplyToAnyImageFormat to true, it will deskew the image, but it will first convert the image to 1bpp. ApplyToAnyImageFormat should be avoided whenever possible, You should always use a Threshold command such as DynamicThresholdCommand, GlobalThresholdCommand, or AdaptiveThresholdCommand to convert it to bitonal first.

If you want to deskew a color image and preserve the color in the original, image, you should use the AutoDeskewCommand against a bitonal COPY of the image to GetDeskewAngle()convert), but then get the SkewAngle from the results and apply a RotateCommand to the original image that rotates the negative of the SkewAngle. Here's some sample code.

static AtalaImage DeskewImage(AtalaImage image, System.Drawing.Color bgColor)
{
    AutoDeskewCommand deskew = new AutoDeskewCommand();

    if (image.PixelFormat != PixelFormat.Pixel1bppIndexed)
    {
        DynamicThresholdCommand threshold = new DynamicThresholdCommand();
        AtalaImage bitonalImg = threshold.Apply(image).Image;

        double angle = deskew.GetDeskewAngle(bitonalImg);
        bitonalImg.Dispose();

        RotateCommand rotate = new RotateCommand(-angle);
        rotate.BackgroundColor = bgColor;

        AtalaImage rotImage = rotate.Apply(image).Image;
        image.Dispose();

        return rotImage;
    }
    else
    {
        return deskew.Apply(image).Image;
    }
}

Original Article:
Q10188 - HOWTO: Deskewing a Color Image

Details
Last Modified: 6 Years Ago
Last Modified By: Administrator
Type: HOWTO
Article not rated yet.
Article has been viewed 907 times.
Options
Also In This Category