Optimal Chamfer Mask and Coefficients Computation

Reference Article


Installation and Compilation

The code has been written in C. The following stands for unix/linux systems, but it should not be difficult for windows folks to achieve to compile it.

  1. Decompress the archive it should result in a help file (this file) and a directory named src.
  2. go in the directory by cd src and compile by make. If you do not have the make command installed, you can also directly compile by
    cc -O -I. -o gener-mask gener-mask.c chamfer.c -lm
you end up with a binary file named gener-mask

Running gener-mask

Chamfer mask construction

Chamfer mask coefficients computation


The -matlab option (by specifying -matlab filename in the command line) generates a Matlab file commands that allows to visualize the distribution of errors (in percentage) on the mask sectors. The figures

5x5x5 isotropic mask 7x7x7 isotropic mask
have been respectively generated by
gener-mask -dim 3 -size 5 -y 1.0 -z 1.0 -matlab mask_size5.m -bo
gener-mask -dim 3 -size 7 -y 1.0 -z 1.0 -matlab mask_size7.m -bo


The command

gener-mask -help
  [-dim %d] [-mask-size|-mask|-size %d] [-error %f] [-vectors %d]
  [-prebuild|-pb %d] [-build-only|-bo] [-y %f] [-z %f]
  [-f %d] [-l %d]
  [-res %s] [-matlab %s] [-latex %s]
  [-help|--help] [-examples|-ex]

 =====  mask construction =====
-dim %d : space dimension (3 or 2 (default))
-mask-size|-mask|-size %d : mask size
 3 (default) -> mask 3x3 or 3x3x3
 5 ->  mask 5x5 or 5x5x5
-vectors %d : maximal number of vectors in mask
   if -mask-size is also specified (after in the command line)
   the vectors are restricted in the given neighborhood
-error %f : maximal sector error
   0.01 means 1%
   can be used in conjunction with -mask-size and -vectors
-prebuild|-pb %d : prebuilt masks (assume dim=3)
   admissible values:
   3, 333 -> mask 3x3x3
   5, 555 -> mask 5x5x5
   7, 777 -> mask 7x7x7
   this was implemented for comparison with (Fouard, IVC, 2005)
-y %f : pixel or voxel dimension along Y
-z %f : voxel dimension along z
-build-only|-bo: do not compute weights

 =====  weight computing  =====
-f %d : first weight value (default=1)
-l %d : last weight value (default=20)

 ===== output controlling =====
-res %s : specify output text file (default is stdout)
-matlab %s : specify output matlab file
   nice plot of mask errors
-latex %s : specify output matlab file
   latex table of computed weights

 =====        misc        =====
-help : print this help
-examples|-ex : print some command lines examples

Authors : Gregoire Malandain & Celine Fouard