This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

Code Generation for Image Processing

Certain Image Processing Toolbox™ functions have been enabled to generate C code (requires MATLAB® Coder™). To use code generation with image processing functions, follow these steps:

  • Write your MATLAB function or application as you would normally, using functions from the Image Processing Toolbox.

  • Add the %#codegen compiler directive to your MATLAB code.

  • Open the MATLAB Coder app, create a project, and add your file to the project. In the app, you can check the readiness of your code for code generation. For example, your code may contain functions that are not enabled for code generation. Make any modifications required for code generation.

  • Generate code by clicking Generate on the Generate Code page of the MATLAB Coder app. You can choose to generate a MEX file, a shared library, a dynamic library, or an executable.

    Even if you addressed all readiness issues identified by MATLAB Coder, you might still encounter build issues. The readiness check only looks at function dependencies. When you try to generate code, MATLAB Coder might discover coding patterns that are not supported for code generation. View the error report and modify your MATLAB code until you get a successful build.

For a complete list of Image Processing Toolbox functions that support code generation, see Functions Supporting Code Generation. For an example of using code generation, see Code Generation with Cell Detection.

Code Generation Using a Shared Library

Image Processing Toolbox functions can generate either standalone C code or code that depends on a precompiled, platform-specific shared library.

  • Some functions generate standalone C code that can be incorporated into applications that run on many platforms, such as ARM processors.

  • Some functions generate C code that uses a platform-specific shared library. The Image Processing Toolbox uses this shared library approach to preserve performance optimizations, but this limits the platforms on which you can run this code to only platforms that can host MATLAB. To view a list of host platforms, see system requirements.

  • Some functions can generate either standalone C code or generate code that depends on a shared library, depending upon which target you choose in the MATLAB Coder configuration settings.

    • If you choose the generic MATLAB Host Computer option, these functions deliver code that uses a shared library.

    • If you choose any other platform option, these functions deliver C code.

The diagram illustrates the difference between generating C code and generating code that uses a shared library.

Related Examples

More About