File Exchange

image thumbnail

MVTec Halcon Wrapper

version (5.05 MB) by Dirk-Jan Kroon
MVTec Halcon function mex-wrapper


Updated 31 Jan 2017

View Version History

View License

MVTec Halcon (12) is an image processing library used in machine vision applications.
At we use both Halcon and Matlab together. Therefor we wrapped all Halcon operators into Matlab Mex-files (c++ code). By compiling the code (compile_cpp_code.m) you can use the Halcon operators in Matlab.
I = transpose(imread('lena.tif'));
Imedian = hMedianImage (I, 'circle', 3, 'continued');
figure, imshow(transpose(Imedian.image))
1. To use the software install Halcon Developer version. A version including temporary license can be obtained at
2. Please note, this wrapper is also compatible with Halcon 11, Halcon 13 ... but in that case first run "generate_cpp_code.m" followed by "generate_help_files.m" followed by "compile_cpp_code.m")

3.If you use Matlab 64-bits, install Halcon x64 and 64-bit c++ compiler.
When using Matlab 32-bits also install Halcon 32-bits.

4. Note image-data is stored row-wise in Halcon and column-wise in Matlab. Thus transpose or permute(I,[2 1 3]) an image from Matlab before using in Halcon and the other-way around

5. XLD's are currently not supported.

6. Halcon is sensitive to input datatypes, thus don't use hFunction("100") or hFunction(100), when Halcon expect an integer, then use hFunction(int32(100)). A mixed tuple equals a cell array like {"true", "red",int32(123),3.14}

Cite As

Dirk-Jan Kroon (2021). MVTec Halcon Wrapper (, MATLAB Central File Exchange. Retrieved .

Comments and Ratings (7)

David Provencher

Alessandro Oliva

Hi Dirk-Jan,
thank you for posting this great tool.

I followed your instructions: I installed Halcon 13 and executed the "generate_cpp_code.m" followed by "generate_help_files.m" followed by "compile_cpp_code.m". No errors occurred.

I compiled using Microsoft Visual Studio 2015 Compiler, and the process returned the message "MEX completed successfully".

Then, I set the Current Folder to the folder containing your wrapper, and I tried to execute your example (adapting the file name):

I = transpose(imread('cameraman.tif'));
Imedian = hMedianImage (I, 'circle', 3, 'continued');
figure, imshow(transpose(Imedian.image))

It returns this error:

Attempt to execute SCRIPT hMedianImage as a function:

Could you pls help me understand what's wrong with my procedure?
Thank you very much in advance.



can this Halcon Wrapper work in MATLAB version later than R2014a?


This is really great. It helps couple two very powerful codes and utilize some of the great features in Halcon. My two issues are:
1. Lack of examples/documentation on how to use these functions effectively in Matlab.
2. Lack of XLD support.

You can typically stumble through and figure out how to use these functions, but it is slow and can be non-obvious if you aren't intimately familiar with Halcon. For example - if a Halcon function returns a "region" - how do we best use that in Matlab space? Say we threshold an image (hDynThreshold) - how do I quickly display the results using imshow()? You can figure it out, it works - but it is not obvious at first.

Overall - very valuable toolbox and very glad this was provided on the file exchange. Some basic examples to help users understand things efficiently could go a long way.



Wont work with Halcon 10


HALCONCpp/HalconCpp.h is missing.

MATLAB Release Compatibility
Created with R2014a
Compatible with any release
Platform Compatibility
Windows macOS Linux

Inspired: MVTec Halcon wrapper with XLD serialization

Community Treasure Hunt

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

Start Hunting!