MATLAB: Am I unable to use the function IMTRANSFORM in an application created with MATLAB Compiler 7.10 (R2009a)

builderImage Processing ToolboxjarjavaMATLAB Compilerstand-alonestandalone

My program loads the transformation structure (TFORM) that is passed to IMTRANSFORM from a MAT file. The program runs fine within MATLAB but fails in compiled mode with the following error:
Warning: Could not find appropriate function on path loading function handle
C:\MATLAB\R2009a\toolbox\images\images\private\inv_piecewiselinear.mexw32>inv_piecewiselinear
Compiling the application using the MATLAB Builder JA shows the following additional information:
Exception caught: com.mathworks.toolbox.javabuilder.MWException: Error using ==> feval
Undefined function handle.

Best Answer

The TFORM structure contains a function handle to a function from the Image Processing Toolbox. Since the structure gets loaded at runtime, the static analysis that is done by the MATLAB Compiler fails to identify the file as a dependency.
To work around this issue, add the following "function pragma" line of code to the beginning of your MATLAB program to indicate that the function CP2TFORM should be included in the compilation:
%#function cp2tform
The function CP2TFORM will automatically include the rest of the files that are needed for the TFORM structure to be loaded/restored correctly from the MAT file.