ImageCrop

ImageCrop[image]
crops image by removing borders of uniform color.

ImageCrop[image,size]
crops image based on the size specification size.

ImageCrop[image,size,spec]
crops image by removing pixels from sides specified by spec.

Details and OptionsDetails and Options

  • ImageCrop[image] effectively removes borders from image whose pixel value distribution is almost uniform.
  • ImageCrop[image,{w,h}] by default removes pixels symmetrically from image, or if w or h is larger than for image, it adds pixels symmetrically.
  • The image size specification size in ImageCrop[image,size] can have the following forms:
  • widthparticular width; height based on aspect ratio
    {width}maximum width
    {width,height}particular width and height
    {width,depth,height}particular width, depth, and height in 3D
  • Specifications for either of the dimensions can be any of the following:
  • dd pixels
    {d}maximum d pixels
    {dmin,dmax}pixel ranges
    Automaticdetermine value from aspect ratio
    Fulldo no cropping in this dimension
  • The cropping specification spec in ImageCrop[image,size,spec] can have the following forms:
  • sidecrop on the specified side; center otherwise
    {side1,side2}crop on the specified sides
    {ax,ay}assign a fraction of cropping to each side
  • Sides can be specified as Left, Right, Bottom, or Top. Center indicates symmetrical cropping.
  • Cropping fractions are between and . In the horizontal case, is equivalent to Left, to Right, and to Center. In the vertical case, is equivalent to Bottom, and to Top.
  • ImageCrop[image,size] is equivalent to ImageCrop[image,size,Center].
  • To obtain an image with an aspect ratio r, use ImageCrop[image,width{1,r}].
  • If the final image specified by ImageCrop[image,] extends beyond image, then pixels are added according to the setting for Padding.

ExamplesExamplesopen allclose all

Basic Examples  (3)Basic Examples  (3)

Automatically crop uniform borders:

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

Crop an image to a given size:

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

Crop constant areas of a 3D image:

In[1]:=
Click for copyable input
Out[1]=
In[2]:=
Click for copyable input
Out[2]=
Introduced in 2008
(7.0)
| Updated in 2012
(9.0)