BorderDimensions
✖
BorderDimensions
gives the pixel width of uniform borders of image in the form {{left,right},{bottom,top}}.
Details and Options

- BorderDimensions works with binary, grayscale, and multichannel images.
- BorderDimensions[image] is equivalent to BorderDimensions[image,0.02].
- ImagePad[image,-BorderDimensions[image]] effectively removes uniform image margins.
- BorderDimensions works with Image3D objects and returns the borders in the form {{left,right},{front,back},{bottom,top}}.
Background & Context
- BorderDimensions computes the constant or semi-uniform border or frame around a 2D or 3D image and returns them as an array of integer values of the form {{left,right},{bottom,top}} (for an Image) or {{left,right},{bottom,top},{bottom,top}} (for an Image3D). With an optional second argument, BorderDimensions finds borders whose pixels vary by an amount less than a given threshold.
- Border dimensions of a uniform image are considered zero.
- ImagePad can be used to remove the detected border from an image. ImageCrop is another function that can be used to crop an almost-uniform border. However, unlike BorderDimensions, ImageCrop does not allow specification of a variance threshold.
Examples
open allclose allBasic Examples (1)Summary of the most common use cases
Scope (3)Survey of the scope of standard use cases
Border dimensions of a grayscale image:

https://wolfram.com/xid/0bnix10e24zro-i01adn

Specify a higher tolerance to detect a noisy image border:

https://wolfram.com/xid/0bnix10e24zro-d6m1uh

Border dimensions of a 3D volume:

https://wolfram.com/xid/0bnix10e24zro-9lnpac

Applications (3)Sample problems that can be solved with this function
Remove blue borders of a color image:

https://wolfram.com/xid/0bnix10e24zro-jtwh1w

https://wolfram.com/xid/0bnix10e24zro-dw42br

Extract the text part of a scanned book:

https://wolfram.com/xid/0bnix10e24zro-85p0v

Extract the foreground objects over a smoothly shaded background:

https://wolfram.com/xid/0bnix10e24zro-cfxlek

Wolfram Research (2010), BorderDimensions, Wolfram Language function, https://reference.wolfram.com/language/ref/BorderDimensions.html (updated 2012).
Text
Wolfram Research (2010), BorderDimensions, Wolfram Language function, https://reference.wolfram.com/language/ref/BorderDimensions.html (updated 2012).
Wolfram Research (2010), BorderDimensions, Wolfram Language function, https://reference.wolfram.com/language/ref/BorderDimensions.html (updated 2012).
CMS
Wolfram Language. 2010. "BorderDimensions." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2012. https://reference.wolfram.com/language/ref/BorderDimensions.html.
Wolfram Language. 2010. "BorderDimensions." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2012. https://reference.wolfram.com/language/ref/BorderDimensions.html.
APA
Wolfram Language. (2010). BorderDimensions. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/BorderDimensions.html
Wolfram Language. (2010). BorderDimensions. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/BorderDimensions.html
BibTeX
@misc{reference.wolfram_2025_borderdimensions, author="Wolfram Research", title="{BorderDimensions}", year="2012", howpublished="\url{https://reference.wolfram.com/language/ref/BorderDimensions.html}", note=[Accessed: 28-May-2025
]}
BibLaTeX
@online{reference.wolfram_2025_borderdimensions, organization={Wolfram Research}, title={BorderDimensions}, year={2012}, url={https://reference.wolfram.com/language/ref/BorderDimensions.html}, note=[Accessed: 28-May-2025
]}