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. |
Finds the nearest color value in an image to a reference color. |
last modified: December 08, 2023
USAGE: nearestcolor [-c color] [-m mode] [-f fontname] [-p pointsize] [-l labelcolor] infile [outfile]
-c .... color ............. reference color; any IM color specification; default=black PURPOSE: To find the nearest color value in an image to a reference color. DESCRIPTION: NEARESTCOLOR finds the nearest color value in an image to a reference color. It will report the reference color and nearest color as an RGB triplet to the terminal in either 8bit (range 0 to 255) or percent (range 0 to 100%) according to the mode selected. If an output file is specified then a pair of side-by-side color swatches will be generated to compare the colors. The swatches will be labeled according to the fontname, pointsize and labelcolor specified. The swatch sizes will depend upon the pointsize and length of the label generated. ARGUMENTS: -c color ... COLOR is the reference color which will be used to find its nearest color in the image. Any valid IM text color may be used. The default is black. See http://imagemagick.org/script/color.php -m mode ... MODE is the mode used to display the RGB color values. The choices are: 8bit (range 0 to 255) or percent (range 0 to 100%). This will be used for display in the color swatches as well as to the terminal. The default is 8bit. -f fontname ... FONTNAME is the desired font or path-to-font-file for the swatch labels. The default is Helvetica. -p pointsize ... POINTSIZE is the desired pointsize for the swatch labels. The default is 18. infile outfile ... If no outfile is provided, then the resulting nearest color and rmse metric will only be reported to the terminal. If an outfile is provided, then a pair of color swatches will be created, labeled and appended. NOTE: This script requires IM 6.5.0-10 or higher due to the use of the new image matching feature in the compare function. 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. |
Image |
![]() |
Arguments: |
![]() |
Arguments: |
![]() |
What the script does is as follows:
This is equivalent to the following IM commands for the case of rgb in the range 0 to 255:
|