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.
ImageCrop[video,…]
crops frames of video.
Details and Options
- Image cropping, also known as image trimming, is the process of removing border pixels from an image and can be used for removing uninteresting regions or extracting regions of interest.
- ImageCrop[image] effectively removes borders from image whose pixel value distribution is almost uniform.
- ImageCrop[image,{width,height}] by default removes pixels symmetrically from image, or if width or height is larger than for image, it adds pixels symmetrically.
- The image size specification size in ImageCrop[image,size] can have the following forms:
-
width particular width; height based on aspect ratio {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:
-
d d pixels UpTo[d] maximum d pixels {dmin,dmax} pixel ranges Automatic determine value from aspect ratio Full do no cropping in this dimension - The cropping specification spec in ImageCrop[image,size,spec] can have the following forms:
-
side crop 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.
Examples
open allclose allScope (7)
Size Specification (2)
Crop an image to a width of 100 pixels, preserving the aspect ratio:
Crop to a 100×100 pixel square:
Do not crop the height of the image:
Crop to a height of 100 pixels, preserving the aspect ratio:
Make the largest dimension not greater than 100 pixels:
Pad the image by using values greater than the image dimensions:
Side Specification (2)
Options (2)
Padding (2)
By default, black padding is used:
Pad the image with a specified color:
Specify a different padding scheme:
Use Padding->None to avoid padding:
The result may be smaller than the given size:
With Padding->Automatic, a color based on the boundary pixel values is chosen:
If the boundary pixels do not have consistent colors, black is used:
Properties & Relations (3)
Possible Issues (2)
Cropping happens if a similar border is present on at least two sides:
If a border is present only on one side, it is not cropped:
Detect the border using BorderDimensions and crop it using ImagePad:
Text
Wolfram Research (2008), ImageCrop, Wolfram Language function, https://reference.wolfram.com/language/ref/ImageCrop.html (updated 2021).
CMS
Wolfram Language. 2008. "ImageCrop." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2021. https://reference.wolfram.com/language/ref/ImageCrop.html.
APA
Wolfram Language. (2008). ImageCrop. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/ImageCrop.html