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. |
Identifies each separate isolated white shape in a binary image. |
last modified: December 15, 2018
USAGE: separate [-m mode] [-t] [-v] [-l] [-b bgcolor] [-e exponent] infile outfile
-m .... mode ......... output mode: 1=index number; 2=stretch index number; PURPOSE: To identify each separate (isolated) white shape in a binary (white on black) image. DESCRIPTION: SEPARATE identifies each separate (isolated) white shape in a binary (white on black) image. Any two-tone image may be used. The image will be converted to binary black/white. Multiple output formats are available. The background for the output image(s) can be either black or transparent (none). ARGUMENTS: -m mode ... MODE is the desired output format. It can one image or multiple images. Mode=1 simply sets the graylevel of each shape to an index from 1 to the number of shapes. The max number of shades is 255. The background will have index 0. For a small number of shapes, this will result in a visually black result. Mode=2 is the same as mode=1, except the resulting image is linearly stretched to full dynamic range so that the shapes has visible graylevels. Mode=3 is the same as mode=2, except the shapes are color coded. Mode=4 is the same as mode=2, but one output image is created for each shape. Mode=5 is the same as mode=4, except the each output is binarized. Mode=6 is the same as mode=4, except each output is color coded. The default=3 -g grid ... GRID is the grid spacing for testing points in the input image to see if they are white or black. The grid value is specified as an integer percent greater than 0 and less than 100 of the width and height of the input image. The default is not to use the grid, but to use a precise, but slower method. -t ... TRIM to bounding box for methods 4, 5 or 6 -v ... Keep virtual canvas information with trimmed outputs. This requires that the output format be one that keeps a virtual canvas, such as PNG or GIF or TIFF. -l ... List image size and offset (WIDTHxHEIGHT+XOFF+YOFF), area, centroid, and morphology distance center for trimmed outputs for methods 4, 5 or 6. -b bgcolor ... BGCOLOR is the background color to be used in the output image(s). The choices are: black or none (i.e. transparency). The default is black. -e exponent ... EXPONENT is used in a non-linear transformation of the graylevel values to map them to colors such that the colors are shifted away from black. Values are integers>0. The default=1. The more shapes/colors that are used, the larger the value. Typical value is about 6 for example, for 26 colors used. REQUIREMENT: IM version 6.5.5-1 due to the use of auto-level, 6.5.0-9 due to the use of compare with unequal sized images, 6.7.5-7 for morphology distance for option -l. 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. |
Mode=1 |
||
Original Image |
Arguments: |
Histogram |
16638: ( 0, 0, 0) #000000 black 2917: ( 1, 1, 1) #010101 rgb(1,1,1) 6303: ( 2, 2, 2) #020202 rgb(2,2,2) 542: ( 3, 3, 3) #030303 grey1 1600: ( 4, 4, 4) #040404 rgb(4,4,4) |
Mode=2 |
|
Original Image |
Arguments: |
Mode=3 |
|
Original Image |
Arguments: |
Mode=4 Black Background |
||
original |
index 0 |
index 1 |
index 2 |
index 3 |
index 4 |
Mode=4 Transparent Background |
||
original |
index 0 |
index 1 |
index 2 |
index 3 |
index 4 |
Mode=5 Black Background |
||
original |
index 0 |
index 1 |
index 2 |
index 3 |
index 4 |
Mode=5 Transparent Background |
||
original |
index 0 |
index 1 |
index 2 |
index 3 |
index 4 |
Mode=6 Black Background |
||
original |
index 0 |
index 1 |
index 2 |
index 3 |
index 4 |
Mode=6 Transparent Background |
||
original |
index 0 |
index 1 |
index 2 |
index 3 |
index 4 |
Mode=3 |
|
Original Image |
|
Arguments: |
What the script does is as follows:
This is equivalent to the following IM commands for the method=3
|