英语翻译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% -----------------
来源:学生作业帮助网 编辑:作业帮 时间:2024/11/13 04:06:06
英语翻译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% -----------------
英语翻译
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);
end
im2 = 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;
end
im2 = 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.
今天中午就要交的试卷,交不了,就悲剧了啊·
英语翻译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% -----------------
Copyright 1993-2002 The MathWorks,Inc.
美国迈斯沃克公司 1993-2002 版权所有.
% $Revision:1.10 $ $Date:2002/03/15 15:27:47 $
版本 1.10 日期:2002/03/15 15:27:47
% Algorithm reference:P.Soille,Morphological Image Analysis:
算法参考:P.Soille 形态学图像分析
% Principles and Applications,Springer,1999,pp.164-165.
原理与应用原书名 Springer,1999,pp.164-165.
% Input-output specs
输入输出 规则
% ------------------
% IM:N-D,real,full matrix
N-D实数全矩阵
% any numeric or logical nonsparse type
任何数字的 或者逻辑非系数 类型
% if islogical(IM),treated as binary
若是逻辑数则为真,以二进制对待.
% empty ok
空集 确定
% Infs ok
Infs确定
% if logical,NaNs are ok and treated as 0s,otherwise
如果合乎逻辑的,通知书是确定并视为0 ,否则
% not allowed.
% ,不允许.
%
% CONN:connectivity
连接器 连通
%
% IM2:Same class and size as IM
IM2 :同一等级,与IM相同的规模
[im,conn] = parse_inputs(varargin{:});
赋值
conn = conn2array(conn); 赋值
marker = im;
标记: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);
end
im2 = 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;
end
im2 = 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
这里跳过NaN检查 如果是双输入,则imreconstruct 函数可以解决.
% is double.