Method

VipsImagefind_trim

Declaration [src]

int
vips_find_trim (
  VipsImage* in,
  int* left,
  int* top,
  int* width,
  int* height,
  ...
)

Description [src]

Search in for the bounding box of the non-background area.

Any alpha is flattened out, then the image is median-filtered (unless line_art is set, see below). The absolute difference from background is computed and binarized according to threshold. Row and column sums of the absolute difference are calculated from this binary image and searched for the first row or column in each direction to obtain the bounding box.

If the image is entirely background, vips_find_trim() returns width == 0 and height == 0.

background defaults to 255, or 65535 for 16-bit images. Set another value, or use vips_getpoint() to pick a value from an edge. You’ll need to flatten before vips_getpoint() to get a correct background value.

threshold defaults to 10.

The detector is designed for photographic or compressed images where there is a degree of noise that needs filtering. If your images are synthetic (eg. rendered from vector art, perhaps), set line_art to disable this filtering.

The image needs to be at least 3x3 pixels in size.

::: tip “Optional arguments” * threshold: gdouble, background / object threshold * background: VipsArrayDouble, background colour * line_art: gboolean, enable line art mode

::: seealso vips_getpoint(), vips_extract_area(), vips_smartcrop().

Parameters

left int*
 

Output left edge.

 The argument will be set by the function.
 The instance takes ownership of the data, and is responsible for freeing it.
top int*
 

Output top edge.

 The argument will be set by the function.
 The instance takes ownership of the data, and is responsible for freeing it.
width int*
 

Output width.

 The argument will be set by the function.
 The instance takes ownership of the data, and is responsible for freeing it.
height int*
 

Output height.

 The argument will be set by the function.
 The instance takes ownership of the data, and is responsible for freeing it.
... none
 

NULL-terminated list of optional named arguments.

Return value

Returns: int
 

0 on success, -1 on error.