Be the first to rate this file! 216 downloads (last 30 days) File Size: 1.55 KB File ID: #12303

getborder

by Wolfgang Schwanghart

 

18 Sep 2006 (Updated 04 Jan 2008)

Code covered by BSD License  

returns a logical border inside or outside a mask

Download Now | Watch this File

File Information
Description

Ib = getborder(I,method)

getborder returns the outline around logical values in I (mask) using a 8-connected neighborhood.
I must be a logical n*m matrix. method 'inside' returns the inner border around "islands" of logical values. 'outside' returns the border outside the islands.
 
  Example:
 
  I = peaks(8)<0;
  
  Ib = getborder(I,'inside')
  
  Ib =
  
       0 0 1 1 1 1 1 1
       0 0 1 1 0 1 1 0
       1 0 0 1 1 1 0 0
       1 1 1 0 0 0 0 0
       1 1 1 0 0 0 0 0
       1 1 0 0 0 0 0 0
       0 0 0 0 0 0 0 0
       0 0 0 0 0 0 0 0
       
  Ib = getborder(I,'outside')
  
  Ib =
  
       0 1 0 0 0 0 0 0
       1 1 0 0 0 0 0 1
       0 1 1 0 0 0 1 1
       0 0 0 1 1 1 1 0
       0 0 0 1 0 0 0 0
       0 0 1 1 0 0 0 0
       1 1 1 0 0 0 0 0
       0 0 0 0 0 0 0 0

MATLAB release MATLAB 7 (R14)
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Please login to add a comment or rating.
Updates
27 Sep 2006

As getborder(A,'inner') did not return 1 when a cell is surrounded by zeros only, I changed this. Sorry...

03 Jan 2008

speed increased by employing conv2, better handle input

04 Jan 2008

removed padding since it was not neccessary

Tag Activity for this File
Tag Applied By Date/Time
matrices Wolfgang Schwanghart 22 Oct 2008 08:39:45
border logical mask Wolfgang Schwanghart 22 Oct 2008 08:39:45
 

MATLAB Central Terms of Use

NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Terms prior to use.

Contact us at files@mathworks.com