How can I use image processing functions such as imfindcircles in a simulink matlab function block? I get an error when I use this function.

here is the function:
if true
% code
end
function y = fcn(u)
I1=u;
I2=imadjust(I1,[0.1 0.3],[0 1]);
[centers, radii] = imfindcircles(I2,[10 30],'ObjectPolarity','dark', 'Sensitivity',0.85);
diameter=radii.*2;
y = diameter;
here is the simulink error The function 'imfindcircles' is not supported for standalone code generation. See the documentation for coder.extrinsic to learn how you can use this function in simulation.
Function 'MATLAB Function' (#31.59.147), line 4, column 1: "[centers, radii] = imfindcircles(I2,[10 30],'ObjectPolarity','dark', 'Sensitivit" Launch diagnostic report. Component: MATLAB Function | Category: Coder error

Answers (2)

Did you do as the Simulink error suggested and take a look at the documentation for coder.extrinsic?

3 Comments

Yes, it suggested I declare the function as a coder.extrinsic function by using: coder.extrinsic('imfindcircles') when I do this I get a new error: The extrinsic function 'imfindcircles' is not available for standalone code generation. It must be eliminated for stand-alone code to be generated. It could not be eliminated because its outputs appear to influence the calling function. Fix this error by not using 'imfindcircles' or by ensuring that its outputs are unused.
Taking a closer look at the tags, you're trying to generate code for a Raspberry Pi from this Simulink model? I'm not sure that will work; from the error message, Simulink doesn't know how to create the code to run on that processor for this function written as MATLAB code.
I'm not really familiar with Simulink code generation, that's just my assessment based on the text of the error, so take it with a grain of salt (and perhaps contact Technical Support to see if there is an alternative function you can use that is supported for code generation.)
Yes, I am creating an image processing model in Simulink that I can deploy to the Raspi. I will contact technical support, thanks.

Sign in to comment.

You could also use an interpreted matlab function block so that Simulink doesn't generate code for it. You'll take a performance hit but it will run.

1 Comment

The functions I want to use (imfindcircles and imadjust) have multiple inputs. The interpreted MATLAB function block only seems to have one signal input? In the block parameters it states that the function must return a single value, I want to process matrices (images), so I doubt this will work? I am not a MATLAB expert so please correct me if I am wrong.

Sign in to comment.

Asked:

on 19 Aug 2015

Commented:

on 20 Aug 2015

Community Treasure Hunt

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

Start Hunting!