为什么 strel 在 MATLAB Coder 中失败

why does strel failed in MATLAB Coder

在 2019b 中使用 MATLAB Coder,以下行:

se = strel('line',20,85);

MATLAB Coder 无法有效描述:

1.All 输入必须是常量。

2.Function调用失败

为什么 Coder 在 strel 中遇到困难?

matlab 编码器支持strel吗?

MATLAB Coder 支持 strel。我在 R2019b 中尝试了以下简单示例并注意到它有效。

% Function foo.m
function y = foo
    se = strel('line',20,85);
    y = numel(se.Neighborhood);
end

% Codegen command in command window
>> codegen foo -report

从您发布的错误消息来看,您对 strel 的输入似乎不是常量,这就是 codegen 失败的原因。请参阅此处文档中有关 C/C++ 代码生成部分的部分:https://www.mathworks.com/help/images/ref/strel.html,其中说明如下:

Usage notes and limitations:

  • strel supports the generation of C code (requires MATLAB® Coder™). For more information, see Code Generation for Image Processing.
  • All input arguments must be compile-time constants.
  • The methods associated with strel objects are not supported in code generation.
  • Arrays of strel objects are not supported.

根据评论显示 imerode 的示例:

% Function foo.m
function y = foo(edgeimg)
    se = strel('line',20,85);
    y = imerode(edgeimg, se.Neighborhood);
end

% Codegen command in command window
% The image must be 2D or 3D according to doc
>> edgeimg = imread('blah.png'); 
>> codegen foo -args edgeimg -report