Error by using function imclose() and implementation of MATLAB code into Simulink model

2 views (last 30 days)
I would like to detect objects on a picture by segmenting, analyzing regions and some other preprocessing. The code is already working in MATLAB and now I am trying to realise this functionality with Simulink. After loading the data (uint8) the RGB image gets converted to gray (uint8) and then to BW (logical) through a threshold. The next step is closing the image with the function imclose. At this point the following error appears:
Expected input number 1, BWP, to be one of these types: uint32. Instead its type was double.
Function 'MATLAB Function2' (#60.208.226), line 8, column 13:
"imclose(bwImg, se)"
Launch diagnostic report.
Component:MATLAB Function | Category:Coder error
According to the Documentation the input array (bwImg) "can be any numeric or logical class and any dimension, and must be nonsparse. If IM is logical, then SE must be flat." bwImg does not have the data type uint32, but is logical. Like I said, the code is working in MATLAB.
Below you can see the code that is located in the MATLAB Function Block.
function closedImg = thresCloseImg(grayImg, threshold)
%%Thresholding Image
bwImg = grayImg > threshold;
%%Close with disc
radius = 5;
decomposition = 8;
se = strel('disk', radius, decomposition);
closedImg = imclose(bwImg, se);
end
Thank you in advance for your Answer!
P.s.: I did not find Simulink blocks from the Image Processing Toolbox which represent apps like the Image Segmenter or the Image Region Analyzer in the MATLAB environment. Because of that I would like to use the generated code in MATLAB Function Blocks. Are there any tips or even better ways to do image processing with Simulink?
  3 Comments
Elias
Elias on 19 Mar 2018
Thank you! That solved the problem. I did not know the MATLAB Function Block Editor Tools.
Is there a possibility to observe data types and values inside of a MATLAB function block during simulation?
Ryan Livingston
Ryan Livingston on 19 Mar 2018
Great! I'll move this to an answer. You can click the View Report button to open the MATLAB Function Report that shows data types and sizes in the MATLAB code.

Sign in to comment.

Accepted Answer

Ryan Livingston
Ryan Livingston on 19 Mar 2018
Copied from a comment
The error is likely prefixed by a statement like "Simulink was unable to determine ..." something about the sizes of signals. If so, then specifying the size and data type of closedImg on the MATLAB Function Block ports and data manager (see edit data entry here) should avoid the issue.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!