ImageCrop
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 all close allBasic Examples (2)
Scope (7)
Data (3)
Size Specification (2)
Crop an image to a width of 100 pixels, preserving the aspect ratio:
i = [image];
ImageCrop[i, 100]Crop to a 100×100 pixel square:
ImageCrop[i, {100, 100}]Do not crop the height of the image:
ImageCrop[i, {100, Full}]Crop to a height of 100 pixels, preserving the aspect ratio:
ImageCrop[i, {Automatic, 100}]Make the largest dimension not greater than 100 pixels:
ImageCrop[ImageRotate[i], UpTo[100]]Pad the image by using values greater than the image dimensions:
ImageCrop[i, 250]i = \!\(\*Graphics3DBox[«10»]\);ImageCrop[i, 23]Crop a 3D image in the vertical dimension only:
ImageCrop[i, {Full, Full, 23}]Side Specification (2)
Crop on the left side, preserving the aspect ratio:
i = [image];ImageCrop[i, 150, Left]Crop at the left side, using numerical values:
ImageCrop[i, 150, {-1, 0}]Crop evenly from both sides using numerical values:
ImageCrop[i, 150, {-0.5, 0}]Crop from the left and bottom sides:
ImageCrop[i, 150, {Left, Bottom}]i = \!\(\*Graphics3DBox[«10»]\);Crop the top 23 slices off a 3D image:
ImageCrop[i, {Full, Full, 23}, Top]Extract a selected horizontal slice of a 3D image:
ImageCrop[i, {Full, Full, 1}, {0, 0, 0.5}]Take all slices in a selected region of the 3D image:
ImageCrop[i, {23, 23, Full}, {-1, 1, 1}]Options (2)
Padding (2)
By default, black padding is used:
i = [image];
ImageCrop[i, {200, 100}]Pad the image with a specified color:
ImageCrop[i, {200, 100}, Padding -> Red]Specify a different padding scheme:
ImageCrop[i, {200, 100}, Padding -> "Fixed"]Use Padding->None to avoid padding:
ImageCrop[i, {200, 100}, Padding -> None]The result may be smaller than the given size:
ImageDimensions[%]With Padding->Automatic, a color based on the boundary pixel values is chosen:
ImageCrop[[image], {300, 200}, Padding -> Automatic]If the boundary pixels do not have consistent colors, black is used:
ImageCrop[[image], {300, 200}, Padding -> Automatic]Applications (1)
Properties & Relations (3)
ImageCrop preserves the aspect ratio of the image:
ImageCrop[[image], 100]Use ImageTake to crop an image:
i = [image];
{w, h} = ImageDimensions[i];
ImageCrop[i, {100, 50}] == ImageTake[i, {1, -1} ((w - 100) / 2 + 1), {1, -1} ((h - 50) / 2 + 1)]ImageCrop adds or removes pixels on the sides to achieve specified output dimensions:
ImageCrop[[image], {190, 60}, Padding -> Yellow]Use ImagePad to add or remove specified numbers of pixels on the sides:
ImagePad[[image], {{20, 20}, {-20, -20}}, Padding -> Yellow]Possible Issues (2)
Cropping happens if a similar border is present on at least two sides:
ImageCrop[[image]]If a border is present only on one side, it is not cropped:
i = [image];ImageCrop[i]Detect the border using BorderDimensions and crop it using ImagePad:
BorderDimensions[i]ImagePad[i, -%]See Also
ImageTrim ImagePad ImageTake BorderDimensions ImagePartition ImageSize ImageAugmentationLayer
Function Repository: ImageSaliencyCrop ImageRegionCrop ArrayCropPad
Tech Notes
Related Workflows
- Crop 2D Images ▪
- Crop 3D Images
History
Introduced in 2008 (7.0) | Updated in 2014 (10.0) ▪ 2015 (10.3) ▪ 2021 (13.0)
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
BibTeX
@misc{reference.wolfram_2026_imagecrop, author="Wolfram Research", title="{ImageCrop}", year="2021", howpublished="\url{https://reference.wolfram.com/language/ref/ImageCrop.html}", note=[Accessed: 12-June-2026]}
BibLaTeX
@online{reference.wolfram_2026_imagecrop, organization={Wolfram Research}, title={ImageCrop}, year={2021}, url={https://reference.wolfram.com/language/ref/ImageCrop.html}, note=[Accessed: 12-June-2026]}