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. |
Crops an image to the largest rectangle that will just trim any irregularly shaped outer boundary color. |
last modified: November 23, 2020
USAGE: innercrop [-o ocolor] [-p prep] [-f fuzzval] [-t thresholds] [-b biases] [-u ucolor] [-m mode] [-g gcolor] [-s swidth] [-i is360] [-r rmse] infile outfile
-o .... ocolor .......... color of outer region to be cropped out; PURPOSE: To crop an image to a rectangle that will just trim any irregularly shaped outer boundary color. DESCRIPTION: INNERCROP crops an image to a rectangle that will just trim any irregularly shaped outer boundary color. The image is first trimmed and then converted to a binary mask. The mask is processed to one column and one row and thresholded to find the first and last occurences of white, which determine the top and bottom and left an right sides for cropping. This is repeated a second time to get the final crop coordinates. ARGUMENTS: -o ocolor ... OCOLOR is the color of the outer region that is to be cropped out of the image. Any valid IM color is allowed. See http://imagemagick.org/script/color.php -p prep ... PREP is the preprocessing trim type to be used. Choices are either 1 or 2. A value of 1 means to simply do a fuzzy trim. A value of 2 means to do a fuzzy floodfill trim. The latter is useful when the image itself contains the ocolor interior to the outer region. The default=1 -f fuzzval ... FUZZVAL is the fuzz factor in percent used in the preprocessing step. The choice of value is important if the outer color is not uniform as may be the case with jpeg compression. Typical values in those cases are a few percent. Over cropping can occur if the fuzzval is too high. Values are 0<=float<=100. The default=0 -t thresholds ... THRESHOLDS are four comma separate combinations of non-negative floating point values or null values (no spaces). The default=",,," which indicates that each of the four thresholds is to be computed automatically. Non-null values may be useful if the automatic thresholds do not provide a good result and one desires to try to improve the result. -b biases ... BIASES are four comma separate non-negative floating point values that are used as multipliers of the automatically computed thresholds. The corresponding bias is not used when a non-null value is proved for a given threshold. The default="1,1,1,1". The biases may be useful if the automatic thresholds do not provide a good result and one desires to try to improve the result. -u ucolor ... UCOLOR is any unused (safe) color in the image that will be used to convert the image into a mask. Any valid IM color is allowd. The default=none (i.e. transparent) and assumes the image is fully opaque. See http://imagemagick.org/script/color.php -m mode ... MODE is the output mode. The choices are: crop and box. When mode=crop, the ouput image will be the cropped version of the input image. When mode=box, a graphic box outline will be drawn on the input image showing where the cropping would take place. The default=crop. -g gcolor ... GCOLOR is the color of the graphic box outline to be used when mode=box. Any valid IM color is allowed. The default=red. See http://imagemagick.org/script/color.php -s swidth ... SWIDTH is the strokewidth to use when drawing the graphic box outline. Values are integers>0. The default=1. -i is360 ... IS360 is a flag to perform a test to determine if the image is a 360 degree panorama. The choices are yes or no. The default=no, which means do not test for 360 degree panorama. -r rmse ... RMSE is the root mean squared error threshold used to compare the first and last columns to determine if they are similar enough. Values are floats>0. The default is 0.05. If the compare test has an rmse value less than this threshold, then the image is determined to be a 360 degree panorama. 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. |
Original Image |
Arguments: |
Arguments: |
Original Image |
Arguments: |
Arguments: |
Original Image |
Arguments: |
Arguments: |
Original Image |
Arguments: |
Arguments: |
What the script does is as follows:
|