Copyright © Fred Weinhaus My scripts are available free of charge for non-commercial (non-profit) use, ONLY. For use of my scripts in commercial (for-profit) environments or non-free applications, please contact me (Fred Weinhaus) for licensing arrangements. My email address is fmw at alink dot net. If you: 1) redistribute, 2) incorporate any of these scripts into other free applications or 3) reprogram them in another scripting language, then you must contact me for permission, especially if the result might be used in a commercial or for-profit environment. Usage, whether stated or not in the script, is restricted to the above licensing arrangements. It is also subject, in a subordinate manner, to the ImageMagick license, which can be found at: http://www.imagemagick.org/script/license.php Please read the Pointers For Use on my home page to properly install and customize my scripts. |
Automatically unrotates a rotated image and trims the surrounding border. |
last modified: September 01, 2022
USAGE: unrotate [-f fuzzval] [-c coords] [-C color] [-a angle] [-l left] [-r right ] [-t top ] [-b bottom ] infile [outfile]
-f .... fuzzval .... fuzz value for determining border color; PURPOSE: To unrotate a rotated image and trim the surrounding border. DESCRIPTION: UNROTATE computes the amount an image has been rotated and attempts to automatically unrotate the image. It assumes that the image contains a border area around the rotated data and that one must identify a coordinate within the border area for the algorithm to extract the base border color. A fuzz value should be specified when the border color is not uniform, but also because the edge of rotated image is a blend of image and border color. Thus, the fuzz value must be a compromise. If too large, the rotation angle will not be accurate. If too small, the blended edge around unrotated image will not be trimmed enough. The rotation angle displayed by the script for an appropriate fuzz value will typically be within a few tenths of a degree of the correct value. However, if the results are not accurate enough or there is still some border showing, you may rerun the script on the original image again and either specify an adjusted rotation angle or use the left/right/top/bottom arguments to specify extra trim. ARGUMENTS: -f fuzzval --- FUZZVAL is the fuzz amount specified as a percent 0 to 100 (without the % sign). The default is zero which indicates that border is a uniform color. Larger values are needed when the border is not a uniform color and to trim the border of the rotated area where the image data is a blend with the border color. -c coords --- COORDS is any location within the border area for the algorithm to find the base border color. It may be specified in terms of gravity parameters (NorthWest, North, NorthEast, East, SouthEast, South, SouthWest or West) or as a pixel coordinate "x,y". The default is the upper left corner = NorthWest = "0,0". -C color ... COLOR of border or background. Any valid IM color is allowed. The default is to use coords to get color. -a angle --- ANGLE is the rotation angle needed to unrotate the picture data within the image. The default (no argument) tells the algorithm to automatically estimate the rotation angle. One may override the automatic determination and specify your own value. Values are positive floats between -45 and 45 degrees. Note that the algorithm cannot correct beyond 45 degrees and cannot distinguish between exactly +45 degrees and exactly -45. Therefore you may need to do a 90, 180, or 270 degree rotation after using this script. If the outfile is left off, then the script will simply report the rotation angle needed to unrotate the image. -l left --- LEFT is the number of extra pixels to shift the trim of the left edge of the image. The trim is shifted right/left for +/- integer values. The default=0. -r right --- RIGHT is the number of extra pixels to shift the trim of the right edge of the image. The trim is shifted right/left for +/- integer values. The default=0. -t top --- TOP is the number of extra pixels to shift the trim of the top edge of the image. The trim is shifted down/up for +/- integer values. The default=0. -b bottom --- BOTTOM is the number of extra pixels to shift the trim of the bottom edge of the image. The trim is shifted down/up for +/- integer values. The default=0. CAVEAT: No guarantee that this script will work on all platforms, nor that trapping of inconsistent parameters is complete and foolproof. Use At Your Own Risk. |
Unrotation Of Rotated Square Image |
|||||
Rotated -45 deg |
Rotated 45 deg |
Rotated -20 deg |
Rotated 10 deg |
Rotated -5 deg |
Rotated 2 deg |
Arguments: |
Arguments: |
Arguments: |
Arguments: |
Arguments: |
Arguments: |
Rotation: 45.00o |
Rotation: 45.00o |
Rotation: 20.08o |
Rotation: -9.62o |
Rotation: 4.55o |
Rotation: -2.60o |
Unrotation Of -20o Rotated Square Image - Variation Of Fuzz Value |
||||||
Original: |
Arguments: |
Arguments: |
Arguments: |
Arguments: |
Arguments: |
Arguments: |
Rotation: 19.90o |
Rotation: 19.94o |
Rotation: 20.08o |
Rotation: 20.08o |
Rotation: 19.73o |
Rotation: 20.19o |
Unrotation Of -20o Rotated Square Image With Extra Border |
|
Original: |
Arguments: |
Rotation: 20.08o |
Unrotation Of 10o Rotated Square Image With Extra Trim |
||
Original: |
Arguments: |
Arguments: |
Rotation: -9.62o |
Rotation: -9.62o |
Unrotation Of Rotated Rectangular Image |
|||||
Rotated -45 deg |
Rotated -20 deg |
Rotated 10 deg |
Rotated -5 deg |
Rotated 2 deg |
|
Arguments: |
Arguments: |
Arguments: |
Arguments: |
Arguments: |
|
Rotation: 45.00o |
Rotation: 19.91o |
Rotation: -9.89o |
Rotation: 4.80o |
Rotation: -1.56o |
What the script does is as follows:
|