MATLAB Answers

C code generation error for bwlabel

2 views (last 30 days)
NAVID FALLAHINIA
NAVID FALLAHINIA on 15 Aug 2019
Answered: Rajani Mishra on 20 Aug 2019
I'm trying build an embeded function in my Simulink model which uses "bwlabel" function but, I'm getting the following code generation error:
Computed maximum size is not bounded.
Static memory allocation requires all sizes to be bounded.
The computed size is [:? x 1].
Function 'bwlabel.m' (#70.1164.1211), line 48, column 21:
"zeros(numRuns,1,coder.internal.indexIntClass())"
Below is a part of my code:
% Get rid of small objects.
coloredObjectsMask = imerode(coloredObjectsMask, structuringElement_erode);
% Dialate the small remaining areas.
coloredObjectsMask = imdilate(coloredObjectsMask, structuringElement_dilate);
% Smooth the border using a morphological closing operation, imclose().
coloredObjectsMask = imclose(coloredObjectsMask, structuringElement_close);
% Fill in any holes in the regions, since they are most likely red also.
coloredObjectsMask = imfill(logical(coloredObjectsMask), 'holes');
% We need to convert the type of coloredObjectsMask to the same data type as hImage.
ObjectsMask = uint8(255* coloredObjectsMask);
% Label connected components
[coloredObjectsMask_label, label_num]= bwlabel(ObjectsMask);
Where "coloredObjectsMask" is a uint8 432*235. I cannot understand what's wrong with it since it's working as a regular function.

  0 Comments

Sign in to comment.

Answers (1)

Rajani Mishra
Rajani Mishra on 20 Aug 2019
The function "bwlabel" requires dynamic memory allocation (malloc) based on the content of the input image. When you label an image, the number of labels required is not known at compile-time. The number of labels varies based on image content. As per release R2015b, MATLAB Function block requires all functions to work without 'malloc', in other words it does not support dynamic memory allocation.
As per the latest release dynamic memory allocation is possible. By default dynamic memory allocation is enabled in the Configuration Parameters dialog box in the Simulation Target > Advanced parameters category you will find Dynamic memory allocation in MATLAB Function blocks

  0 Comments

Sign in to comment.

Sign in to answer this question.

Products


Release

R2015b