View License

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video

Highlights from
Draw a border around an image

4.2 | 5 ratings Rate this file 32 Downloads (last 30 days) File Size: 2.16 KB File ID: #21005 Version: 1.2
image thumbnail

Draw a border around an image


Eric Johnson (view profile)


07 Aug 2008 (Updated )

Draws a colored border around an image.

| Watch this File

File Information

ADDBORDER draws a border around an image.

NEWIMG = ADDBORDER(IMG, T, C, S) adds a border to the image IMG with thickness T, in pixels. C specifies the color, and should match the color format of the image (e.g., RGB or indexed). STROKE is a string indicating the position of the border:

'inner' - border is added to the inside of the image. The dimensions of OUT will be the same as IMG.

'outer' - the border sits completely outside of the image, and does not obscure any portion of it.

'center' - the border straddles the edges of the image.


load mandrill
X2 = addborder(X, 20, 62, 'center');
axis off
axis image

MATLAB release MATLAB 7.6 (R2008a)
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (8)
05 Apr 2016 Arpit Bhatia

29 Mar 2016 Mohamed Gaber

That's what i was searching for, Many thanks!

23 Oct 2014 James Cusack

Fantastic implementation, nice and simple. Well documented. Thank you.

06 Apr 2014 Jose Ramos

This is a great function. It made my day. However, it gives me an error when I want to use it with grayscale images. Is this only for color images? Do you know a workaround grayscale images? That would be great. Thanks for a good job.

Comment only
13 Aug 2012 M Sohrabinia

M Sohrabinia (view profile)

The function works perfectly, however, it could have a better help to explain where X comes from: X in the example is the input image (or IMG) for which you want to show (e.g., using imshow). In fact, this function turns the marginal pixels to the values given by color. My suggestion is to assign default values for T, C and Stroke, something like: T=1 pixel, C=0=black, S= 'center'. Its a great function anyway, thanks for sharing.

17 Nov 2011 Dave

Dave (view profile)

Awesome. Just what I needed.

Comment only
17 Nov 2011 Dave

Dave (view profile)

21 Apr 2011 jun

jun (view profile)

Where doese the X from your example come from? It is not working at all. The 't' is limited to 1 and what I get is only img2 = 'c' depends on what is entered to 'c'.

Comment only
31 Dec 2009 1.2


Contact us