---
title: "BorderDimensions"
language: "en"
type: "Symbol"
summary: "BorderDimensions[image] gives the pixel width of uniform borders of image in the form {{left, right}, {bottom, top}}. BorderDimensions[image, t] finds borders whose pixels vary by an amount less than t."
keywords: 
- border
- borders
- frame
- crop
- cropping
- margin
- margins
canonical_url: "https://reference.wolfram.com/language/ref/BorderDimensions.html"
source: "Wolfram Language Documentation"
related_guides: 
  - 
    title: "Basic Image Manipulation"
    link: "https://reference.wolfram.com/language/guide/BasicImageManipulation.en.md"
  - 
    title: "Geometric Operations"
    link: "https://reference.wolfram.com/language/guide/ImageGeometry.en.md"
related_workflows: 
  - 
    title: "Crop 2D Images"
    link: "https://reference.wolfram.com/language/workflow/Crop2DImages.en.md"
related_functions: 
  - 
    title: "ImagePad"
    link: "https://reference.wolfram.com/language/ref/ImagePad.en.md"
  - 
    title: "ImageCrop"
    link: "https://reference.wolfram.com/language/ref/ImageCrop.en.md"
  - 
    title: "ImageTake"
    link: "https://reference.wolfram.com/language/ref/ImageTake.en.md"
  - 
    title: "ImageDimensions"
    link: "https://reference.wolfram.com/language/ref/ImageDimensions.en.md"
  - 
    title: "PixelValue"
    link: "https://reference.wolfram.com/language/ref/PixelValue.en.md"
---
# BorderDimensions

BorderDimensions[image] gives the pixel width of uniform borders of image in the form {{left, right}, {bottom, top}}.

BorderDimensions[image, t] finds borders whose pixels vary by an amount less than t.

## 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 (8)

### Basic Examples (1)

Find the pixel dimensions of the black margins:

```wl
In[1]:= BorderDimensions[[image]]

Out[1]= {{10, 20}, {30, 40}}
```

### Scope (3)

Border dimensions of a grayscale image:

```wl
In[1]:= BorderDimensions[[image]]

Out[1]= {{45, 49}, {36, 47}}
```

---

Specify a higher tolerance to detect a noisy image border:

```wl
In[1]:= BorderDimensions[[image], .1]

Out[1]= {{16, 21}, {10, 13}}
```

---

Border dimensions of a 3D volume:

```wl
In[1]:= BorderDimensions[[image]]

Out[1]= {{63, 52}, {25, 35}, {2, 0}}
```

### Applications (3)

Remove blue borders of a color image:

```wl
In[1]:= i = [image];

In[2]:= ImagePad[i, -BorderDimensions[i, .07]]

Out[2]= [image]
```

---

Extract the text part of a scanned book:

```wl
In[1]:= i = [image];ImagePad[i, -BorderDimensions[GradientFilter[i, 1], 0.06]]

Out[1]= [image]
```

---

Extract the foreground objects over a smoothly shaded background:

```wl
In[1]:= i = [image];ImagePad[i, -BorderDimensions[GradientFilter[i, 1]]]

Out[1]= [image]
```

### Properties & Relations (1)

Border dimensions of a uniform image are considered zero:

```wl
In[1]:= BorderDimensions[[image]]

Out[1]= {{0, 0}, {0, 0}}
```

## See Also

* [`ImagePad`](https://reference.wolfram.com/language/ref/ImagePad.en.md)
* [`ImageCrop`](https://reference.wolfram.com/language/ref/ImageCrop.en.md)
* [`ImageTake`](https://reference.wolfram.com/language/ref/ImageTake.en.md)
* [`ImageDimensions`](https://reference.wolfram.com/language/ref/ImageDimensions.en.md)
* [`PixelValue`](https://reference.wolfram.com/language/ref/PixelValue.en.md)

## Related Guides

* [Basic Image Manipulation](https://reference.wolfram.com/language/guide/BasicImageManipulation.en.md)
* [Geometric Operations](https://reference.wolfram.com/language/guide/ImageGeometry.en.md)

## Related Workflows

* [Crop 2D Images](https://reference.wolfram.com/language/workflow/Crop2DImages.en.md)

## History

* [Introduced in 2010 (8.0)](https://reference.wolfram.com/language/guide/SummaryOfNewFeaturesIn80.en.md) \| [Updated in 2012 (9.0)](https://reference.wolfram.com/language/guide/SummaryOfNewFeaturesIn90.en.md)