Error by using function imclose() and implementation of MATLAB code into Simulink model
5 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:
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)
bwImg = grayImg > threshold;
%%Close with disc
radius = 5;
decomposition = 8;
se = strel('disk', radius, decomposition);
closedImg = imclose(bwImg, se);
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?
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.