ImageTrim

ImageTrim[image,{pt1,pt2,}]

gives the smallest subimage of image that includes all of the specified points.

ImageTrim[image,{pt1,pt2,},r]

adds a margin of size r back to the resulting image.

Details and Options

  • In 2D, ImageTrim assumes that points {x,y} are in the standard image coordinate system, where x runs from 0 to image width and y runs from 0 to image height. The point {0,0} corresponds to the bottom-left corner of the image.
  • In 3D, ImageTrim assumes that points {x,y,z} are in the standard 3D image coordinate system, where x runs from 0 to width, y runs from 0 to depth, and z runs from 0 to height. The point {0,0,0} corresponds to the bottom-left front corner.
  • If fewer elements exist than are requested, ImageTrim will just return the elements that are present.
  • By setting a Padding option, pixels outside the original image can also be included. »
  • For integer coordinate values {i,j} the trimmed image will include all pixels touching the point {i,j}. Coordinates {i+.5,j+.5} lie at the center of pixels.
  • ImageTrim takes a DataRange option that specifies the range of pixels in the input image. The default setting is DataRange->Full. See the reference page for ImageValue for all possible settings.
  • ImageTrim[image,{{x1,y1},},{rx,ry}] specifies different horizontal and vertical margins.

Examples

open allclose all

Basic Examples  (2)

Trim an image:

In[1]:=
Click for copyable input
Out[1]=

Trim a 3D image:

In[1]:=
Click for copyable input
Out[1]=

Scope  (1)

Options  (2)

Applications  (1)

Properties & Relations  (1)

See Also

ImageTake  ImageCrop  BorderDimensions  ImageValue

Introduced in 2010
(8.0)
| Updated in 2012
(9.0)