我需要在Matlab中使用imfill (版本2010 b,7.11.0)。我现在认为程序中有一个bug。我发现的最简单的这里示例如下:(填充[4 3]位置开始的图像背景(0) )
BW = [ 0 0 0 0 0 0 0 0;
0 1 1 1 1 1 0 0;
0 1 0 0 0 1 0 0;
0 1 0 0 0 1 0 0;
0 1 0 0 0 1 0 0;
0 1 1 1 1 0 0 0;
0 0 0 0 0 0 0 0;
0 0 0 0 0 0 0 0];
imfill(BW,[4 3])根据规范,这应该工作的IMHO,但我总是得到以下消息。有人能告诉我我做错了什么吗?
??? Error using ==> iptcheckconn at 56
Function IMFILL expected its second input argument, CONN,
to be a valid connectivity specifier.
A nonscalar connectivity specifier must be 3-by-3-by- ...
-by-3.
Error in ==> imfill>parse_inputs at 259
iptcheckconn(conn, mfilename, 'CONN', conn_position);
Error in ==> imfill at 124
[I,locations,conn,do_fillholes] = parse_inputs(varargin{:});
Error in ==> test at 9
imfill(BW,[4 3]) 发布于 2014-11-01 16:03:00
这并不能解释问题,但将BW转换为逻辑数组确实有效。但我不知道为什么会这样:
clear
close all
clc
BW = [ 0 0 0 0 0 0 0 0
0 1 1 1 1 1 0 0
0 1 0 0 0 1 0 0
0 1 0 0 0 1 0 0
0 1 0 0 0 1 0 0
0 1 1 1 1 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0];
BW2 = imfill(logical(BW),[4 3])
BW2 =
0 0 0 0 0 0 0 0
0 1 1 1 1 1 0 0
0 1 1 1 1 1 0 0
0 1 1 1 1 1 0 0
0 1 1 1 1 1 0 0
0 1 1 1 1 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0发布于 2014-11-01 16:01:21
正如您在@Benoit_11的另一个解决方案中已经看到的那样,最有可能的情况是输入不是logical类的,这会向您抛出一个错误。那么,你被安置在那里了!
现在,我想在这里提出一点额外的建议。
让我们假设您有一组种子点和它们的row和column in,并且希望一次用这些种子点填充图像。对于这种情况,您需要使用这些ID作为列向量。因此,如果您将row和column ID作为-
row_id = [4 3];
col_id = [3 7];你可以用这个填充图像-
BW = imfill(BW,[row_id(:) col_id(:)])但是,下面的代码会把错误抛给你-
BW = imfill(BW,[row_id col_id])https://stackoverflow.com/questions/26690960
复制相似问题