Deskew is a tool for deskewing scanned text documents. Deskewing is a term used for fixing the scans to get the lines of text straight. That means rotating the image of the scanned page a little to compensate for the misalignment of the paper in the scanner.
Deskew uses Hough transform to detect "text lines" in the image and their orientation. As an output, you get an image rotated so that the detected lines are horizontal. You can find more theory in introductory post Deskewing Scanned Documents if you are curious.
Deskew is a command line tool for Windows, Linux, and macOS. Simple GUI frontend also exists. Based on the user feedback and my own usage, I'd say it works quite well 🙂 On occasion, I think about stuff like: Deskew web app, GPU deskewing, Deskew app for Android, and even Deskew Photoshop plugin!
All Posts About Deskew
- Deskew CLI Tool v1.30 Released Posted on: June 19, 2019
- GUI Frontend for Deskew Posted on: December 4, 2018
- Deskew Tool v1.25 Released Posted on: May 23, 2018
- Deskew Tool v1.20 Released Posted on: November 29, 2016
- Deskew Tool Version 1.10 Posted on: March 7, 2014
- Deskew Tool Updated Posted on: June 6, 2012
- Deskewing Scanned Documents Posted on: January 5, 2011
Command line tool and GUI frontend downloads:
» 4.3 MiB - 18,643 hits - June 19, 2019
Command line tool for deskewing scanned documents. Binaries for several platforms, test images, and Object Pascal source code included.
» 4.1 MiB - 5,200 hits - March 18, 2019
GUI frontend for Deskew command line tool. Prebuilt binaries for Windows, macOS, and Linux. Windows and Linux versions need Deskew command line tool binaries.
Bug Reports & Feature Proposals
Please report bugs and propose enhancements and new features in Deskew's issue tracker:
Deskew's sources are hosted here:
If you want to donate to Deskew Tools you can click Sponsor button at Deskew's GitHub page.
I tried to use this amazing tool in ubuntu server 64 bit using deskew64 command line, I got the following error:
./deskew64: error while loading shared libraries: libtiff.so.5: cannot open shared object file: No such file or directory
Make sure you have libtiff5 package installed in Ubuntu (not libtiff4 or 3).
Thank you, actually I have Ubuntu Server 12.04, in order to include libtiff5 package I have to upgrade at least to Ubuntu Server 12.10.
Unfortunately, there’s tiny API change going from libtiff4 to libtiff5. Deskew can work with only one of them – so I chose the newer one.
Elegant, excellent. Thank you.
The precompiled ../Bin/deskew works flawlessly under Linux openSUSE 13.1 64-bit.
I’ll give you a plug on my site shortly.
Thank you again.
Great to hear this, thanks.
Nice program to deskew an image. Is there an option to generate the output with no loss in quality ? I have noticed that JPEGs get compressed to lesser quality.
You can use PNG instead of JPEG as output format to get lossless result.
Tesseract OCR does not deskew pages and this makes a difference. I use xsane2tess.pl to call Tesseract from XSane. I edited my own version of xsane2tess.pl to include a deskew command. (Many thanks for Deskew!) My page http://www.d-meeus.be/linux/TesseractXSane.html is in French but you could guess… enough to download my own xsane2tess.pl.
Can i get 600 dpi resolution output. it’s my requirement.
You might can use this program to find your angle, then rotate using another method.
Can you explain how to simply find the angle but not rotate using this tool? Since I’m dealing with archival TIFFs I need to keep the DPI and embedded metadata in place, so I’m thinking I would use ImageMagick to rotate once I have the angle. Thanks.
For now you could use -l parameter:
-l angle: Skip deskewing step if skew angle is smaller
And use some large threshold so rotation will always be skipped.
$deskew -l 80 Sken003.png
Preparing input image (Sken003.png) ...
Calculating skew angle...
Skew angle found: 0.23
Skipping deskewing step, skew angle lower than threshold of 80.00
For next version I plan to modify this: angle is optional and if omitted rotation is always skipped.
When deskewing images and converting from one format to another (for example, from jpg to tif) if the source image is not deskewed (rotation angle smaller than the default 0.01) then the source image is simply copied to the output image without conversion to the appropriate format, which results in files with wrong extension.
For example, running this command on an image that doesn’t need deskewing (can happen in batch files)
deskew -t 200 -o image_001.tif -b FFFFFF image_001.jpg
will simply copy image_001.jpg to image_001.tif WITHOUT actually converting it to TIFF format.
The workaround at the moment is to specify -l 0 or to convert every file to destination format prior to deskewing.
Other than this minor bug, deskew is an excellent program.
Thank very much.
Thanks for reporting this, will be fixed in the next release.
I just discovered this outstanding tool.
I am working for a non-profit organization operating a digitization shop. We are now in the process of scanning a lot of old newspapers, as well as old books, etc. After being created by the scanners, some image files are post-processed through a automated workflow using ImageMagick, LibTiff tools and Adobe Acrobat. Some originals are very difficult to align properly and their images come out with small amounts of skew, for example when the content does not properly align with the paper it is printed on. When viewed in the isolated, rectangular environment that a computer screen is, even small amounts of skew, in the order of little more than 0.1 degrees, are clearly visible and produce a bad impression on the reader.
Your tool is the first one giving us very satisfactory results. The deskewing function included in Acrobat does a mediocre job, often even tilting pages that previously were optically aligned. Your tool, with its very good deskewing, the possibility of setting a minimum threshold for deskewing, and the command line interface, is the ideal for the job.
Meanwhile, it has two aspects that I would like to modify by recompiling it:
— The density unit is defined in pixels per cm. Although this does not cause any problem in isolated images, I discovered that when the files rotated and not rotated by Deskew are combined in a multipage Tiff file, the rotated pages appear with a different size when imported into Adobe Acrobat. Either tiffcp or Acrobat (I can investigate which one later) gets confused by the mixing of units in different pages. I am using ImageMagick convert with the -units command to process the files after coming out from Deskew. It works but it is inelegant and introduces an additional step.
— Deskew compresses the modified images with LZW. Although this is alright for many purposes, it is unnecessary in our case and causes a small delay for each file, which can turn into a lot when we are talking about thousands of files in sequence. Although the ideal would be to chose the type of compression, including none, for now I would like to set the default to no compression.
I looked into the source files and I think I know where I can make the slight modifications mentioned above. So I tried to compile the code using Free Pascal but the build stops with the following error:
deskew.lpr(47,1) Error: Undefined symbol: __TIFFerrorHandler
deskew.lpr(47,1) Error: Undefined symbol: __TIFFwarningHandler
deskew.lpr(47,1) Fatal: There were 2 errors compiling module, stopping
Fatal: Compilation aborted
Although I often build software,I am not a programmer and my knowledge of these matters is very limited. When an error like this appears, I’m stuck. Although, of course, I can search for information, it would take a while, which is not compatible with my current enthusiasm with this tool. I really would like to further experiment with it.
Can you please give me some hint about what to do to solve this? Furthermore, I would like a Win64 build and I don’t know how to do it. Pascal is a complete stranger to me.
Thank you for offering us this very nice work. I don’t understand why a lot more people don’t know about it.
As we later discussed by email FPC version 3+ has some problems linking with precompiled LibTiff (Windows build). For time being use latest version of FPC 2 please.
This is now fixed so Deskew for Windows can be built with FPC 3+ as well.
Thank you. Excellent. I’,m newbie. Please help.
I have many thousands scanned .tif files, and I need a batch script .bat for this utility.
.Tif files exist in PICTURE1 folder, I’d like to run and deskewing files copy to PICTURE2 folder. How to write this script .bat ???.
This is a very great tool! Many thanks!
Using version 1.20 on Mac OS X 10.10.5, I noticed that deskewing .png files would result in output .png files, which are to a small degree blurrier than the original. This is a problem for me with low quality input files.
What can I do?
You could use Deskew just to find the skew angle and then rotate in some other program with better rotation output (ImageMagick maybe).
Thanks again for this great tool.
One issue I’m facing is when there is a small percentage of text on a page that is purposefully skewed (on a diagonal). Is there a way to ignore a percentage of lines of text if it’s below a certain threshold?
Here’s an example of a page that consistently gets deskewed at the wrong angle due to intentional diagonal text: https://www.dropbox.com/s/pvnpf890721z2h4/BAR_19931230_004.jpg?dl=0
You can try running deskew on just a part of the page, see “-r” parameter.
Love the deskew tool, but I have noticed that it changes the dpi of all the images to 46dpi from 300dpi.
I do apologise. I have just done some tests and it isn’t the deskew tool that changes the dpi, it is the program I use to crop afterwards.
Any advice to use the Deskew “tool” in Gimp as a plugin.
It works nice as a stand alone, but I’m converting a book from paper to document, using “gimagereader” extract the texts and Gimp to cut out the images (that are rarely straight), then straigthen them with the rotation tool there, eventuality also use the perspective tool if they are not perfectly rectangular.
There are is an older deskew tool in gimp, but does not work (does not compile properly).
I am not able to use deskew on linux.
I have downloaded zip file and extracted in home folder.
however it gives error- deskew command not found.
can u tell me proper installations steps please?
Maybe just exec permission is not set on the file:
chmod +x deskew
Deskew is an excellent tool and a huge time saver!
I have long been looking for a comfortable way to automatically straighten skewed scans of text documents. Deskew does exactly that – no more, no less. Adapting the test bat file for my specific situation was easy even for me who doesn’t know the first thing about programming or scripting.
However, Deskew would be of even greater use to me (or anyone, I gather) if I were able to process all the image files in a folder without having to add a separate line in the batch script for every file. There must be a way, I suppose …
I apologize for my complete ignorance and would very much appreciate if you could give me some hint/advice on how I would have to adapt the script for that purpose.
In a batch file you can iterate over all files in the folder: http://goo.gl/B4CU6
Anyway, I’m now planning a simple GUI frontend for Deskew that will do “many files at once” deskewing.
Thanks for your reply and the link to stack overflow.
I’m afraid the explanations I found there on how to iterate a command in a batch file are just beyond my abilities, though, as weird as that may sound to a crack coder.
So I really appreciate your plan to develop a GUI for people like me. Can’t wait to use it!
The GUI is now available!
This tool is not working for above 20degrees skew image.
how to implement deskew with above 20degrees skewed images,
give me any suggestions for solve my problem, Thank you
You can try set wider search angle with -a parameter: deskew -a 40 ….
This doesn’t support the multipage tiff.
How to do it?
This is a fantastic tool made even better with the introduction of the GUI.
I use this tool all the time on magazine pages scanned as raw files and it is a HUGE time saver for me. Even if I have to correct a few images where it doesn’t interpret them properly here or there, I simply cannot recommend it highly enough if you have a requirement for straightening large quantities of scanned images.
On windows with Deskew 1.25 and GUI, can not find the rotated pixtures in directory. !
Only a visible in the add windows, not in explorer .
Have you an solution?
DeskewGUI on macOS 10.14 doesn’t seem to like TIFF images.
Deskew 1.27 (2018-09-07) x64 by Marek Mauder
Error: File format not supported: Scan.tiff
file Scan.tiff: TIFF image data, big-endian, direntries=18, height=4200, bps=1, compression=bi-level group 4, PhotometricIntepretation=BlackIsZero, model=Brother ADS-2800W, orientation=upper-left, width=2539
This was captured by the macOS Image Capture tool.
Deskew on Mac needs LibTIFF installed on the system by default. For GUI I’ve now included LibTIFF binaries in GUI’s Mac app bundle so please re-download it to get the updated version.
Excellent tool, thanks, Marek!
Just one question: my (only greyscale) PNG files become roughly 7 times larger after deskewing. Can that be avoided? A PNG file of 100KB is 700KB after this command:
Deskew 1.25 (2018-05-19) x64 by Marek Mauder
Preparing input image (scan.png) …
Calculating skew angle…
Skew angle found [deg]: 4.980
Could you upload that file somewhere?
Sure. Here’s the original scan (103 KB): https://c.gmx.net/@319022631263142077/6UE6k01TQTCzXp4nendnwg
Here’s the deskewed result (700 KB): https://c.gmx.net/@319022631263142077/AHak1A-BReGZMVqvm-iGIQ
Yes, here’s the original file: https://c.gmx.net/@319022631263142077/6UE6k01TQTCzXp4nendnwg
and the much larger deskewed file: https://c.gmx.net/@319022631263142077/AHak1A-BReGZMVqvm-iGIQ
Why is the file size so much more and can that be avoided? I’m dealing with heaps of scans…Thanks for getting back.
You original image is 1bit (black and white) only so the smallest it can get. Deskew saves rotated image in 8bit greyscale by default (for 1bit input) because there’s many new “colors” introduced by filtered rotation.
Anyway, you can force the output to be 1bit like this:
deskew -f b1 scan.png
Thanks a lot, works like a charm!
I have found an issue, but I would need to send you an image.
I have a receipt that is perfectly straight, angle=0.
Receipt is clear and normal, except that it has one red line in a middle of receipt with angle=15.
When I do deskew without any arguments, it’s ok.
But when I put deskew -a 25, it rotates receipt 3 degrees right.
I don’t understand why this is happening, it’s not consistent behaviour.
Please send the image for test.
How to send image?
Here is the image
Did you see this?
Yes I saw it, looks like a standard image that should be ideal for Deskew but it determines it is skewed. I’ll keep it for testing but for now I have no solution sorry.