MATLAB Answers

Matlab coder with bwboundries

1 ビュー (過去 30 日間)
Tej Patel
Tej Patel 2017 年 4 月 18 日
コメント済み: Timo 2018 年 12 月 4 日
I am getting an issue trying to compile a simulink block. This block contains a matlab function that uses this function call inside:
B = bwboundaries(BW, 8, 'noholes');
Note that BW is simply a binary image of known size.
When trying to compile, I get an error for the function bwboundries returning an unbounded value:
Computed maximum size of the output of function 'bwboundaries' is not bounded.
Static memory allocation requires all sizes to be bounded. The computed size is [:? x 1].
Function 'bla' (#40.123.153), line 7, column 5:
"bwboundaries(BW, 8, 'noholes')"
This simulink model is intended to run on a Beaglebone Black if that helps.
I've tried to declare the variable size of BW and of B with coder.varsize but it did not help.
Thanks..

  1 件のコメント

Nikhil Sreekumar
Nikhil Sreekumar 2017 年 4 月 28 日
Hey,
Can you mention how you used the coder.varsize? Was it something like this?
coder.varsize('B', [100 1])
Assuming the number of objects and holes won't go above 100.
Thanks
Nikhil

サインインしてコメントする。

回答 (1 件)

Ankit Bhardwaj
Ankit Bhardwaj 2017 年 4 月 24 日
According to the following documentation, code generation for 'bwboundaries' function requires 'conn' and 'options' (i.e. 2nd and 3rd parameter) to be a compile-time constant.
https://www.mathworks.com/help/releases/R2017a/images/ref/bwboundaries.html#bvmx88x-1
If this does not help, please provide a reproduction model and information about the MATLAB version you are using.

  2 件のコメント

Nikhil Sreekumar
Nikhil Sreekumar 2017 年 4 月 28 日
Hi Ankit,
The issue here seems to be related to the output of the bwboundaries function. Also, the options for bwboundaries are declared at compile time.
B = bwboundaries(BW, 8, 'noholes');
Seems like the number of objects and holes are not calculated, (? x 1), or may want the size to be declared beforehand.
Thanks
Nikhil
Timo
Timo 2018 年 12 月 4 日
Hi Nikhil and others,
I am facing the same issue. Since B is a cell array, the coder.varsize('B', [100 1]) command needs to come after the first call of bwboundaries right? To be sure, as Ankit suggested, I also declared the conn variable with coder.varsize, and all variables that are derived from B afterwards in my code.
To give some context to the code below: I am looking for the pixel coordinates (X,Y) of the edge of the largest Blob detected with bwboundaries. Since I do analysis on a region-of-interest, I have another separate function to return the actual pixel coordinates for given ROI-coordinates. If no feature is detected, I simply return NaNs.
In the model explorer, the variables Xe, Ye are set to be variable size with bounds. I turned dynamic memory allocation off since this code needs to be RT at some point.
Many thanks for your help,
Timo
function [Xe,Ye,qual] = get_boundary_perim(afterthreshmedian,ROI_pars) %#codegen
coder.varsize('Xe',750);
coder.varsize('Ye',750);
coder.varsize('conn',1,0);
coder.varsize('n',1,0);
coder.varsize('afterthreshmedian',size(ROI_pars.ROI),[0 0]);
conn = 8;
B = bwboundaries(afterthreshmedian,conn);
coder.varsize('B', [100 1],[1 0]);
assert(length(B)<100);
n = length(B);
if ~isempty(B)
Xetemp = cell(1,n);
Yetemp = cell(1,n);
lengths = zeros(1,n);
for ii = 1:n
xy = B{ii};
lengths(ii) = length(xy);
[Xetemp{ii},Yetemp{ii}] = ROIind2imag(ROI_pars,xy(:,2),xy(:,1));
end
qual = true;
[~,ind] = max(lengths);
Xe = Xetemp{ind};
Ye = Yetemp{ind};
else
Xe = NaN;
Ye = NaN;
qual = false;
end

サインインしてコメントする。

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by