Error by using function imclose() and implementation of MATLAB code into Simulink model
1 view (last 30 days)
Show older comments
Elias on 15 Mar 2018
Answered: Ryan Livingston on 19 Mar 2018
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?
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.
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)
Find more on Computer Vision With Simulink in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!Start Hunting!