Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Detect skew angle only (no rotation done) #5

Closed
galfar opened this issue Oct 26, 2017 · 7 comments
Closed

Detect skew angle only (no rotation done) #5

galfar opened this issue Oct 26, 2017 · 7 comments

Comments

@galfar
Copy link
Owner

galfar commented Oct 26, 2017

Original report by Marek Mauder (Bitbucket: galfar, GitHub: galfar).


As requested on blog:

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.

Answer:

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
Done!

For next version I plan to modify this: angle is optional and if omitted rotation is always skipped.

@galfar
Copy link
Owner Author

galfar commented Oct 26, 2017

Original comment by Marek Mauder (Bitbucket: galfar, GitHub: galfar).


We must distinguish between these cases:

  1. Detection only - no output file created
  2. Detected small angle - no rotation done but output file created in requested format (see Issue Doesn't compile on Arch Linux #4).

@galfar
Copy link
Owner Author

galfar commented Nov 11, 2017

Original comment by Miguel Medalha (Bitbucket: Medalha, GitHub: Medalha).


I discovered that images rotated by ImageMagick's "convert" or "mogrify", using the angle provided by Deskew, look a bit sharper than those rotated by Deskew itself, probably due to differences in processing methods (calculating the redistribution of pixels) between the imaging libraries used. This is important because any rotation which is not at 90 degree multiples always somewhat softens the image, degrading it more or less. Obviously, less is preferable.

Deskew is specially good at detecting the skew angle of an image. It would be nice being able to get the skew angle provided by Deskew and use it to rotate the image with any other program. To experiment with this, I came up with a "quick and dirty" solution for now. I went to the source file "MainUnit.pas" and made a few modifications which enable me to get as the only output the skew angle, already inverted (multiplication by -1) to provide the rotation needed, not the skew angle itself. This value is then directly passed to "magick mogrify -rotate" as a parameter, through an environment variable. Mogrify rotates the image and rewrites it while respecting the embedded metadata.

In my view, Deskew would benefit greatly from being able to satisfy what I suppose are the two main cases: those who want to use all its functionality as is, producing the final images, and those who would like to integrate it in a broader workflow.

Relating to what I just exposed (skipping for now other needs such as the type of compression, etc.) I propose the creation of the following new command line switches:

-g for "getting" as output only the needed rotation angle (the inverse of the skew angle).

-q for "quiet" (Deskew's output is a little bit "chatty" for integration into an automated workflow).

Of course these letters are only examples, albeit logic ones

(In the case of quiet operation, a log option would also be desirable?).

Thank you again. Regards.

@galfar
Copy link
Owner Author

galfar commented Nov 26, 2017

Original comment by Marek Mauder (Bitbucket: galfar, GitHub: galfar).


Good idea, something like this will be in!

@galfar
Copy link
Owner Author

galfar commented May 17, 2019

Original comment by Marek Mauder (Bitbucket: galfar, GitHub: galfar).


As requested on blog:

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.

Answer:

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
Done!

For next version I plan to modify this: angle is optional and if omitted rotation is always skipped.

@galfar
Copy link
Owner Author

galfar commented Jun 6, 2019

Original comment by Marek Mauder (Bitbucket: galfar, GitHub: galfar).


@galfar galfar closed this as completed Jun 6, 2019
@galfar
Copy link
Owner Author

galfar commented Jun 11, 2019

Original comment by Miguel Medalha (Bitbucket: Medalha, GitHub: Medalha).


I appreciate your effort in introducing this feature. Nevertheless, as it is it cannot be used to integrate a wider workflow. What would be needed, as I explained above, is a simple output of the rotation angle needed to deskew the image, i.e. in MainUnit.pas remove all output except the following:

WriteLn(SkewAngle * -1:4:3);

This could be obtained by a new flag under the -g parameter.

In this way, the program’s output can be passed to any other program or file, giving your program increased versatility.

Thank you again.

Miguel

@galfar
Copy link
Owner Author

galfar commented Jun 11, 2019

Original comment by Miguel Medalha (Bitbucket: Medalha, GitHub: Medalha).


Here’s an example of a workflow I used with ImageMagick, after doing the aforementioned modification to MainUnit.pas:

for /F %%r in ('deskew -g d "%ClientPath%%JobDir%%JobName%-%PageNum%.tif.tmp.tif"') do set Rotation=%%r
magick mogrify ^
-background OrangeRed ^
-rotate %Rotation% ^
-units PixelsPerInch ^
-resample 300x300 ^
+repage ^
"%ClientPath%%JobDir%%JobName%-%PageNum%.tif.tmp.tif"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant