Partial replacement for MATLAB's Image Processing Toolbox

I recently needed to replace the following functions from MATLAB’s Image Processing Toolbox: bwareaopen(), bwconncomp(), colfilt(), im2bw(), imclose(), imdilate(), imerode(), imfilter(), imopen() in order to remove it as a dependency of one of the new SPM toolboxes I’ve been working on. If you happen to be in a similar situation or just need this functions for other reasons, here they are (license: GPL). All of them behave exactly as their commercial counterparts, with the following exceptions:

  • Only 1-, 2- and 3-dimensional images are supported.
  • ls_imfilter(), ls_imdilate(), ls_imerode(), ls_imopen(), ls_imclose() use ls_improc.c as their core, ls_improc.c is multi-threaded and requires pthreads/pthreads-win32 to compile
  • ls_colfilt() takes function name instead of function handle as third argument. The function has to be on the MATLATB path. This can be easily fixed to use handles as well.
  • ls_imfilter() accepts only fixed numerical value or ‘symmetric’ modes of boundary processing. See ls_improc.c if you want to fix this.
  • ls_bwconncomp() requires spm_bwlabel() (part of SPM).

That’s it. Enjoy: !


  • Hi, great tool

    how do i get the ls_conncomp function running (linux machine)? It shows an error that it does not find ls_conncomp_pix_list.
    There is probably an easy way to compile it to a mex-file. How can i do that? (Sorry i am rather a beginner in compiling and mex extensions)


    • ahh ok, i am stupid.. reading the matlab help and using the mex function helps..
      but the next code line pops up a new problem:
      do you know of any free implementation of the functionality of the regionprops function?

Leave a Reply

Your email address will not be published. Required fields are marked *