MATLAB 2015b:在strel命令中无法识别“sphere”

时间:2018-04-03 17:25:17

标签: matlab 3d binary

我有一个3d二进制图像,我试图在MATLAB 2015b中进行3d扩张。我试过了:

se=strel('sphere',20);
3Ddilated=imdilate(3Dimage,se);

但我得到了:

Error using strel>ParseInputs (line 1223)
Expected input number 1, STREL_TYPE, to match one of these strings:

'arbitrary', 'square', 'diamond', 'rectangle', 'octagon', 'line', 'pair', 'periodicline', 'disk', 'ball'

The input, 'sphere', did not match any of the valid strings.

Error in strel (line 147)
                [type,params] = ParseInputs(varargin{:});

在2015b中,strel不会做'球'吗?有没有好的选择?

2 个答案:

答案 0 :(得分:0)

您可以自己创建一个:

r = 20;
x = -r:r;
x = x.^2;
[x,y,z]=ndgrid(x,x,x);
se = (x+y+z) <= r.^2;

答案 1 :(得分:0)

您可以自己生成一个3D球形结构元素,该元素等于strel'sphere'选项。在MATLAB R2016b中进行测试:

radius = 5;

sphereSE = strel('sphere', radius);  % Spherical element

[x, y, z] = ndgrid(-radius:radius);
arbitSE = strel(sqrt(x.^2+y.^2+z.^2) <= radius);  % The `arbitrary` argument is optional

isequal(sphereSE.Neighborhood, arbitSE.Neighborhood)  % Check equality

ans =

  logical

   1  % They give the same result