Image Mask Quickstart

Image Mask (imagemask) is a command line application to prepare images of coins for publication. The application can automatically find the coin in the image, crop to the edges of the coin, and mask out the background. Command line parameters can be used to specify the coin's location and size. Coins that aren't round can be found heandled with this application.

Installation instructions for Image Mask.

Examples

Example 1 - Source, Destination, And Summary Files
Example 2 - Specify Output Size Of Coin
Example 3 - Crop Image To Edge Of Coin
Example 4 - Handle A Coin That Is Not Round
Example 5 - Non-Round Coin Avoid Jagged Edges
Example 6 - Specify Background Color
Example 7 - Background With Problematic Edges - The Problem
Example 8 - Background With Problematic Edges - The Fix

Example Source Images

A round coin with a background that offers no significant noise that we must deal with.

A non-round coin.

Background with problematic edges.


Example 1 - Source, Destination, And Summary Files

The summary file provides a visual summary of imagemask's calculations. Since the default size of the coin is used (--diameter not specified) the output image is very small.

KNOWN BUG: This example shows a known bug of this application. The affect is the coin is calculated to be much larger than it is actually is. This is caused by incorrectly detecting the coins edge at the exact top, bottom, left and right of the input image.

Source
Destination
Summary
$ imagemask --src=example_a_lg.jpg --dst=1_destination_lg.jpg --sum=1_summary_lg.jpg --find --mask

Example 2 - Specify Output Size Of Coin

  • Specify source, destination, and summary files.
  • Automatically find the coin.
  • Mask out the background.
  • Specify a number of points to avoid the bug described in Example 1.
  • Specify an output size for the coin.
  • Specify the units in which the output size is specified.

NOTE: By specifying an output diameter of two inches and using the default resolution of 300 DPI the output image is 600 pixels along it's longest edge. Since we did not specify the image be cropped to the edges of the coin, the entire image is used.

Source
Destination
Summary
$ imagemask --src=example_a_lg.jpg --dst=2_destination_lg.jpg --sum=2_summary_lg.jpg --find --mask --points=12 --diameter=2 --diamunit=in

Example 3 - Crop Image To Edge Of Coin

  • Specify source, destination, and summary files.
  • Automatically find the coin.
  • Mask out the background.
  • Specify a number of points to avoid the bug described in Example 1.
  • Specify an output size for the coin.
  • Specify the units in which the output size is specified.
  • Crop the image to the edges of the coin.

NOTE: By specifying an output diameter of two inches and using the default resolution of 300 DPI the output image is 600 pixels along it's longest edge. Since we cropped the image to the edges of the coin the final image is square.

Source
Destination
Summary
$ imagemask --src=example_a_lg.jpg --dst=2_destination_lg.jpg --sum=2_summary_lg.jpg --find --mask --points=12 --diameter=2 --diamunit=in --cropcoin

Example 4 - Handle A Coin That Is Not Round

  • Handle a coin that is not round.
  • Specify source, destination, and summary files.
  • Automatically find the coin.
  • Mask out the background.
  • Specify a number of points to avoid the bug described in Example 1.
  • Specify an output size for the coin.
  • Specify the units in which the output size is specified.
  • Crop the image to the edges of the coin.

NOTE: The --findtype=irregular specifies that the coin is not round. This affects how the edges of the coin are determined. Since we can't assume a round coin we just draw a line between adjacent points found at the edge of the coin.

NOTE: Using a small number of points we have a result with very jagged edges. This is not an acceptable result.

Source
Destination
Summary
$ imagemask --src=example_b_lg.jpg --dst=4_destination_lg.jpg --sum=4_summary_lg.jpg --find --findtype=irregular --mask --points=12 --diameter=2 --diamunit=in --cropcoin

Example 5 - Non-Round Coin Avoid Jagged Edges

  • Handle a coin that is not round.
  • Specify a large number of points avoid jagged edges.
  • Specify source, destination, and summary files.
  • Automatically find the coin.
  • Mask out the background.
  • Specify a number of points to avoid the bug described in Example 1.
  • Specify an output size for the coin.
  • Specify the units in which the output size is specified.
  • Crop the image to the edges of the coin.

NOTE: By specifying a large number of points we can smooth out the jaggedness from Example 4.

Source
Destination
Summary
$ imagemask --src=example_b_lg.jpg --dst=5_destination_lg.jpg --sum=5_summary_lg.jpg --find --findtype=irregular --mask --points=1005 --diameter=2 --diamunit=in --cropcoin

Example 6 - Specify Background Color

  • Handle a coin that is not round.
  • Specify a large number of points avoid jagged edges.
  • Specify source, destination, and summary files.
  • Automatically find the coin.
  • Mask out the background.
  • Specify a number of points to avoid the bug described in Example 1.
  • Specify an output size for the coin.
  • Specify the units in which the output size is specified.
  • Crop the image to the edges of the coin.
  • Specify background color.

NOTE: Most color names can be specified. A list of colors will be provided in the future.

Source
Destination
Summary
$ imagemask --src=example_b_lg.jpg --dst=5_destination_lg.jpg --sum=5_summary_lg.jpg --find --findtype=irregular --mask --points=1005 --diameter=2 --diamunit=in --cropcoin --background=blue

Example 7 - Background With Problematic Edges - The Problem

  • Specify source, destination, and summary files.
  • Automatically find the coin.
  • Mask out the background.
  • Specify a number of points to avoid the bug described in Example 1.
  • Specify an output size for the coin.
  • Specify the units in which the output size is specified.
  • Crop the image to the edges of the coin.
  • Specify background color.

NOTE: This example shows a problem where the edges of the background have objects intruding from the edge. The next example shows a fix for this problem.

Source
Destination
Summary
$ imagemask --src=example_c_lg.jpg --dst=7_destination_lg.jpg --sum=7_summary_lg.jpg --find --mask --points=28 --diameter=2 --diamunit=in --cropcoin

Example 8 - Background With Problematic Edges - The Fix

  • Specify source, destination, and summary files.
  • Automatically find the coin.
  • Mask out the background.
  • Specify a number of points to avoid the bug described in Example 1.
  • Specify an output size for the coin.
  • Specify the units in which the output size is specified.
  • Crop the image to the edges of the coin.
  • Specify background color.

NOTE: This example shows fix for a problem where the edges of the background have objects intruding from the edge. The previous example shows the problem.

Source
Destination
Summary
$ imagemask --src=example_c_lg.jpg --dst=8_destination_lg.jpg --sum=8_summary_lg.jpg --find --mask --points=28 --diameter=2 --diamunit=in --cropcoin --borderright=400 --borderleft=400