Fred's ImageMagick Scripts



    Licensing:

    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.

TRIM2DETAIL


Trims an image to the bounding rectangle about the images' main content using Canny edges as a measure of content detail.

Download Script

last modified: August 24, 2019



USAGE: trim2detail [-e edgewidth] [-t1 thresh1] [-t2 thresh2] [-p pad] [-a area] infile outfile
USAGE: trim2detail [-h or -help]

-e .... edgewidth ... width (sigma) argument for Canny edge detection; float>0; default=1
-t1 ... thresh1 ..... lower hysteresis (percent) threshold for Canny edge detection;
..................... 0<=integer<=100; default=10
-t2 ... thresh2 ..... upper hysteresis (percent) threshold for Canny edge detection;
..................... 0<=integer<=100; default=30
-p .... pad ......... pad amount; integer>=0; default=5
-a .... area ........ area of connected components in order to remove small regions;
..................... integer>=0; default=0

PURPOSE: To trim an image to the bounding rectangle about the image's main content.

DESCRIPTION: TRIM2DETAIL trims an image to the bounding rectangle about the images' main content using Canny edges as a measure of content detail. This script is only designed to work when the background region is of slowly varying content with little to no detail, such as gradual shadowing.

ARGUMENTS:

-e edgewidth ... EDGEWIDTH is the width argument for canny edge detection. Values are float>0. The default=1.

-t1 thresh1 ... THRESH1 is the lower hysteresis (percent) threshold for canny edge detection. Values are 0<=integer<=100. The default=10.

-t2 thresh2 ... THRESH2 is the lower hysteresis (percent) threshold for canny edge detection. Values are 0<=integer<=100. The default=30.

-p pad ... PAD amount. Values are integer>=0. The default=5

-a area ... AREA of connected components in order to remove small regions. Values are integer>=0. The default=0.

REQUIREMENTS: Requires Imagemagick 6.8.9-0 or higher for Canny edge detection.

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.


EXAMPLES


Example 1
((source))

Input

Arguments:
defaults



Example 2
((source))

Input

Arguments:
defaults



What the script does is as follows:

  • Reads the input image
  • Applys Canny edge detection
  • Optionally removes small areas
  • Determines the trim bounding box
  • Crops the image using the trim bounding box adjusted for padding
  • Writes the output image

See the script for coding details