Copyright 1993-2002 The MathWorks, Inc.% $Revision: 1.10 $ $Date: 2002/03/15 15:27:47 $% Algorithm reference: P. Soille, Morphological Image Analysis:% Principles and Applications, Springer, 1999, pp. 164-165.% Input-output specs% ------------------% IM: N-D, real, full matrix% any numeric or logical nonsparse type% if islogical(IM), treated as binary% empty ok% Infs ok% if logical, NaNs are ok and treated as 0s, otherwise% not allowed.%% CONN: connectivity%% IM2: Same class and size as IM[im,conn] = parse_inputs(varargin{:});conn = conn2array(conn);marker = im;% Now figure out which elements of the marker image are connected to the% outside, according to the connectivity definition.im2 = true(size(marker));im2 = padarray(im2, ones(1,ndims(im2)), 0, 'both');im2 = imerode(im2,conn);idx = cell(1,ndims(im2));for k = 1:ndims(im2) idx{k} = 2:(size(im2,k) - 1);endim2 = im2(idx{:});% Set all elements of the marker image that are not connected to the% outside to the lowest possible value.if islogical(marker) marker(im2) = false;else marker(im2) = -Inf;endim2 = imreconstruct(marker, im, conn);if islogical(im2) im2 = im & ~im2;else im2 = imsubtract(im,im2);end%%%%%% parse_inputs%%%function [im,conn] = parse_inputs(varargin)checknargin(1,2,nargin,mfilename);im = varargin{1};checkinput(im, {'numeric' 'logical'}, {'nonsparse' 'real'}, ... mfilename, 'IM', 1);if nargin < 2 conn = conndef(ndims(im),'maximal');else conn = varargin{2}; checkconn(conn,mfilename,'CONN',2);end% Skip NaN check here; it will be done by imreconstruct if input% is double.
今天中午就要交的试卷,交不了,就悲剧了啊·麻烦大大们帮帮忙啊!
|