Home : Image Processing : Image Clean-up/Correction Techniques : Deskewing a Color Image
Q10188 - HOWTO: Deskewing a Color Image

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;
   
}
}

Related Articles
No Related Articles Available.

Article Attachments
No Attachments Available.

Related External Links
No Related Links Available.
Help us improve this article...
What did you think of this article?

poor 
1
2
3
4
5
6
7
8
9
10

 excellent
Tell us why you rated the content this way. (optional)
 
Approved Comments...
No user comments available for this article.

Powered By InstantKB.NET v1.3
Copyright © 2002, 2017. InstantASP Ltd. All Rights Reserved