FAQ (Frequently Asked Questions) for MatLab developers on using WSQ image library
As of MatLab 6.5.1 (R13SP1) and later versions, it is possible to access functions defined in Windows standard dynamic link libraries (.dll) through the MatLab command line using the LOADLIBRARY function. This feature is available for Windows platforms only for releases R13SP1 through R14SP1. As of release R14SP2, LOADLIBRARY is supported on both Windows and Linux.
The difficulty arises if you want to use HBITMAP data type in function call to the DLL, because MatLab does not natively support HBITMAP data type.
The solution is to use wrapper DLL which wraps HBITMAP data type into native MatLab uint8 array for image storage using MatLab MEX interface.
Such a wrapper interface is provided in DLL files "WSQ_library_read_image.dll" and "WSQ_library_write_image.dll".
MEX-files are a way to call your custom C or FORTRAN routines directly from MatLab as if they were MatLab built-in functions.
MEX stands for MatLab Executable. MEX-files are dynamically linked subroutines produced from C or Fortran source code that, when compiled, can be run from within MatLab in the same way as MatLab M-files or built-in functions. The external interface functions provide functionality to transfer data between MEX-files and MatLab, and the ability to call MatLab functions from C or Fortran code.
The external interface functions could be compiled to executables called MEX-files. MEX-files in Microsoft Windows have *.dll extension. MEX-files in other operating systems have other extensions.
The main reasons to use a MEX-file are:
- The ability to call large existing C or FORTRAN routines directly from MatLab without having to rewrite them as M-files.
- Speed; you can rewrite bottleneck computations (like for-loops) as a MEX-file for efficiency.
MatLab stores the numbers in real (double) format as the default. When you call a C function in the DLL, MatLab passes real (double) format value instead of integer format.
The solution is to explicitly set the function argument to integer by using MatLab int32() function.
As for example, suppose you are trying to call function factorial(int number) in the DLL.
Instead of using
you should use
Natively MatLab supports only one function in one MEX file (dll).
|