📄 bweuler.m
字号:
function e = bweuler(a,n)
%BWEULER Compute the Euler number of binary image.
% EUL = BWEULER(BW,N) returns the Euler number for the binary
% image BW. EUL is a scalar whose value is the number of
% objects in the image minus the total number of holes in those
% objects. N can have a value of either 4 or 8, where 4
% specifies 4-connected objects and 8 specifies 8-connected
% objects; if the argument is omitted, it defaults to 8.
%
% Class Support
% -------------
% BW can be of class uint8 or double. EUL is of class double.
%
% Example
% -------
% BW = imread('circles.tif');
% imshow(BW)
% bweuler(BW)
%
% See also BWPERIM, BWMORPH.
% Clay M. Thompson 12-2-92
% Revised Steven L. Eddins 1996
% Copyright 1993-1998 The MathWorks, Inc. All Rights Reserved.
% $Revision: 5.9 $ $Date: 1997/11/24 15:34:05 $
% Reference: William Pratt, Digital Image Processing, John Wiley
% and Sons, 1991, pp. 630-634.
if nargin<2, n = 8; end
if n~=8 & n~=4, error('N must be either 4 or 8.'); end
if n==4,
lut = 4*[0 0.25 0.25 0 0.25 0 .5 -0.25 0.25 0.5 0 -0.25 0 ...
-0.25 -0.25 0] + 2;
else
lut = 4*[0 0.25 0.25 0 0.25 0 -.5 -0.25 0.25 -0.5 0 -0.25 0 ...
-0.25 -0.25 0] + 2;
end
% Need to zero-pad the input
b = repmat(uint8(0),size(a)+2);
b(2:end-1,2:end-1) = a;
weights = applylut(b,lut);
e = (sum(weights(:)) - 2*prod(size(b))) / 4;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -