function pout = bwperim(b,n)
%BWPERIM Perimeter of objects in a binary image.
%	P = BWPERIM(BW,N) returns a binary image containing
%	only the perimeter pixels of objects in the image BW
%	assuming an N-connected neighborhood.  N can be 4 or 8.  
%	A pixel is part of the perimeter if a 1 is connected 
%	to a zero.
%	
%	BWPERIM(BW) uses the default 4-connected neighborhood.
%
%	To find the number of perimeter points use SUM(SUM(P)).
%
%	See also BWAREA, BWEULER, ERODE, DILATE, BWMORPH.

%	Clay M. Thompson 11-17-92
%	Copyright (c) 1992 by The MathWorks, Inc.
%	$Revision: 1.6 $  $Date: 1993/09/13 22:38:50 $

error(nargchk(1,2,nargin));

if nargin<2, n = 4; end

if n~=8 & n~=4, error('N must be either 4 or 8.'); end

if n==4,
  p = bwmorph(b,'perim4');
else
  p = bwmorph(b,'perim8');
end

if nargout==0, imshow(p,2), return, end
pout = p;
