2.6.5.7 imgTrim

Menu Information

AutoTrim

Brief Information

Trim image with auto threshold settings

Command Line Usage

1. imgTrim t:=20;
2. imgTrim t:=20 img:=1 oimg:=2 o:=3;

X-Function Execution Options

Please refer to the page for additional option switches when accessing the x-function from script

Variables

Display
Name
Variable
Name
I/O
and
Type
Default
Value
Description
Threshold t

Input

int

0

Specifies the threshold value for detecting blank space. This X-Function starts at each edge of the input image and scans toward the center. If it finds that the change in intensity that is less than or equal to the threshold, the current area will be considered blank space. Valid values of this variable range from 0 to 255.

Input Matrix img

Input

Image

<active>

Specifies the image to be manipulated. The default input is the active image.

Output Image oimg

Output

Image

<input>

Specifies the output image. By default, the output image is the same as the input image. See the syntax here.

Edge o

Input

int

all

Specifies the edges to trim.

Option list

  • all :All boundary
Trims all edges.
  • tl:Top & Left
Trims the top and left edges.
  • br:Bottom & Right
Trims the bottom and right edges.
  • top :Top
Trims the top edge only.
  • left:Left
Trims the left edge only.
  • bottom:Bottom
Trims the bottom edge only.
  • right:Right
Trims the right edge only.

Description

This function trims blank space around the edges of the input image automatically.

Examples

  • Code Sample
// Rotate image and trim empty areas
//Create a new folder in the Project Explorer
pe_mkdir RotateTrim path:=aa$;
pe_cd aa$;
//Create a matrix and import an image into it
window -t m;
fname$ = System.path.program$ +"samples\Image Processing and Analysis\rice.bmp";
impimage;
window -r %h Original;
matrix -pg DIM nCol1 nRow1;	 //Get the dimension of the original iamge
window -d;	//Duplicate the image
window -r %h Modified;

imgRotate angle:=42;
imgTrim t:=17;

matrix -pg DIM nCol2 nRow2; //Get the dimension of the modified iamge
window -s T;	//Tile the windows horizontally
//Report
window -n n Report;
old = type.redirection;
type.redirection = 2;
type.notes$=Report;
type "Dimension of the original image: ";
type "   $(nCol1) * $(nRow1)\r\n";
type "Dimension of the modified image: ";
type "   $(nCol2) * $(nRow2)\r\n";
type.redirection = old;

Algorithm

The computation uses L_TrimBitmap() function from LEADTOOLS Main API. Please refer to the LEADTOOLS Main API Help file, Version 14 and read the L_TrimBitmap topic.

References

LEADTOOLS Main API Help file, Version 14

Related X-Functions

imgCrop, imgResize, imgShear