ImageTrim

ImageTrim[image,roi]

gives the smallest subimage of image that includes the specified region of interest roi.

ImageTrim[image,roi,r]

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

ImageTrim[image,{roi1,roi2,},]

extracts multiple subimages specified by roii from image.

Details and Options

  • ImageTrim[image,roi] returns a subimage containing the region of interest roi. The region roi can be any of the following:
  • {{x1,y1},}or {{x1,y1,z1},}a list of 2D or 3D image positions
    regiona 2D or 3D geometric region (Point, Disk, Sphere, etc.)
    maskimagenonzero pixels of a 2D or 3D object
    fa region returned by a function f
  • ImageTrim assumes the standard image coordinate system.
  • For integer coordinate values the trimmed image will include all pixels touching the point . Coordinates lie at the center of pixels.
  • ImageTrim[image,{pt1,},{rx,ry}] specifies different horizontal and vertical margins.
  • The following options can be given:
  • DataRangeFullrange of pixel positions in image
    PaddingNonepadding scheme to use
  • By default, if fewer elements exist than are requested, ImageTrim will just return the elements that are present. By setting the Padding option to anything else, pixels outside the original image can also be included. »
  • Possible settings for DataRange include:
  • Automatic{{0,1},{0,h/w}} in 2D, {{0,1},{0,d/w},{0,h/w}} in 3D
    Full{{0,w},{0,h}} in 2D, {{0,1},{0,d},{0,h}} in 3D (default)
    {{left,right},{bottom,top}}explicit coordinate ranges in 2D
    {{left,right},{front,back},{bottom,top}}explicit coordinate ranges in 3D

Examples

open allclose all

Basic Examples  (1)

Trim an image:

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

Scope  (9)

Options  (2)

Applications  (7)

Properties & Relations  (2)

See Also

ImageTake  ImageCrop  BorderDimensions  ImageValue  Masking

Introduced in 2010
(8.0)
| Updated in 2018
(11.3)